[PATCH 2/5] drivers/dma: Return -ENOMEM on memory allocation failure

From: Julia Lawall
Date: Wed Aug 11 2010 - 06:11:16 EST


From: Julia Lawall <julia@xxxxxxx>

In this code, 0 is returned on memory allocation failure, even though other
failures return -ENOMEM or other similar values.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression ret;
expression x,e1,e2,e3;
@@

ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <julia@xxxxxxx>

---
drivers/dma/coh901318.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/coh901318.c b/drivers/dma/coh901318.c
index 557e227..6dd9488 100644
--- a/drivers/dma/coh901318.c
+++ b/drivers/dma/coh901318.c
@@ -1475,8 +1475,10 @@ static int __init coh901318_probe(struct platform_device *pdev)
pdata->max_channels *
sizeof(struct coh901318_chan),
GFP_KERNEL);
- if (!base)
+ if (!base) {
+ err = -ENOMEM;
goto err_alloc_coh_dma_channels;
+ }

base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/