Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings
@ 2025-03-10 22:23 Kees Cook
  2025-03-14 10:31 ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2025-03-10 22:23 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Kees Cook, Jonathan Cameron, Lars-Peter Clausen, linux-iio,
	linux-kernel, linux-hardening

When a character array without a terminating NUL character has a static
initializer, GCC 15's -Wunterminated-string-initialization will only
warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
with __nonstring to and correctly identify the char array as "not a C
string" and thereby eliminate the warning.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
---
 drivers/iio/magnetometer/ak8974.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c
index 08975c60e325..44d8428a69b0 100644
--- a/drivers/iio/magnetometer/ak8974.c
+++ b/drivers/iio/magnetometer/ak8974.c
@@ -535,8 +535,8 @@ static int ak8974_detect(struct ak8974 *ak8974)
 				       fab_data2, sizeof(fab_data2));
 
 		for (i = 0; i < 3; ++i) {
-			static const char axis[3] = "XYZ";
-			static const char pgaxis[6] = "ZYZXYX";
+			static const char axis[3] __nonstring = "XYZ";
+			static const char pgaxis[6] __nonstring = "ZYZXYX";
 			unsigned offz = le16_to_cpu(fab_data2[i]) & 0x7F;
 			unsigned fine = le16_to_cpu(fab_data1[i]);
 			unsigned sens = le16_to_cpu(fab_data1[i + 3]);
-- 
2.34.1


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

* Re: [PATCH] iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings
  2025-03-10 22:23 [PATCH] iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings Kees Cook
@ 2025-03-14 10:31 ` Linus Walleij
  2025-03-15 18:31   ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2025-03-14 10:31 UTC (permalink / raw)
  To: Kees Cook
  Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio, linux-kernel,
	linux-hardening

On Mon, Mar 10, 2025 at 11:23 PM Kees Cook <kees@kernel.org> wrote:

> When a character array without a terminating NUL character has a static
> initializer, GCC 15's -Wunterminated-string-initialization will only
> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> with __nonstring to and correctly identify the char array as "not a C
> string" and thereby eliminate the warning.
>
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: linux-iio@vger.kernel.org
> Signed-off-by: Kees Cook <kees@kernel.org>

Fair enough,
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH] iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings
  2025-03-14 10:31 ` Linus Walleij
@ 2025-03-15 18:31   ` Jonathan Cameron
  2025-03-15 21:56     ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2025-03-15 18:31 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Kees Cook, Lars-Peter Clausen, linux-iio, linux-kernel,
	linux-hardening

On Fri, 14 Mar 2025 11:31:09 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Mon, Mar 10, 2025 at 11:23 PM Kees Cook <kees@kernel.org> wrote:
> 
> > When a character array without a terminating NUL character has a static
> > initializer, GCC 15's -Wunterminated-string-initialization will only
> > warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> > with __nonstring to and correctly identify the char array as "not a C
> > string" and thereby eliminate the warning.
> >
> > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> > Cc: Linus Walleij <linus.walleij@linaro.org>
> > Cc: Jonathan Cameron <jic23@kernel.org>
> > Cc: Lars-Peter Clausen <lars@metafoo.de>
> > Cc: linux-iio@vger.kernel.org
> > Signed-off-by: Kees Cook <kees@kernel.org>  
> 
> Fair enough,
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
Kees,

I've currently queued this for next cycle as it doesn't feel like a fix
as such and I've already sent my pull request for the merge window.

Is it worth rushing it in, or is a fully cycle delay an issue? (6.16)

If slow is fine, applied to the testing branch of iio.git which gets
0-day bot exposure.

Jonathan

> Yours,
> Linus Walleij


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

* Re: [PATCH] iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings
  2025-03-15 18:31   ` Jonathan Cameron
@ 2025-03-15 21:56     ` Kees Cook
  2025-04-22 18:11       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2025-03-15 21:56 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Linus Walleij, Lars-Peter Clausen, linux-iio, linux-kernel,
	linux-hardening

On Sat, Mar 15, 2025 at 06:31:25PM +0000, Jonathan Cameron wrote:
> On Fri, 14 Mar 2025 11:31:09 +0100
> Linus Walleij <linus.walleij@linaro.org> wrote:
> 
> > On Mon, Mar 10, 2025 at 11:23 PM Kees Cook <kees@kernel.org> wrote:
> > 
> > > When a character array without a terminating NUL character has a static
> > > initializer, GCC 15's -Wunterminated-string-initialization will only
> > > warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> > > with __nonstring to and correctly identify the char array as "not a C
> > > string" and thereby eliminate the warning.
> > >
> > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> > > Cc: Linus Walleij <linus.walleij@linaro.org>
> > > Cc: Jonathan Cameron <jic23@kernel.org>
> > > Cc: Lars-Peter Clausen <lars@metafoo.de>
> > > Cc: linux-iio@vger.kernel.org
> > > Signed-off-by: Kees Cook <kees@kernel.org>  
> > 
> > Fair enough,
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> > 
> Kees,
> 
> I've currently queued this for next cycle as it doesn't feel like a fix
> as such and I've already sent my pull request for the merge window.
> 
> Is it worth rushing it in, or is a fully cycle delay an issue? (6.16)
> 
> If slow is fine, applied to the testing branch of iio.git which gets
> 0-day bot exposure.

No rush needed at all. This is just for cleaning up warnings for the
coming releases of GCC 15 in couple months. Thanks for picking it up!

-- 
Kees Cook

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

* Re: [PATCH] iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings
  2025-03-15 21:56     ` Kees Cook
@ 2025-04-22 18:11       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2025-04-22 18:11 UTC (permalink / raw)
  To: Kees Cook
  Cc: Linus Walleij, Lars-Peter Clausen, linux-iio, linux-kernel,
	linux-hardening

On Sat, 15 Mar 2025 14:56:02 -0700
Kees Cook <kees@kernel.org> wrote:

> On Sat, Mar 15, 2025 at 06:31:25PM +0000, Jonathan Cameron wrote:
> > On Fri, 14 Mar 2025 11:31:09 +0100
> > Linus Walleij <linus.walleij@linaro.org> wrote:
> >   
> > > On Mon, Mar 10, 2025 at 11:23 PM Kees Cook <kees@kernel.org> wrote:
> > >   
> > > > When a character array without a terminating NUL character has a static
> > > > initializer, GCC 15's -Wunterminated-string-initialization will only
> > > > warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> > > > with __nonstring to and correctly identify the char array as "not a C
> > > > string" and thereby eliminate the warning.
> > > >
> > > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> > > > Cc: Linus Walleij <linus.walleij@linaro.org>
> > > > Cc: Jonathan Cameron <jic23@kernel.org>
> > > > Cc: Lars-Peter Clausen <lars@metafoo.de>
> > > > Cc: linux-iio@vger.kernel.org
> > > > Signed-off-by: Kees Cook <kees@kernel.org>    
> > > 
> > > Fair enough,
> > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> > >   
> > Kees,
> > 
> > I've currently queued this for next cycle as it doesn't feel like a fix
> > as such and I've already sent my pull request for the merge window.
> > 
> > Is it worth rushing it in, or is a fully cycle delay an issue? (6.16)
> > 
> > If slow is fine, applied to the testing branch of iio.git which gets
> > 0-day bot exposure.  
> 
> No rush needed at all. This is just for cleaning up warnings for the
> coming releases of GCC 15 in couple months. Thanks for picking it up!
> 

Dropped because it clashes with:

  05e8d261a34e ("gcc-15: add '__nonstring' markers to byte arrays")

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

end of thread, other threads:[~2025-04-22 18:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 22:23 [PATCH] iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings Kees Cook
2025-03-14 10:31 ` Linus Walleij
2025-03-15 18:31   ` Jonathan Cameron
2025-03-15 21:56     ` Kees Cook
2025-04-22 18:11       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox