diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2014-08-14 07:59:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-08-14 17:38:54 -0400 |
commit | 9b9ba821b6c47b6d1a711b8f6fff931277217bab (patch) | |
tree | 19fe44ecda226e216ba2c2bb21f897144f897873 /drivers/net/ethernet/apm/xgene | |
parent | 9d186cac7ffb1831e9f34cb4a3a8b22abb9dd9d4 (diff) |
net: xgene: Check negative return value of xgene_enet_get_ring_size()
xgene_enet_get_ring_size() returns a negative value in case of an error,
but its only caller in xgene_enet_create_desc_ring() currently uses the
return value directly as u32. Instead, check for a negative value first and
error out in case. Also move the call to xgene_enet_get_ring_size() before
devm_kzalloc() so we don't need to free anything in the error path.
This fixes the following issue reported by the Coverity Scanner:
** CID 1231336: Improper use of negative value (NEGATIVE_RETURNS)
/drivers/net/ethernet/apm/xgene/xgene_enet_main.c: 596 in xgene_enet_create_desc_ring()
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/apm/xgene')
-rw-r--r-- | drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c index af7c40ac1455..e1a8f4e19983 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c | |||
@@ -581,7 +581,11 @@ static struct xgene_enet_desc_ring *xgene_enet_create_desc_ring( | |||
581 | struct xgene_enet_desc_ring *ring; | 581 | struct xgene_enet_desc_ring *ring; |
582 | struct xgene_enet_pdata *pdata = netdev_priv(ndev); | 582 | struct xgene_enet_pdata *pdata = netdev_priv(ndev); |
583 | struct device *dev = ndev_to_dev(ndev); | 583 | struct device *dev = ndev_to_dev(ndev); |
584 | u32 size; | 584 | int size; |
585 | |||
586 | size = xgene_enet_get_ring_size(dev, cfgsize); | ||
587 | if (size < 0) | ||
588 | return NULL; | ||
585 | 589 | ||
586 | ring = devm_kzalloc(dev, sizeof(struct xgene_enet_desc_ring), | 590 | ring = devm_kzalloc(dev, sizeof(struct xgene_enet_desc_ring), |
587 | GFP_KERNEL); | 591 | GFP_KERNEL); |
@@ -593,7 +597,6 @@ static struct xgene_enet_desc_ring *xgene_enet_create_desc_ring( | |||
593 | ring->cfgsize = cfgsize; | 597 | ring->cfgsize = cfgsize; |
594 | ring->id = ring_id; | 598 | ring->id = ring_id; |
595 | 599 | ||
596 | size = xgene_enet_get_ring_size(dev, cfgsize); | ||
597 | ring->desc_addr = dma_zalloc_coherent(dev, size, &ring->dma, | 600 | ring->desc_addr = dma_zalloc_coherent(dev, size, &ring->dma, |
598 | GFP_KERNEL); | 601 | GFP_KERNEL); |
599 | if (!ring->desc_addr) { | 602 | if (!ring->desc_addr) { |