mbox series

[0/3] string.h: Use ARRAY_SIZE() for memtostr*()/strtomem*()

Message ID 20250206175216.work.225-kees@kernel.org (mailing list archive)
Headers show
Series string.h: Use ARRAY_SIZE() for memtostr*()/strtomem*() | expand

Message

Kees Cook Feb. 6, 2025, 6:11 p.m. UTC
Work around a Clang 14 bug by switching to ARRAY_SIZE() (with the
added benefit of explicitly checking for char array arguments) in
memtostr*/strtomem*().

-Kees

Kees Cook (3):
  compiler.h: Move C string helpers into C-only kernel section
  compiler.h: Introduce __must_be_char_array()
  string.h: Use ARRAY_SIZE() for memtostr*()/strtomem*()

 include/linux/compiler.h | 32 +++++++++++++++++++-------------
 include/linux/string.h   | 12 ++++++++----
 2 files changed, 27 insertions(+), 17 deletions(-)

Comments

Andy Shevchenko Feb. 6, 2025, 6:41 p.m. UTC | #1
On Thu, Feb 6, 2025 at 8:11 PM Kees Cook <kees@kernel.org> wrote:
>
> Work around a Clang 14 bug by switching to ARRAY_SIZE() (with the
> added benefit of explicitly checking for char array arguments) in
> memtostr*/strtomem*().

What's the minimum Clang version we build kernel with? 12?
Miguel Ojeda Feb. 6, 2025, 6:44 p.m. UTC | #2
On Thu, Feb 6, 2025 at 7:42 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> What's the minimum Clang version we build kernel with? 12?

13.0.1 for most architectures according to `scripts/min-tool-version.sh`.

Cheers,
Miguel
Andy Shevchenko Feb. 6, 2025, 6:45 p.m. UTC | #3
On Thu, Feb 6, 2025 at 8:44 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Feb 6, 2025 at 7:42 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > What's the minimum Clang version we build kernel with? 12?
>
> 13.0.1 for most architectures according to `scripts/min-tool-version.sh`.

Okay, does it mean 13 has no such a bug?
Otherwise the commit message and other comments might be clearer...
Kees Cook Feb. 6, 2025, 6:52 p.m. UTC | #4
On Thu, Feb 06, 2025 at 08:45:41PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 6, 2025 at 8:44 PM Miguel Ojeda
> <miguel.ojeda.sandonis@gmail.com> wrote:
> >
> > On Thu, Feb 6, 2025 at 7:42 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > >
> > > What's the minimum Clang version we build kernel with? 12?
> >
> > 13.0.1 for most architectures according to `scripts/min-tool-version.sh`.
> 
> Okay, does it mean 13 has no such a bug?

It probably did, but Clang 13 didn't support compile-time error messages
(added in 14). Regardless, this fixes it there and makes the API more
robust.

> Otherwise the commit message and other comments might be clearer...

How should I rephrase things? I mention the bug and when it was fixed
in patch 3:

  ...
  benefit of working around a bug in Clang (fixed[1] in 15+) that got
  ...

-Kees
Andy Shevchenko Feb. 6, 2025, 7:12 p.m. UTC | #5
On Thu, Feb 06, 2025 at 10:52:18AM -0800, Kees Cook wrote:
> On Thu, Feb 06, 2025 at 08:45:41PM +0200, Andy Shevchenko wrote:
> > On Thu, Feb 6, 2025 at 8:44 PM Miguel Ojeda
> > <miguel.ojeda.sandonis@gmail.com> wrote:
> > > On Thu, Feb 6, 2025 at 7:42 PM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > >
> > > > What's the minimum Clang version we build kernel with? 12?
> > >
> > > 13.0.1 for most architectures according to `scripts/min-tool-version.sh`.
> > 
> > Okay, does it mean 13 has no such a bug?
> 
> It probably did, but Clang 13 didn't support compile-time error messages
> (added in 14). Regardless, this fixes it there and makes the API more
> robust.
> 
> > Otherwise the commit message and other comments might be clearer...
> 
> How should I rephrase things? I mention the bug and when it was fixed
> in patch 3:
> 
>   ...
>   benefit of working around a bug in Clang (fixed[1] in 15+) that got
>   ...

Ah, the version is mentioned only in cover letter. So, the patch's commit
message seems good to me.