mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kernel/itimer.c use ternary operators where appropriate and fix all style issues.
@ 2011-03-24 17:26 Michael Rodriguez
  2011-03-24 17:41 ` Alexey Dobriyan
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Rodriguez @ 2011-03-24 17:26 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel, Michael Rodriguez

Signed-off-by: Michael Rodriguez <dkingston02@gmail.com>
---
 kernel/itimer.c |   32 +++++++++++---------------------
 1 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/kernel/itimer.c b/kernel/itimer.c
index d802883..d07ace5 100644
--- a/kernel/itimer.c
+++ b/kernel/itimer.c
@@ -12,10 +12,9 @@
 #include <linux/time.h>
 #include <linux/posix-timers.h>
 #include <linux/hrtimer.h>
+#include <linux/uaccess.h>
 #include <trace/events/timer.h>
 
-#include <asm/uaccess.h>
-
 /**
  * itimer_get_remtime - get remaining time for the timer
  *
@@ -33,12 +32,8 @@ static struct timeval itimer_get_remtime(struct hrtimer *timer)
 	 * hrtimer_get_remtime() call but before this condition
 	 * then we return 0 - which is correct.
 	 */
-	if (hrtimer_active(timer)) {
-		if (rem.tv64 <= 0)
-			rem.tv64 = NSEC_PER_USEC;
-	} else
-		rem.tv64 = 0;
-
+	rem.tv64 = ((hrtimer_active(timer) && rem.tv64 <= 0) ?
+			NSEC_PER_USEC : 0);
 	return ktime_to_timeval(rem);
 }
 
@@ -57,17 +52,12 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
 		cputime_t t;
 
 		thread_group_cputimer(tsk, &cputime);
-		if (clock_id == CPUCLOCK_PROF)
-			t = cputime_add(cputime.utime, cputime.stime);
-		else
-			/* CPUCLOCK_VIRT */
-			t = cputime.utime;
-
-		if (cputime_le(cval, t))
-			/* about to fire */
-			cval = cputime_one_jiffy;
-		else
-			cval = cputime_sub(cval, t);
+
+		t = (clock_id == CPUCLOCK_PROF) ? cputime_add(cputime.utime,
+			cputime.stime) : cputime.utime;
+
+		cval = (cputime_le(cval, t) ? cputime_one_jiffy :
+			cputime_sub(cval, t));
 	}
 
 	spin_unlock_irq(&tsk->sighand->siglock);
@@ -95,7 +85,7 @@ int do_getitimer(int which, struct itimerval *value)
 		get_cpu_itimer(tsk, CPUCLOCK_PROF, value);
 		break;
 	default:
-		return(-EINVAL);
+		return -EINVAL;
 	}
 	return 0;
 }
@@ -283,7 +273,7 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value,
 	int error;
 
 	if (value) {
-		if(copy_from_user(&set_buffer, value, sizeof(set_buffer)))
+		if (copy_from_user(&set_buffer, value, sizeof(set_buffer)))
 			return -EFAULT;
 	} else
 		memset((char *) &set_buffer, 0, sizeof(set_buffer));
-- 
1.7.4.1


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

* Re: [PATCH] kernel/itimer.c use ternary operators where appropriate and fix all style issues.
  2011-03-24 17:26 [PATCH] kernel/itimer.c use ternary operators where appropriate and fix all style issues Michael Rodriguez
@ 2011-03-24 17:41 ` Alexey Dobriyan
  0 siblings, 0 replies; 2+ messages in thread
From: Alexey Dobriyan @ 2011-03-24 17:41 UTC (permalink / raw)
  To: Michael Rodriguez; +Cc: tglx, linux-kernel

On Thu, Mar 24, 2011 at 01:26:03PM -0400, Michael Rodriguez wrote:
> @@ -33,12 +32,8 @@ static struct timeval itimer_get_remtime(struct hrtimer *timer)
>  	 * hrtimer_get_remtime() call but before this condition
>  	 * then we return 0 - which is correct.
>  	 */
> -	if (hrtimer_active(timer)) {
> -		if (rem.tv64 <= 0)
> -			rem.tv64 = NSEC_PER_USEC;
> -	} else
> -		rem.tv64 = 0;
> -
> +	rem.tv64 = ((hrtimer_active(timer) && rem.tv64 <= 0) ?
> +			NSEC_PER_USEC : 0);

NAK, not equivalent code.

>  	return ktime_to_timeval(rem);
>  }
>  
> @@ -57,17 +52,12 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
>  		cputime_t t;
>  
>  		thread_group_cputimer(tsk, &cputime);
> -		if (clock_id == CPUCLOCK_PROF)
> -			t = cputime_add(cputime.utime, cputime.stime);
> -		else
> -			/* CPUCLOCK_VIRT */
> -			t = cputime.utime;
> -
> -		if (cputime_le(cval, t))
> -			/* about to fire */
> -			cval = cputime_one_jiffy;
> -		else
> -			cval = cputime_sub(cval, t);
> +
> +		t = (clock_id == CPUCLOCK_PROF) ? cputime_add(cputime.utime,
> +			cputime.stime) : cputime.utime;
> +
> +		cval = (cputime_le(cval, t) ? cputime_one_jiffy :
> +			cputime_sub(cval, t));

This code is not more readable than original one.

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

end of thread, other threads:[~2011-03-24 17:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-24 17:26 [PATCH] kernel/itimer.c use ternary operators where appropriate and fix all style issues Michael Rodriguez
2011-03-24 17:41 ` Alexey Dobriyan

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

all inboxes | Powered by JetHome®