Re: [PATCH v3 4/8] printk: Replace strncmp with str_has_prefix
From: Geert Uytterhoeven
Date: Tue Aug 06 2019 - 04:08:12 EST
Hi Chuhong,
On Mon, Aug 5, 2019 at 2:24 PM Chuhong Yuan <hslester96@xxxxxxxxx> wrote:
> strncmp(str, const, len) is error-prone because len
> is easy to have typo.
> The example is the hard-coded len has counting error
> or sizeof(const) forgets - 1.
> So we prefer using newly introduced str_has_prefix()
> to substitute such strncmp to make code better.
>
> Signed-off-by: Chuhong Yuan <hslester96@xxxxxxxxx>
Thanks for your patch!
> --- a/kernel/printk/braille.c
> +++ b/kernel/printk/braille.c
> @@ -11,11 +11,13 @@
>
> int _braille_console_setup(char **str, char **brl_options)
> {
> - if (!strncmp(*str, "brl,", 4)) {
> + size_t len;
> +
> + if ((len = str_has_prefix(*str, "brl,"))) {
Please write this as
len = str_has_prefix(*str, "brl,");
if (len) {
(everywhere)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds