Thread (2 messages) flat view 2 messages, 2 authors, 2016-02-13
STALE3854d

[PATCH 2/3] ibmveth: Return correct error codes

From: Amitoj Kaur Chawla <hidden>
Date: 2016-02-04 13:56:09
Also in: lkml
Subsystem: ibm power virtual ethernet device driver, linux for powerpc (32-bit and 64-bit), networking drivers, the rest · Maintainers: Nick Child, Madhavan Srinivasan, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

The return value of kmalloc and kcalloc on failure of allocation of
memory should be -ENOMEM and not -1.

Found using Coccinelle. A simplified version of the semantic patch
used is:

//<smpl>
@@
expression *e;
position p,q;
@@

e@q = \(kmalloc\|kcalloc\)(...);
if@p (e == NULL) {
...
return
- -1
+ -ENOMEM
;
}
//</smpl>

The two call sites only check that the return value is not 0,
hence no change is required at the call sites.

Signed-off-by: Amitoj Kaur Chawla <redacted>
---
 drivers/net/ethernet/ibm/ibmveth.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 7af870a..92a9a70 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -167,13 +167,13 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
 	pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
 
 	if (!pool->free_map)
-		return -1;
+		return -ENOMEM;
 
 	pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL);
 	if (!pool->dma_addr) {
 		kfree(pool->free_map);
 		pool->free_map = NULL;
-		return -1;
+		return -ENOMEM;
 	}
 
 	pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL);
@@ -184,7 +184,7 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
 
 		kfree(pool->free_map);
 		pool->free_map = NULL;
-		return -1;
+		return -ENOMEM;
 	}
 
 	memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
-- 
1.9.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help