diff options
author | Alexey Khoroshilov <khoroshilov@ispras.ru> | 2016-10-14 17:01:20 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-10-15 17:47:32 -0400 |
commit | fb5c6cfaec126d9a96b9dd471d4711bf4c737a6f (patch) | |
tree | 05dcacadd11d40b436d4d702afc7cadb042671cd /drivers/net/vmxnet3 | |
parent | 50756ebecf69276b8a908409fa32c123bb12420b (diff) |
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 <khoroshilov@ispras.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/vmxnet3')
-rw-r--r-- | drivers/net/vmxnet3/vmxnet3_drv.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index b5554f2ebee4..ef83ae3b0a44 100644 --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c | |||
@@ -2279,6 +2279,7 @@ vmxnet3_set_mc(struct net_device *netdev) | |||
2279 | &adapter->shared->devRead.rxFilterConf; | 2279 | &adapter->shared->devRead.rxFilterConf; |
2280 | u8 *new_table = NULL; | 2280 | u8 *new_table = NULL; |
2281 | dma_addr_t new_table_pa = 0; | 2281 | dma_addr_t new_table_pa = 0; |
2282 | bool new_table_pa_valid = false; | ||
2282 | u32 new_mode = VMXNET3_RXM_UCAST; | 2283 | u32 new_mode = VMXNET3_RXM_UCAST; |
2283 | 2284 | ||
2284 | if (netdev->flags & IFF_PROMISC) { | 2285 | if (netdev->flags & IFF_PROMISC) { |
@@ -2307,13 +2308,15 @@ vmxnet3_set_mc(struct net_device *netdev) | |||
2307 | new_table, | 2308 | new_table, |
2308 | sz, | 2309 | sz, |
2309 | PCI_DMA_TODEVICE); | 2310 | 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 | } | ||
2310 | } | 2318 | } |
2311 | 2319 | if (!new_table_pa_valid) { | |
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 { | ||
2317 | netdev_info(netdev, | 2320 | netdev_info(netdev, |
2318 | "failed to copy mcast list, setting ALL_MULTI\n"); | 2321 | "failed to copy mcast list, setting ALL_MULTI\n"); |
2319 | new_mode |= VMXNET3_RXM_ALL_MULTI; | 2322 | new_mode |= VMXNET3_RXM_ALL_MULTI; |
@@ -2338,7 +2341,7 @@ vmxnet3_set_mc(struct net_device *netdev) | |||
2338 | VMXNET3_CMD_UPDATE_MAC_FILTERS); | 2341 | VMXNET3_CMD_UPDATE_MAC_FILTERS); |
2339 | spin_unlock_irqrestore(&adapter->cmd_lock, flags); | 2342 | spin_unlock_irqrestore(&adapter->cmd_lock, flags); |
2340 | 2343 | ||
2341 | if (new_table_pa) | 2344 | if (new_table_pa_valid) |
2342 | dma_unmap_single(&adapter->pdev->dev, new_table_pa, | 2345 | dma_unmap_single(&adapter->pdev->dev, new_table_pa, |
2343 | rxConf->mfTableLen, PCI_DMA_TODEVICE); | 2346 | rxConf->mfTableLen, PCI_DMA_TODEVICE); |
2344 | kfree(new_table); | 2347 | kfree(new_table); |