lkml.org 
[lkml]   [2014]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/3] sched: Use clamp() and clamp_val() to make it more readable.
On Wed, 05 Mar 2014 07:17:36 -0800
Joe Perches <joe@perches.com> wrote:

> On Wed, 2014-03-05 at 20:36 +0800, Dongsheng Yang wrote:
> > As Kees suggested, I use clamp() function to replace the if and
> > else branch, making it more readable and modular.
> >
> > Suggested-by: Kees Cook <keescook@chromium.org>
> > Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
> []
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> []
> > @@ -3070,17 +3070,10 @@ SYSCALL_DEFINE1(nice, int, increment)
> > * We don't have to worry. Conceptually one call occurs first
> > * and we have a single winner.
> > */
> > - if (increment < -40)
> > - increment = -40;
> > - if (increment > 40)
> > - increment = 40;
> > -
> > + increment = clamp(increment, -40, 40);
>
> Maybe:
>
> increment = clamp(increment, -(NICE_MAX - NICE_MIN + 1),
> , NICE_MAX - NICE_MIN + 1)

Ug, that's much harder to read.

>
> or add yet another define like #define NICE_RANGE
> or #define NICE_MAX_INCREMENT

Sure, if there's a NICE_MAX_INC == 40, then we could do:

increment = clamp(increment, -NICE_MAX_INC, NICE_MAX_INC);

-- Steve


\
 
 \ /
  Last update: 2014-03-06 06:01    [W:0.146 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site