Skip to content

Commit fb5c6cf

Browse files
khoroshilovdavem330
authored andcommitted
vmxnet3: avoid assumption about invalid dma_pa in vmxnet3_set_mc()
vmxnet3_set_mc() checks new_table_pa returned by dma_map_single() with dma_mapping_error(), but even there it assumes zero is invalid pa (it assumes dma_mapping_error(...,0) returns true if new_table is NULL). The patch adds an explicit variable to track status of new_table_pa. Found by Linux Driver Verification project (linuxtesting.org). v2: use "bool" and "true"/"false" for boolean variables. Signed-off-by: Alexey Khoroshilov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 50756eb commit fb5c6cf

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/net/vmxnet3/vmxnet3_drv.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,7 @@ vmxnet3_set_mc(struct net_device *netdev)
22792279
&adapter->shared->devRead.rxFilterConf;
22802280
u8 *new_table = NULL;
22812281
dma_addr_t new_table_pa = 0;
2282+
bool new_table_pa_valid = false;
22822283
u32 new_mode = VMXNET3_RXM_UCAST;
22832284

22842285
if (netdev->flags & IFF_PROMISC) {
@@ -2307,13 +2308,15 @@ vmxnet3_set_mc(struct net_device *netdev)
23072308
new_table,
23082309
sz,
23092310
PCI_DMA_TODEVICE);
2311+
if (!dma_mapping_error(&adapter->pdev->dev,
2312+
new_table_pa)) {
2313+
new_mode |= VMXNET3_RXM_MCAST;
2314+
new_table_pa_valid = true;
2315+
rxConf->mfTablePA = cpu_to_le64(
2316+
new_table_pa);
2317+
}
23102318
}
2311-
2312-
if (!dma_mapping_error(&adapter->pdev->dev,
2313-
new_table_pa)) {
2314-
new_mode |= VMXNET3_RXM_MCAST;
2315-
rxConf->mfTablePA = cpu_to_le64(new_table_pa);
2316-
} else {
2319+
if (!new_table_pa_valid) {
23172320
netdev_info(netdev,
23182321
"failed to copy mcast list, setting ALL_MULTI\n");
23192322
new_mode |= VMXNET3_RXM_ALL_MULTI;
@@ -2338,7 +2341,7 @@ vmxnet3_set_mc(struct net_device *netdev)
23382341
VMXNET3_CMD_UPDATE_MAC_FILTERS);
23392342
spin_unlock_irqrestore(&adapter->cmd_lock, flags);
23402343

2341-
if (new_table_pa)
2344+
if (new_table_pa_valid)
23422345
dma_unmap_single(&adapter->pdev->dev, new_table_pa,
23432346
rxConf->mfTableLen, PCI_DMA_TODEVICE);
23442347
kfree(new_table);

0 commit comments

Comments
 (0)