[PATCH 6/9] Simplify bound checks in cifs for copy_from_user

From: Arjan van de Ven
Date: Sat Sep 26 2009 - 14:55:12 EST


From: Arjan van de Ven <arjan@xxxxxxxxxxxxxxx>
Subject: [PATCH 6/9] Simplify bound checks in cifs for copy_from_user
CC: Steve French <sfrench@xxxxxxxxx>

The CIFS code unfortunately hits a missed optimization in gcc
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41477)
where gcc can't prove to itself that count will not be larger than 11.

This patch simplifies the expression so that GCC does realize this,
giving slightly better code soon when copy_from_user() grows some checks.

Signed-off-by: Arjan van de Ven <arjan@xxxxxxxxxxxxxxx>

diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index 42cec2a..94b86da 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -732,11 +732,13 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
char flags_string[12];
char c;

- if ((count < 1) || (count > 11))
- return -EINVAL;
-
memset(flags_string, 0, 12);

+ if (count < 1)
+ return -EINVAL;
+ if (count > 11)
+ return -EINVAL;
+
if (copy_from_user(flags_string, buffer, count))
return -EFAULT;




--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org
--
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/