Re: [PATCH 7/9] sys: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.

From: Dongsheng Yang
Date: Tue Feb 11 2014 - 22:59:56 EST


Hi Kees,

On 02/12/2014 02:27 AM, Kees Cook wrote:
On Mon, Feb 10, 2014 at 11:34 PM, Dongsheng Yang
<yangds.fnst@xxxxxxxxxxxxxx> wrote:
Signed-off-by: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx>
cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
cc: Oleg Nesterov <oleg@xxxxxxxxxx>
cc: Robin Holt <holt@xxxxxxx>
cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
cc: Kees Cook <keescook@xxxxxxxxxxxx>
cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
cc: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
cc: Ingo Molnar <mingo@xxxxxxxxxx>
---
kernel/sys.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index c0a58be..adaeab6 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)

/* normalize: avoid signed division (rounding problems) */
error = -ESRCH;
- if (niceval < -20)
- niceval = -20;
- if (niceval > 19)
- niceval = 19;
+ if (niceval < MIN_NICE)
+ niceval = MIN_NICE;
+ if (niceval > MAX_NICE)
+ niceval = MAX_NICE;
Good catch! I'm all for using names instead of numeric values,
however, I wonder if it'd be more readable to use "clamp" instead?

niceval = clamp(niceval, MIN_NICE, MAX_NICE);

Good suggestion! This patch here is just to replace the numeric values with
a name defined in prio.h. So I will send another patch to make it more readable
with clamp after the patch set here applied. Is this plan ok to you?

Thanx.

-Kees

rcu_read_lock();
read_lock(&tasklist_lock);
--
1.8.2.1




--
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/