[PATCH] small binfmt_elf warning fix (copy_from_user return valuechecking)

From: Jesper Juhl
Date: Wed Oct 06 2004 - 16:49:43 EST



Since my patch to try and clean up all the warnings generated by
fs/binfmt_elf.c all at once seems to be ignored I'll try a different
approach; smaller patches fixing just a little bit at a time. Here's one
such tiny fix.

This is the warning that triggered this patch :
fs/binfmt_elf.c:1226: warning: ignoring return value of `copy_from_user', declared with attribute warn_unused_result

The patch silences the warning by actually using the return value, but in
this case there's no great harm done if the copy fails, psinfo has already
been zeroed, so a failed copy will just result in a few psinfo->pr_psargs
being zero (which as I read it is suboptimal but not fatal).
Even though we could safely ignore the return value we can gain a tiny
bennefit from it by using it to decrease the 'len' variable that is used
in the for() loop below - if copy to user failed to copy all data, then
there's no need for the loop to iterate over any more than what was
actually copied (and we know the rest is zeroed).

So, we get two small bennefits from this patch:
- Silence the warning by actually using the return value of copy_from_user
- If copy_from_user fails save a few loop iterations (at least then some
good came from a bad situation).

Signed-off-by: Jesper Juhl <juhl-lkml@xxxxxx>

diff -up linux-2.6.9-rc3-bk5-orig/fs/binfmt_elf.c linux-2.6.9-rc3-bk5/fs/binfmt_elf.c
--- linux-2.6.9-rc3-bk5-orig/fs/binfmt_elf.c 2004-09-30 05:04:32.000000000 +0200
+++ linux-2.6.9-rc3-bk5/fs/binfmt_elf.c 2004-10-06 23:21:22.000000000 +0200
@@ -1223,7 +1223,7 @@ static void fill_psinfo(struct elf_prpsi
len = mm->arg_end - mm->arg_start;
if (len >= ELF_PRARGSZ)
len = ELF_PRARGSZ-1;
- copy_from_user(&psinfo->pr_psargs,
+ len -= copy_from_user(&psinfo->pr_psargs,
(const char __user *)mm->arg_start, len);
for(i = 0; i < len; i++)
if (psinfo->pr_psargs[i] == 0)


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/