* [PATCH] sh: use sizeof() in memchunk_cmdline_override
@ 2026-04-23 12:04 Thorsten Blum
2026-04-24 11:05 ` Geert Uytterhoeven
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-04-23 12:04 UTC (permalink / raw)
To: Rich Felker, John Paul Adrian Glaubitz
Cc: Thorsten Blum, linux-sh, linux-kernel
Replace the hard-coded string length with 'sizeof("memchunk.") - 1' and
remove the comment.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/sh/mm/consistent.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c
index 0de206c1acfe..8f3a5bcbccfe 100644
--- 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;
if (!strncmp(name, p, k) && p[k] == '=') {
p += k + 1;
*sizep = memparse(p, NULL);
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] sh: use sizeof() in memchunk_cmdline_override
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
0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2026-04-24 11:05 UTC (permalink / raw)
To: Thorsten Blum
Cc: Rich Felker, John Paul Adrian Glaubitz, linux-sh, linux-kernel
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?
> if (!strncmp(name, p, k) && p[k] == '=') {
> p += k + 1;
> *sizep = memparse(p, NULL);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] sh: use sizeof() in memchunk_cmdline_override
2026-04-24 11:05 ` Geert Uytterhoeven
@ 2026-04-24 11:15 ` Thorsten Blum
2026-04-24 17:10 ` Thorsten Blum
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-04-24 11:15 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Rich Felker, John Paul Adrian Glaubitz, linux-sh, linux-kernel
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().
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] sh: use sizeof() in memchunk_cmdline_override
2026-04-24 11:15 ` Thorsten Blum
@ 2026-04-24 17:10 ` Thorsten Blum
0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-24 17:10 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Rich Felker, John Paul Adrian Glaubitz, linux-sh, linux-kernel
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-24 17:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox