linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Steven Rostedt <srostedt@redhat.com>, Ingo Molnar <mingo@elte.hu>,
	"David S. Miller" <davem@davemloft.net>,
	sparclinux <sparclinux@vger.kernel.org>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] module: clean up initialization of variable
Date: Mon, 5 Jan 2009 15:30:25 -0500 (EST)	[thread overview]
Message-ID: <alpine.DEB.1.10.0901051523370.25066@gandalf.stny.rr.com> (raw)
In-Reply-To: <20090105195415.GA6204@uranus.ravnborg.org>



Impact: clean up

On Mon, 5 Jan 2009, Sam Ravnborg wrote:
> 
> Fully ageed on the readability.
> I happen to trigger this as an error in the sparc code.
> But I see the same warning also in generic code.
> 
> >From kernel/module.c:
>         /* Suck in entire file: we'll want most of it. */
>         /* vmalloc barfs on "unusual" numbers.  Check here */
>         if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
>                 return ERR_PTR(-ENOMEM);
> 
> 
> This gives following warning:
> kernel/module.c: In function `load_module':
> kernel/module.c:1842: warning: 'hdr' might be used uninitialized in this function

The above is caused by having the branch tracer on and the following type 
of initialization:

	if (x || !(y = init_me())
		return;

	use_me(y);

This is sloppy initialization because it initializes, not only in an
if condition, but also as the second part of a complex conditional.

This patch makes the code a bit easier to read.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Reported-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/kernel/module.c b/kernel/module.c
index 9712c52..112d6cd 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1864,7 +1864,10 @@ static noinline struct module *load_module(void __user *umod,
 
 	/* Suck in entire file: we'll want most of it. */
 	/* vmalloc barfs on "unusual" numbers.  Check here */
-	if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
+	if (len > 64 * 1024 * 1024)
+		return ERR_PTR(-ENOMEM);
+	hdr = vmalloc(len);
+	if (hdr == NULL)
 		return ERR_PTR(-ENOMEM);
 	if (copy_from_user(hdr, umod, len) != 0) {
 		err = -EFAULT;

  parent reply	other threads:[~2009-01-05 20:30 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-05 18:19 ftrace breaks sparc64 build Sam Ravnborg
2009-01-05 19:31 ` Steven Rostedt
2009-01-05 19:42   ` [PATCH] sparc: make proces_ver_nack a bit more readable Steven Rostedt
2009-01-05 19:46     ` Steven Rostedt
2009-01-05 19:56     ` Steven Rostedt
2009-01-05 20:07       ` Sam Ravnborg
2009-01-05 20:08     ` Sam Ravnborg
2009-01-06 18:23       ` David Miller
2009-01-05 19:54   ` ftrace breaks sparc64 build Sam Ravnborg
2009-01-05 20:05     ` Steven Rostedt
2009-01-05 21:31       ` Sam Ravnborg
2009-01-05 21:52         ` Steven Rostedt
2009-01-05 22:01           ` Sam Ravnborg
2009-01-05 22:14             ` Steven Rostedt
2009-01-05 23:11               ` Heiko Carstens
2009-01-06  2:07                 ` Steven Rostedt
2009-01-06  9:36                   ` Heiko Carstens
2009-01-06  4:30                 ` Steven Rostedt
2009-01-06  9:45                   ` Heiko Carstens
2009-01-06 18:32       ` David Miller
2009-01-06 18:52         ` Steven Rostedt
2009-01-06 19:01           ` David Miller
2009-01-06 19:52             ` Sam Ravnborg
2009-01-06 20:02               ` David Miller
2009-01-05 20:30     ` Steven Rostedt [this message]
2009-01-05 22:59       ` [PATCH] module: clean up initialization of variable Harvey Harrison
2009-01-06  1:22       ` Rusty Russell
2009-01-06  2:02         ` Steven Rostedt
2009-01-05 19:48 ` ftrace breaks sparc64 build Al Viro
2009-01-05 19:55   ` Sam Ravnborg
2009-01-06  7:53     ` Jan Beulich
2009-01-06 11:35       ` Al Viro
2009-01-06 12:39         ` Jan Beulich
2009-01-06 13:34         ` Sam Ravnborg
2009-01-06 15:52           ` Al Viro
2009-01-06 18:39           ` David Miller
2009-01-08  9:28         ` Jan Beulich

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=alpine.DEB.1.10.0901051523370.25066@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rusty@rustcorp.com.au \
    --cc=sam@ravnborg.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=srostedt@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).