From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932908Ab0HKKL2 (ORCPT ); Wed, 11 Aug 2010 06:11:28 -0400 Received: from mgw2.diku.dk ([130.225.96.92]:41245 "EHLO mgw2.diku.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932856Ab0HKKL0 (ORCPT ); Wed, 11 Aug 2010 06:11:26 -0400 Date: Wed, 11 Aug 2010 12:11:24 +0200 (CEST) From: Julia Lawall To: Eric Moore , support@lsi.com, DL-MPTFusionLinux@lsi.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 3/5] drivers/message/fusion: 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/message/fusion/mptbase.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c index d8c668d..49f8ec1 100644 --- a/drivers/message/fusion/mptbase.c +++ b/drivers/message/fusion/mptbase.c @@ -5954,8 +5954,10 @@ mpt_findImVolumes(MPT_ADAPTER *ioc) goto out; mem = kmalloc(iocpage2sz, GFP_KERNEL); - if (!mem) + if (!mem) { + rc = -ENOMEM; goto out; + } memcpy(mem, (u8 *)pIoc2, iocpage2sz); ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;