From patchwork Fri Oct 15 13:00:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 67948 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8834CB6EE8 for ; Fri, 15 Oct 2010 23:56:37 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754855Ab0JOMyK (ORCPT ); Fri, 15 Oct 2010 08:54:10 -0400 Received: from mgw2.diku.dk ([130.225.96.92]:56472 "EHLO mgw2.diku.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754331Ab0JOMyJ (ORCPT ); Fri, 15 Oct 2010 08:54:09 -0400 Received: from localhost (localhost [127.0.0.1]) by mgw2.diku.dk (Postfix) with ESMTP id 70F0619BCCD; Fri, 15 Oct 2010 14:54:08 +0200 (CEST) Received: from mgw2.diku.dk ([127.0.0.1]) by localhost (mgw2.diku.dk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 16937-04; Fri, 15 Oct 2010 14:54:06 +0200 (CEST) Received: from palace.topps.diku.dk (palace.ekstranet.diku.dk [192.38.115.202]) by mgw2.diku.dk (Postfix) with ESMTP id F41AA19BCCC; Fri, 15 Oct 2010 14:54:05 +0200 (CEST) From: Julia Lawall To: Samuel Ortiz Cc: kernel-janitors@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] drivers/net/irda/irtty-sir.c: Return -ENOMEM on memory allocation failure Date: Fri, 15 Oct 2010 15:00:04 +0200 Message-Id: <1287147610-8041-1-git-send-email-julia@diku.dk> X-Mailer: git-send-email 1.7.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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. The initial value of ret as 0 is never used, so drop the initialization. A simplified version of the semantic match that finds the first 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/net/irda/irtty-sir.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -u -p a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c --- a/drivers/net/irda/irtty-sir.c +++ b/drivers/net/irda/irtty-sir.c @@ -426,7 +426,7 @@ static int irtty_open(struct tty_struct { struct sir_dev *dev; struct sirtty_cb *priv; - int ret = 0; + int ret; /* Module stuff handled via irda_ldisc.owner - Jean II */ @@ -459,8 +459,10 @@ static int irtty_open(struct tty_struct /* allocate private device info block */ priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) + if (!priv) { + ret = -ENOMEM; goto out_put; + } priv->magic = IRTTY_MAGIC; priv->tty = tty;