All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <thomas@t-8ch.de>
Cc: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] tools/nolibc: add missing memchr() to string.h
Date: Sat, 21 Jun 2025 10:42:34 +0200	[thread overview]
Message-ID: <20250621084234.GA26934@1wt.eu> (raw)
In-Reply-To: <d7b81639-c53c-4186-9e30-04137576a1f1@t-8ch.de>

On Sat, Jun 21, 2025 at 10:27:11AM +0200, Thomas Weißschuh wrote:
> On 2025-06-20 12:02:51+0200, Willy Tarreau wrote:
> > Surprisingly we forgot to add this common one. It was added with a
> > per-arch guard allowing to later implement it in arch-specific asm
> > code like was done for a few other ones.
> > 
> > The test verifies that we don't search past the indicated length.
> > 
> > Signed-off-by: Willy Tarreau <w@1wt.eu>
> > ---
> >  tools/include/nolibc/string.h                | 15 +++++++++++++++
> >  tools/testing/selftests/nolibc/nolibc-test.c |  2 ++
> >  2 files changed, 17 insertions(+)
> > 
> > diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h
> > index 163a17e7dd38b..4000926f44ac4 100644
> > --- a/tools/include/nolibc/string.h
> > +++ b/tools/include/nolibc/string.h
> > @@ -93,6 +93,21 @@ void *memset(void *dst, int b, size_t len)
> >  }
> >  #endif /* #ifndef NOLIBC_ARCH_HAS_MEMSET */
> >  
> > +#ifndef NOLIBC_ARCH_HAS_MEMCHR
> 
> So far we only have added these guards when necessary,
> which they aren't here. Can we drop them?

I intentionally placed them so that we can easily override them,
as we did for the other ones on x86 where string operations are
super short (repnz scasb is two bytes once you have the registers
already loaded).

> > +static __attribute__((unused))
> > +void *memchr(const void *s, int c, size_t len)
> > +{
> > +	char *p = (char *)s;
> 
> The docs say that they are interpreted as "unsigned char".

It does not change anything here, except adding an extra
modifier (since we'll then also have to do it in the loop
when comparing against c), thus IMHO it's extra noise.

> Also, can we keep the const?

It's memchr()'s definition which requires to return a void* so the
const needs to be dropped somewhere. Here I found visually cleaner to
have a single cast during the variable assignment rather than have a
second one on the return statement. But it's a matter of taste. I
tend to hate casts as they confuse the reader and remove the ability
of the compiler to produce relevant warnings, so for me the less the
better.

Thanks,
Willy

  reply	other threads:[~2025-06-21  8:42 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20 10:02 [PATCH 0/4] tools/nolibc: assorted fixes and small updates Willy Tarreau
2025-06-20 10:02 ` [PATCH 1/4] tools/nolibc: fix misleading help message regarding installation path Willy Tarreau
2025-06-20 10:02 ` [PATCH 2/4] tools/nolibc: add the more portable inttypes.h Willy Tarreau
2025-06-20 10:02 ` [PATCH 3/4] tools/nolibc: move FD_* definitions to sys/select.h Willy Tarreau
2025-06-21  8:21   ` Thomas Weißschuh
2025-06-22  7:19     ` Willy Tarreau
2025-06-22 19:58       ` Thomas Weißschuh
2025-06-23  2:56         ` Willy Tarreau
2025-06-29  8:46           ` Willy Tarreau
2025-06-29  8:53             ` Thomas Weißschuh
2025-06-29  9:25               ` Willy Tarreau
2025-06-29  9:37                 ` Thomas Weißschuh
2025-06-29  9:40                   ` Willy Tarreau
2025-06-29 15:10                     ` Willy Tarreau
2025-06-29 15:54                       ` Thomas Weißschuh
2025-06-29 16:08                         ` Willy Tarreau
2025-06-29 16:14                           ` Thomas Weißschuh
2025-06-29 16:19                             ` Willy Tarreau
2025-06-29 16:27                               ` Thomas Weißschuh
2025-06-29 17:56                                 ` Willy Tarreau
2025-06-20 10:02 ` [PATCH 4/4] tools/nolibc: add missing memchr() to string.h Willy Tarreau
2025-06-21  8:27   ` Thomas Weißschuh
2025-06-21  8:42     ` Willy Tarreau [this message]
2025-06-22 19:56       ` Thomas Weißschuh
2025-06-23  3:01         ` Willy Tarreau

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=20250621084234.GA26934@1wt.eu \
    --to=w@1wt.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=thomas@t-8ch.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.