Re: [RFC PATCH v1 07/12] efi: Replace strstarts() by str_has_prefix().

From: Francis Laniel
Date: Fri Dec 04 2020 - 12:20:34 EST


Le vendredi 4 décembre 2020, 18:07:11 CET Ard Biesheuvel a écrit :
> On Fri, 4 Dec 2020 at 18:06, <laniel_francis@xxxxxxxxxxxxxxxxxxx> wrote:
> > From: Francis Laniel <laniel_francis@xxxxxxxxxxxxxxxxxxx>
> >
> > The two functions indicates if a string begins with a given prefix.
> > The only difference is that strstarts() returns a bool while
> > str_has_prefix() returns the length of the prefix if the string begins
> > with it or 0 otherwise.
> Why?

The code works fine actually with the two functions, it is a fact.

Not long ago, I read string.h and saw that there was two functions doing the
same thing.
At this moment, I thought that it can be a good idea to replace one by another
so there is only one remaining function.

I think the benefit of this patch is that it makes the code a bit simpler.
I agree that this is not a huge benefit and that the code can stay in its
actual state.
I also marked this patch as RFC to get people's opinion about if they find it
useful or not.

> > Signed-off-by: Francis Laniel <laniel_francis@xxxxxxxxxxxxxxxxxxx>
> > ---
> >
> > drivers/firmware/efi/libstub/efi-stub-helper.c | 2 +-
> > drivers/firmware/efi/libstub/gop.c | 10 +++++-----
> > 2 files changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c
> > b/drivers/firmware/efi/libstub/efi-stub-helper.c index
> > aa8da0a49829..a502f549d900 100644
> > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > @@ -230,7 +230,7 @@ efi_status_t efi_parse_options(char const *cmdline)
> >
> > if (parse_option_str(val, "debug"))
> >
> > efi_loglevel = CONSOLE_LOGLEVEL_DEBUG;
> >
> > } else if (!strcmp(param, "video") &&
> >
> > - val && strstarts(val, "efifb:")) {
> > + val && str_has_prefix(val, "efifb:")) {
> >
> > efi_parse_option_graphics(val + strlen("efifb:"));
> >
> > }
> >
> > }
> >
> > diff --git a/drivers/firmware/efi/libstub/gop.c
> > b/drivers/firmware/efi/libstub/gop.c index ea5da307d542..fbe95b3cc96a
> > 100644
> > --- a/drivers/firmware/efi/libstub/gop.c
> > +++ b/drivers/firmware/efi/libstub/gop.c
> > @@ -39,7 +39,7 @@ static bool parse_modenum(char *option, char **next)
> >
> > {
> >
> > u32 m;
> >
> > - if (!strstarts(option, "mode="))
> > + if (!str_has_prefix(option, "mode="))
> >
> > return false;
> >
> > option += strlen("mode=");
> > m = simple_strtoull(option, &option, 0);
> >
> > @@ -65,10 +65,10 @@ static bool parse_res(char *option, char **next)
> >
> > h = simple_strtoull(option, &option, 10);
> > if (*option == '-') {
> >
> > option++;
> >
> > - if (strstarts(option, "rgb")) {
> > + if (str_has_prefix(option, "rgb")) {
> >
> > option += strlen("rgb");
> > pf = PIXEL_RGB_RESERVED_8BIT_PER_COLOR;
> >
> > - } else if (strstarts(option, "bgr")) {
> > + } else if (str_has_prefix(option, "bgr")) {
> >
> > option += strlen("bgr");
> > pf = PIXEL_BGR_RESERVED_8BIT_PER_COLOR;
> >
> > } else if (isdigit(*option))
> >
> > @@ -90,7 +90,7 @@ static bool parse_res(char *option, char **next)
> >
> > static bool parse_auto(char *option, char **next)
> > {
> >
> > - if (!strstarts(option, "auto"))
> > + if (!str_has_prefix(option, "auto"))
> >
> > return false;
> >
> > option += strlen("auto");
> > if (*option && *option++ != ',')
> >
> > @@ -103,7 +103,7 @@ static bool parse_auto(char *option, char **next)
> >
> > static bool parse_list(char *option, char **next)
> > {
> >
> > - if (!strstarts(option, "list"))
> > + if (!str_has_prefix(option, "list"))
> >
> > return false;
> >
> > option += strlen("list");
> > if (*option && *option++ != ',')
> >
> > --
> > 2.20.1