public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] regulator: hi6421v530: fix building with GCC 15
@ 2025-04-15 11:14 Brahmajit Das
  2025-04-16 10:41 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Brahmajit Das @ 2025-04-15 11:14 UTC (permalink / raw)
  Cc: Borislav Petkov (AMD), Dave Hansen, Pawan Gupta, Tony Luck,
	linux-kernel

Since the Linux kernel initializes many non-C-string char arrays with
literals. While it would be possible to convert initializers from:
   { "BOOP", ... }
to something like:
   { { 'B', 'O', 'O', 'P' }, ... }
that is annoying.
Making -Wunterminated-string-initialization stay silent about char
arrays marked with nonstring would be much better.

Without the __attribute__((nonstring)) we would get the following build
error:
drivers/regulator/hi6421v530-regulator.c:189:19: error: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (21 chars into 20 available) [-Werror=unterminated-string-initialization]
  189 |         { .name = "hi6421v530-regulator" },
      |                   ^~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Upstream GCC has added this commit
622968990beee7499e951590258363545b4a3b57[0][1] which silences warning
about truncating NUL char when initializing nonstring arrays.

[0]: https://gcc.gnu.org/cgit/gcc/commit/?id=622968990beee7499e951590258363545b4a3b57
[1]: https://gcc.gnu.org/cgit/gcc/commit/?id=afb46540d3921e96c4cd7ba8fa2c8b0901759455

Thanks to Jakub Jelinek <jakub@gcc.gnu.org> for the gcc patch.

Signed-off-by: Brahmajit Das <listout@listout.xyz>
---
 include/linux/mod_devicetable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index bd7e60c0b72f..f9bb623d0949 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -605,7 +605,7 @@ struct dmi_system_id {
 #define PLATFORM_MODULE_PREFIX	"platform:"
 
 struct platform_device_id {
-	char name[PLATFORM_NAME_SIZE];
+	char name[PLATFORM_NAME_SIZE] __attribute__((nonstring));
 	kernel_ulong_t driver_data;
 };
 
-- 
2.49.0


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

end of thread, other threads:[~2025-05-07  9:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 11:14 [PATCH 1/1] regulator: hi6421v530: fix building with GCC 15 Brahmajit Das
2025-04-16 10:41 ` kernel test robot
2025-04-16 11:23 ` kernel test robot
2025-04-16 12:13 ` [PATCH v2 " Brahmajit Das
2025-05-07  9:29   ` kernel test robot

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