All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gioh Kim <gi-oh.kim@ionos.com>
To: Jinpu Wang <jinpu.wang@ionos.com>
Cc: open list <linux-kernel@vger.kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Dan Williams <dan.j.williams@intel.com>,
	laniel_francis@privacyrequired.com,
	Kees Cook <keescook@chromium.org>,
	dja@axtens.net, Andrew Morton <akpm@linux-foundation.org>,
	Haris Iqbal <haris.iqbal@ionos.com>
Subject: Re: [PATCH v3] lib/string: Introduce sysfs_streqcase
Date: Thu, 8 Apr 2021 15:06:53 +0200	[thread overview]
Message-ID: <CAJX1YtbVMMppbsqJ+fWECxzagnUEGdWT0DmQ+iaQY+SBL=E_jQ@mail.gmail.com> (raw)
In-Reply-To: <CAMGffEkApJiMwdLF75c_539jKLkSPtVqNTFY2byR0Fe5XoiNzw@mail.gmail.com>

Hi Jinpu,

I removed #ifdef CONFIG_SYSFS ~ #endif.
Could you please review again?

On Thu, Apr 8, 2021 at 12:50 PM Jinpu Wang <jinpu.wang@ionos.com> wrote:
>
> On Thu, Apr 8, 2021 at 11:34 AM Gioh Kim <gi-oh.kim@ionos.com> wrote:
> >
> > As the name shows, it checks if strings are equal in case insensitive
> > manner.
> >
> > For example, drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c uses
> > strncasecmp to check that the input via sysfs is "mi". But it would
> > work even-if the input is "min-wrongcommand".
> >
> > I found some more cases using strncasecmp to check the entire string
> > such as rtrs-clt-sysfs.c does. drivers/pnp/interface.c checks
> > "disable" command with strncasecmp but it would also work if the
> > command is "disable-wrong".
> >
> > Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com>
> It looks good to me.
> Reviewed-by: Jack Wang <jinpu.wang@ionos.com>
> > ---
> >  include/linux/string.h |  1 +
> >  lib/string.c           | 38 ++++++++++++++++++++++++++++++--------
> >  2 files changed, 31 insertions(+), 8 deletions(-)
> >
> > diff --git a/include/linux/string.h b/include/linux/string.h
> > index 4fcfb56abcf5..36d00ff8013e 100644
> > --- a/include/linux/string.h
> > +++ b/include/linux/string.h
> > @@ -184,6 +184,7 @@ extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
> >  extern void argv_free(char **argv);
> >
> >  extern bool sysfs_streq(const char *s1, const char *s2);
> > +extern bool sysfs_streqcase(const char *s1, const char *s2);
> >  extern int kstrtobool(const char *s, bool *res);
> >  static inline int strtobool(const char *s, bool *res)
> >  {
> > diff --git a/lib/string.c b/lib/string.c
> > index 7548eb715ddb..cb53845cc4ac 100644
> > --- a/lib/string.c
> > +++ b/lib/string.c
> > @@ -687,6 +687,18 @@ char *strsep(char **s, const char *ct)
> >  EXPORT_SYMBOL(strsep);
> >  #endif
> >
> > +#ifdef CONFIG_SYSFS
> > +static inline bool __streq_terminal(const char *s1, const char *s2)
> > +{
> > +       if (*s1 == *s2)
> > +               return true;
> > +       if (!*s1 && *s2 == '\n' && !s2[1])
> > +               return true;
> > +       if (*s1 == '\n' && !s1[1] && !*s2)
> > +               return true;
> > +       return false;
> > +}
> > +
> >  /**
> >   * sysfs_streq - return true if strings are equal, modulo trailing newline
> >   * @s1: one string
> > @@ -703,17 +715,27 @@ bool sysfs_streq(const char *s1, const char *s2)
> >                 s1++;
> >                 s2++;
> >         }
> > -
> > -       if (*s1 == *s2)
> > -               return true;
> > -       if (!*s1 && *s2 == '\n' && !s2[1])
> > -               return true;
> > -       if (*s1 == '\n' && !s1[1] && !*s2)
> > -               return true;
> > -       return false;
> > +       return __streq_terminal(s1, s2);
> >  }
> >  EXPORT_SYMBOL(sysfs_streq);
> >
> > +/**
> > + * sysfs_streqcase - same to sysfs_streq and case insensitive
> > + * @s1: one string
> > + * @s2: another string
> > + *
> > + */
> > +bool sysfs_streqcase(const char *s1, const char *s2)
> > +{
> > +       while (*s1 && tolower(*s1) == tolower(*s2)) {
> > +               s1++;
> > +               s2++;
> > +       }
> > +       return __streq_terminal(s1, s2);
> > +}
> > +EXPORT_SYMBOL(sysfs_streqcase);
> > +#endif
> > +
> >  /**
> >   * match_string - matches given string in an array
> >   * @array:     array of strings
> > --
> > 2.25.1
> >

  reply	other threads:[~2021-04-08 13:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08  9:33 [PATCH v3] lib/string: Introduce sysfs_streqcase Gioh Kim
2021-04-08 10:50 ` Jinpu Wang
2021-04-08 13:06   ` Gioh Kim [this message]
2021-04-08 12:36 ` kernel test robot
2021-04-08 12:36   ` kernel test robot
2021-04-08 14:00 ` kernel test robot
2021-04-08 14:00   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJX1YtbVMMppbsqJ+fWECxzagnUEGdWT0DmQ+iaQY+SBL=E_jQ@mail.gmail.com' \
    --to=gi-oh.kim@ionos.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=dja@axtens.net \
    --cc=haris.iqbal@ionos.com \
    --cc=jinpu.wang@ionos.com \
    --cc=keescook@chromium.org \
    --cc=laniel_francis@privacyrequired.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.