From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755782Ab0JOMyg (ORCPT ); Fri, 15 Oct 2010 08:54:36 -0400 Received: from mgw2.diku.dk ([130.225.96.92]:56490 "EHLO mgw2.diku.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755330Ab0JOMyL (ORCPT ); Fri, 15 Oct 2010 08:54:11 -0400 From: Julia Lawall To: "James E.J. Bottomley" Cc: kernel-janitors@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] drivers/scsi/libsas/sas_ata.c: Return -ENOMEM on memory allocation failure Date: Fri, 15 Oct 2010 15:00:08 +0200 Message-Id: <1287147610-8041-5-git-send-email-julia@diku.dk> X-Mailer: git-send-email 1.7.1 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/scsi/libsas/sas_ata.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff -u -p a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -464,8 +464,10 @@ static int sas_execute_task(struct sas_t if (dma_dir != DMA_NONE) { scatter = kzalloc(sizeof(*scatter), GFP_KERNEL); - if (!scatter) + if (!scatter) { + res = -ENOMEM; goto out; + } sg_init_one(scatter, buffer, size); num_scatter = 1;