Re: [PATCH] sh: use sizeof() in memchunk_cmdline_override

From: Thorsten Blum

Date: Fri Apr 24 2026 - 07:23:08 EST


On Fri, Apr 24, 2026 at 01:05:48PM +0200, Geert Uytterhoeven wrote:
> Hi Thorsten,
>
> On Thu, 23 Apr 2026 at 14:10, Thorsten Blum <thorsten.blum@xxxxxxxxx> wrote:
> > Replace the hard-coded string length with 'sizeof("memchunk.") - 1' and
> > remove the comment.
> >
> > Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
>
> Thanks for your patch!
>
> > --- a/arch/sh/mm/consistent.c
> > +++ b/arch/sh/mm/consistent.c
> > @@ -23,7 +23,7 @@ static void __init memchunk_cmdline_override(char *name, unsigned long *sizep)
> > int k = strlen(name);
> >
> > while ((p = strstr(p, "memchunk."))) {
> > - p += 9; /* strlen("memchunk.") */
> > + p += sizeof("memchunk.") - 1;
>
> Can't you just use strlen() instead, i.e. won't the compiler optimize
> that into a constant?

That only works if ARCH_HAS_FORTIFY_SOURCE is selected, which is not the
case for arch/sh. Otherwise I would have used strlen().