From: Thorsten Blum <thorsten.blum@linux.dev>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sh: use sizeof() in memchunk_cmdline_override
Date: Fri, 24 Apr 2026 19:10:46 +0200 [thread overview]
Message-ID: <aeukFnPUqcm64-2_@linux.dev> (raw)
In-Reply-To: <aetQv3emr_o8kK-h@linux.dev>
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 <thorsten.blum@linux.dev> wrote:
> > > Replace the hard-coded string length with 'sizeof("memchunk.") - 1' and
> > > remove the comment.
> > >
> > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> >
> > 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.
prev parent reply other threads:[~2026-04-24 17:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 12:04 [PATCH] sh: use sizeof() in memchunk_cmdline_override Thorsten Blum
2026-04-24 11:05 ` Geert Uytterhoeven
2026-04-24 11:15 ` Thorsten Blum
2026-04-24 17:10 ` Thorsten Blum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aeukFnPUqcm64-2_@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=dalias@libc.org \
--cc=geert@linux-m68k.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox