lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VcTpAkMeKa0YXpp91WooVPs5X7jPGk0w2ruitp4siKLVw@mail.gmail.com>
Date:   Tue, 22 May 2018 01:13:56 +0300
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Yisheng Xie <xieyisheng1@...wei.com>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Ingo Molnar <mingo@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH 27/33] sched/debug: use match_string() helper

On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie <xieyisheng1@...wei.com> wrote:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.
>
> Cc: Ingo Molnar <mingo@...hat.com>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Signed-off-by: Yisheng Xie <xieyisheng1@...wei.com>
> ---
>  kernel/sched/debug.c | 20 +++++++++-----------
>  1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 15b10e2..9e34499 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -111,16 +111,14 @@ static int sched_feat_set(char *cmp)
>                 cmp += 3;
>         }
>
> -       for (i = 0; i < __SCHED_FEAT_NR; i++) {
> -               if (strcmp(cmp, sched_feat_names[i]) == 0) {
> -                       if (neg) {
> -                               sysctl_sched_features &= ~(1UL << i);
> -                               sched_feat_disable(i);
> -                       } else {
> -                               sysctl_sched_features |= (1UL << i);
> -                               sched_feat_enable(i);
> -                       }
> -                       break;
> +       i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);

> +       if (i >= 0) {

Why not

if (i < 0)
 return i;

?

> +               if (neg) {
> +                       sysctl_sched_features &= ~(1UL << i);
> +                       sched_feat_disable(i);
> +               } else {
> +                       sysctl_sched_features |= (1UL << i);
> +                       sched_feat_enable(i);
>                 }
>         }
>
> @@ -150,7 +148,7 @@ static int sched_feat_set(char *cmp)
>         inode_lock(inode);
>         i = sched_feat_set(cmp);
>         inode_unlock(inode);

> -       if (i == __SCHED_FEAT_NR)
> +       if (i < 0)
>                 return -EINVAL;

Now it would be

if (i < 0)
 return i;

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ