drivers/iio/magnetometer/ak8974.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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
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
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
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
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")
© 2016 - 2026 Red Hat, Inc.