[PATCH 2/5] drivers/dma: Return -ENOMEM on memory allocation failure
Julia Lawall
julia at diku.dk
Wed Aug 11 06:11:07 EDT 2010
From: Julia Lawall <julia at diku.dk>
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 at diku.dk>
---
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);
More information about the linux-arm-kernel
mailing list