From: Ralf Baechle <ralf@linux-mips.org>
To: bin.jiang@windriver.com
Cc: linux-mips@linux-mips.org
Subject: Re: [PATCH] MIPS: get_user: set the parameter @x to zero on error
Date: Tue, 18 Nov 2014 12:22:59 +0100 [thread overview]
Message-ID: <20141118112258.GQ24983@linux-mips.org> (raw)
In-Reply-To: <1416292496-6149-1-git-send-email-bin.jiang@windriver.com>
On Tue, Nov 18, 2014 at 02:34:56PM +0800, bin.jiang@windriver.com wrote:
> From: Bin Jiang <bin.jiang@windriver.com>
>
> The following compile warning is caused to use uninitialized variables:
>
> fs/compat_ioctl.c: In function 'compat_SyS_ioctl':
> arch/mips/include/asm/uaccess.h:451:2: warning: 'length' may be used \
> uninitialized in this function [-Wmaybe-uninitialized]
> __asm__ __volatile__( \
> ^
> fs/compat_ioctl.c:208:6: note: 'length' was declared here
> int length, err;
> ^
>
> In get_user function, the parameter @x is used to store result. If the
> function return error, the @x won't be set and cause above warning.
>
> According to the description of get_user function, the parameter @x should
> be set to zero on error.
You're not the first to send such a patch, see
http://patchwork.linux-mips.org/patch/1307/
However I've hesistated to apply the previous patch which only claimed to
resolve a warning because __get_user and get_user get expanded very often
in the kernel so a small innocent looking change like this results in a
surprisingly large bloat.
A smart compiler will reorder this:
int x;
if (...) {
...
} else
x = 0;
into:
int x = 0;
if (...) {
...
}
Which avoids the branches otherwise necessary for the else construct. However
both the original and your patch fail to take care of the case where the
if is taken but __get_user_asm aborts due to an inaccessible fault.
That case is only fixed by manually doing above reordering - a compiler can't
know that the inline assembler won't assign anything in that case.
The comment btw was cut and paste and - blame me - it seems I failed to read
what it promises about @x for the error case; I had implemented get_user under
the assumption that the returned value was undefined in case of an -EFAULT
error.
Thanks for reporting this!
Ralf
next prev parent reply other threads:[~2014-11-18 11:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-18 6:34 [PATCH] MIPS: get_user: set the parameter @x to zero on error bin.jiang
2014-11-18 6:34 ` bin.jiang
2014-11-18 11:22 ` Ralf Baechle [this message]
2014-11-18 17:19 ` Ralf Baechle
2014-11-18 20:48 ` Ralf Baechle
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=20141118112258.GQ24983@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=bin.jiang@windriver.com \
--cc=linux-mips@linux-mips.org \
/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