public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kernel/itimer.c: beautify code, not need check 'value', so save one instruction, simpler and easier for readers.
@ 2013-06-20 11:26 Chen Gang
  2013-06-20 12:02 ` Chen Gang
  2013-06-20 13:42 ` Thomas Gleixner
  0 siblings, 2 replies; 12+ messages in thread
From: Chen Gang @ 2013-06-20 11:26 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: linux-kernel@vger.kernel.org


Since copy_to_user() will check 'value', we do not need check it outside
again,  so can save one comparing instruction at least.

Also can let code simpler and easier for readers: if checking parameter
'value', it will easily lead readers to think about why not return
-EINVAL instead of -EFAULT, when checking parameter failed.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/itimer.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/kernel/itimer.c b/kernel/itimer.c
index 8d262b4..3b12271 100644
--- a/kernel/itimer.c
+++ b/kernel/itimer.c
@@ -102,15 +102,14 @@ int do_getitimer(int which, struct itimerval *value)
 
 SYSCALL_DEFINE2(getitimer, int, which, struct itimerval __user *, value)
 {
-	int error = -EFAULT;
+	int error;
 	struct itimerval get_buffer;
 
-	if (value) {
-		error = do_getitimer(which, &get_buffer);
-		if (!error &&
-		    copy_to_user(value, &get_buffer, sizeof(get_buffer)))
-			error = -EFAULT;
-	}
+	error = do_getitimer(which, &get_buffer);
+	if (!error &&
+	    copy_to_user(value, &get_buffer, sizeof(get_buffer)))
+		error = -EFAULT;
+
 	return error;
 }
 
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-07-22  2:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 11:26 [PATCH v2] kernel/itimer.c: beautify code, not need check 'value', so save one instruction, simpler and easier for readers Chen Gang
2013-06-20 12:02 ` Chen Gang
2013-06-20 12:55   ` Thomas Gleixner
2013-06-21  1:24     ` Chen Gang
2013-06-20 13:42 ` Thomas Gleixner
2013-06-21  2:04   ` Chen Gang
2013-06-21 10:31     ` [PATCH v3] kernel/itimer.c: remove the checking 'value' statement Chen Gang
2013-06-24 23:28     ` [PATCH v2] kernel/itimer.c: beautify code, not need check 'value', so save one instruction, simpler and easier for readers.t Thomas Gleixner
2013-06-25  0:58       ` Chen Gang
2013-06-25  1:16         ` [PATH v4] itimers: Remove bogus NULL pointer check in sys_getitimer() Chen Gang
2013-07-05  1:28           ` Chen Gang
2013-07-22  2:45             ` Chen Gang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox