From patchwork Mon Jan 5 20:30:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 16698 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.176.167]) by ozlabs.org (Postfix) with ESMTP id D4F8BDE0F8 for ; Tue, 6 Jan 2009 07:30:41 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753292AbZAEUaa (ORCPT ); Mon, 5 Jan 2009 15:30:30 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755133AbZAEUaa (ORCPT ); Mon, 5 Jan 2009 15:30:30 -0500 Received: from hrndva-omtalb.mail.rr.com ([71.74.56.123]:61317 "EHLO hrndva-omtalb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755110AbZAEUa2 (ORCPT ); Mon, 5 Jan 2009 15:30:28 -0500 Received: from gandalf ([74.67.89.75]) by hrndva-omta05.mail.rr.com with ESMTP id <20090105203026.JHOU18002.hrndva-omta05.mail.rr.com@gandalf>; Mon, 5 Jan 2009 20:30:26 +0000 Date: Mon, 5 Jan 2009 15:30:25 -0500 (EST) From: Steven Rostedt X-X-Sender: rostedt@gandalf.stny.rr.com To: Sam Ravnborg cc: LKML , Steven Rostedt , Ingo Molnar , "David S. Miller" , sparclinux , Rusty Russell , Andrew Morton Subject: [PATCH] module: clean up initialization of variable In-Reply-To: <20090105195415.GA6204@uranus.ravnborg.org> Message-ID: References: <20090105181922.GA25622@uranus.ravnborg.org> <20090105195415.GA6204@uranus.ravnborg.org> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.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 Reported-by: Sam Ravnborg --- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;