[PATCH 1/1] regulator: hi6421v530: fix building with GCC 15
From: Brahmajit Das
Date: Tue Apr 15 2025 - 07:15:07 EST
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@xxxxxxxxxxx> for the gcc patch.
Signed-off-by: Brahmajit Das <listout@xxxxxxxxxxx>
---
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