Re: [PATCH] sh: use sizeof() in memchunk_cmdline_override
Thorsten Blum <[email protected]>
| Newsgroups | gmane.linux.ports.sh.devel,gmane.linux.kernel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Apr 24, 2026 at 01:15:20PM +0200, Thorsten Blum wrote: > 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 <[email protected]> wrote: > > > Replace the hard-coded string length with 'sizeof("memchunk.") - 1' and > > > remove the comment. > > > > > > Signed-off-by: Thorsten Blum <[email protected]> > > > > 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(). More concretely, because __HAVE_ARCH_STRLEN is set in arch/sh/include/asm/string_32.h, strlen() resolves to the arch-specific assembly implementation in arch/sh/lib/strlen.S. However, constant folding is only guaranteed when calls go through __builtin_strlen(), e.g. via the wrapper in linux/fortify-string.h, which SH does not use with dreamcast_defconfig. I also checked the disassembly, and sh4-linux-gnu-gcc (Debian 14.2.0-19) did not optimize it into a constant.