[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANhBUQ3beB_aHMJSy9G942oUo_BT=x0w3gB3Vip_-nJxVjqu8A@mail.gmail.com>
Date: Thu, 1 Aug 2019 16:07:47 +0800
From: Chuhong Yuan <hslester96@...il.com>
To: Pavel Machek <pavel@....cz>
Cc: "Rafael J . Wysocki" <rjw@...ysocki.net>,
Len Brown <len.brown@...el.com>, linux-pm@...r.kernel.org,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 07/12] power: Replace strncmp with str_has_prefix
Pavel Machek <pavel@....cz> 于2019年7月30日周二 上午3:15写道:
>
> On Mon 2019-07-29 23:14:54, Chuhong Yuan wrote:
> > strncmp(str, const, len) is error-prone.
> > We had better use newly introduced
> > str_has_prefix() instead of it.
> >
> > Signed-off-by: Chuhong Yuan <hslester96@...il.com>
> > ---
> > kernel/power/hibernate.c | 8 ++++----
> > kernel/power/main.c | 2 +-
> > 2 files changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> > index cd7434e6000d..49d4bfdb2b67 100644
> > --- a/kernel/power/hibernate.c
> > +++ b/kernel/power/hibernate.c
> > @@ -1188,15 +1188,15 @@ static int __init resume_offset_setup(char *str)
> >
> > static int __init hibernate_setup(char *str)
> > {
> > - if (!strncmp(str, "noresume", 8)) {
> > + if (str_has_prefix(str, "noresume")) {
> > noresume = 1;
> > - } else if (!strncmp(str, "nocompress", 10)) {
> > + } else if (str_has_prefix(str, "nocompress")) {
> > nocompress = 1;
>
> Ok, old code is bad, too... but this makes the error visible. We do
> not want "noresumenextmonday" to set noresume = 1, right?
>
I am not clear about the semantic of the code.
Therefore, what is the right way to fix this error?
> Pavel
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Powered by blists - more mailing lists