public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Julia Lawall <Julia.Lawall@lip6.fr>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
	Julia.Lawall@lip6.fr, tglx@linutronix.de
Subject: [tip:x86/urgent] arch/x86/kernel/kdebugfs.c: Ensure a consistent return value in error case
Date: Thu, 26 Jul 2012 08:19:55 -0700	[thread overview]
Message-ID: <tip-41fb433b63cc4745f4918fdaf295763da5ca826c@git.kernel.org> (raw)
In-Reply-To: <1342284188-19176-7-git-send-email-Julia.Lawall@lip6.fr>

Commit-ID:  41fb433b63cc4745f4918fdaf295763da5ca826c
Gitweb:     http://git.kernel.org/tip/41fb433b63cc4745f4918fdaf295763da5ca826c
Author:     Julia Lawall <Julia.Lawall@lip6.fr>
AuthorDate: Sat, 14 Jul 2012 18:43:08 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 26 Jul 2012 15:07:20 +0200

arch/x86/kernel/kdebugfs.c: Ensure a consistent return value in error case

Typically, the return value desired for the failure of a
function with an integer return value is a negative integer.  In
these cases, the return value is sometimes a negative integer
and sometimes 0, due to a subsequent initialization of the
return variable within the loop.

A simplified version of the semantic match that finds this
problem is: (http://coccinelle.lip6.fr/)

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Link: http://lkml.kernel.org/r/1342284188-19176-7-git-send-email-Julia.Lawall@lip6.fr
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/kdebugfs.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
index 1d5d31e..dc1404b 100644
--- a/arch/x86/kernel/kdebugfs.c
+++ b/arch/x86/kernel/kdebugfs.c
@@ -107,7 +107,7 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 {
 	struct setup_data_node *node;
 	struct setup_data *data;
-	int error = -ENOMEM;
+	int error;
 	struct dentry *d;
 	struct page *pg;
 	u64 pa_data;
@@ -121,8 +121,10 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 
 	while (pa_data) {
 		node = kmalloc(sizeof(*node), GFP_KERNEL);
-		if (!node)
+		if (!node) {
+			error = -ENOMEM;
 			goto err_dir;
+		}
 
 		pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
 		if (PageHighMem(pg)) {

      reply	other threads:[~2012-07-26 15:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
2012-07-14 16:43 ` [PATCH 1/6] drivers/pci/hotplug/cpci_hotplug_core.c: " Julia Lawall
2012-07-14 16:43 ` [PATCH 2/6] drivers/net/can/softing/softing_main.c: " Julia Lawall
2012-07-15 20:21   ` Kurt Van Dijck
2012-07-16  7:34   ` Marc Kleine-Budde
2012-07-14 16:43 ` [PATCH 3/6] arch/arm/mach-netx/xc.c: " Julia Lawall
2012-07-14 16:43 ` [PATCH 4/6] drivers/cpuidle/sysfs.c: " Julia Lawall
2012-07-14 16:43 ` [PATCH 5/6] drivers/pci/hotplug: " Julia Lawall
2012-07-16 15:54   ` Bjorn Helgaas
2012-07-14 16:43 ` [PATCH 6/6] arch/x86/kernel/kdebugfs.c: " Julia Lawall
2012-07-26 15:19   ` tip-bot for Julia Lawall [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-41fb433b63cc4745f4918fdaf295763da5ca826c@git.kernel.org \
    --to=julia.lawall@lip6.fr \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox