All of lore.kernel.org
 help / color / mirror / Atom feed
* re: [PATCH bpf-next v3 1/2] bpf: add bpf_strcasecmp kfunc
@ 2025-09-03 11:35 Sebastian Ramadan
  0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Ramadan @ 2025-09-03 11:35 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org

Hi,

While reviewing the recent patch ([PATCH bpf-next v3 1/2] bpf: add
bpf_strcasecmp kfunc), I noticed a small but important standards
compliance issue regarding the use of tolower() with char variables:

char c1, c2;
// ...
if (ignore_case) {
    c1 = tolower(c1);
    c2 = tolower(c2);
}

According to the ISO C standard, functions and macros in <ctype.h>
(such as tolower()) are only defined for arguments that are either:
1/ Representable as an unsigned char, or
2/ Equal to the special value EOF.

Passing a plain char that contains a negative value (other than EOF)
results in undefined behavior. This can easily go unnoticed in
environments where char defaults to unsigned (such as GCC on x86), but
will break or behave unpredictably on platforms where char is signed.

To ensure portable and defined behavior, it's typically recommended to
cast to unsigned char before passing to tolower():

c1 = tolower((unsigned char)c1);
c2 = tolower((unsigned char)c2);

This ensures compliance with the standard and avoids silent issues
across different toolchains and architectures.

While this may not cause immediate problems in the GNU-C ecosystem,
implicitly relying on compiler-specific behavior can gradually reduce
the kernel's portability. Keeping these cases in check helps maintain
the kernel's long-standing goal of wide platform support.

Thanks for your time, and for the ongoing work toward clean and
portable kernel code.

Regards, Sebastian Ramadan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-03 11:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1756804522.git.rtoax@foxmail.com>
2025-09-02  9:19 ` [PATCH bpf-next v3 1/2] bpf: add bpf_strcasecmp kfunc Rong Tao
2025-09-02  9:45   ` Viktor Malik
2025-09-02 16:54   ` Yonghong Song
2025-09-02 23:49     ` Rong Tao
2025-09-02  9:19 ` [PATCH bpf-next v3 2/2] selftests/bpf: Test kfunc bpf_strcasecmp Rong Tao
2025-09-03 11:35 [PATCH bpf-next v3 1/2] bpf: add bpf_strcasecmp kfunc Sebastian Ramadan

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.