All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] ibmveth: Return correct error codes
@ 2016-02-04 13:55 Amitoj Kaur Chawla
  2016-02-13 10:58 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-04 13:55 UTC (permalink / raw)
  To: tlfalcon, netdev, linux-kernel; +Cc: julia.lawall

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 <amitoj1606@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/3] ibmveth: Return correct error codes
  2016-02-04 13:55 [PATCH 2/3] ibmveth: Return correct error codes Amitoj Kaur Chawla
@ 2016-02-13 10:58 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-02-13 10:58 UTC (permalink / raw)
  To: amitoj1606; +Cc: tlfalcon, netdev, linux-kernel, julia.lawall

From: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Date: Thu, 4 Feb 2016 19:25:19 +0530

> 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:
 ...
> 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 <amitoj1606@gmail.com>

This does not apply cleanly and gives rejects.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-13 10:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-04 13:55 [PATCH 2/3] ibmveth: Return correct error codes Amitoj Kaur Chawla
2016-02-13 10:58 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.