From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932885Ab0HKKLM (ORCPT ); Wed, 11 Aug 2010 06:11:12 -0400 Received: from mgw2.diku.dk ([130.225.96.92]:41231 "EHLO mgw2.diku.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932870Ab0HKKLK (ORCPT ); Wed, 11 Aug 2010 06:11:10 -0400 Date: Wed, 11 Aug 2010 12:11:07 +0200 (CEST) From: Julia Lawall To: Linus Walleij , Dan Williams , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 2/5] drivers/dma: Return -ENOMEM on memory allocation failure Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Julia Lawall 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/) // @@ 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; } // Signed-off-by: Julia Lawall --- 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);