linux-gbmc(stable): Annotate stmmac stat_string with __nonstring
When building linux-gbmc-stable (6.14.1) with CONFIG_WERROR enabled,
GCC 15 produces the following compiler error:
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:117:53: error:
initializer-string for array of 'char' truncates NUL terminator but
destination lacks 'nonstring' attribute (33 chars into 32 available)
[-Werror=unterminated-string-initialization]
117 | STMMAC_STAT(ptp_rx_msg_type_pdelay_follow_up),
| ^
In struct stmmac_stats, stat_string is a fixed-size character array of
ETH_GSTRING_LEN (32) bytes. The statistic identifier
ptp_rx_msg_type_pdelay_follow_up stringifies to exactly 32 characters.
Initializing stat_string with this 32-character string literal leaves
no space for a terminating NUL byte, causing GCC 15 to flag it with
-Wunterminated-string-initialization.
Add a kernel patch that annotates stat_string with the __nonstring
attribute in struct stmmac_stats to declare that the character array
is not required to be NUL-terminated. Add this patch to SRC_URI in
linux-gbmc_stable.bb to resolve the build failure.
Fixes: 80892bc818ea ("linux-gbmc(stable): 6.13 -> 6.14")
Tested: Built
Fusion-Link: fusion2 N/A
Google-Bug-Id: 558753346
Change-Id: Ib0d912cc945393c444ba354ef328fb1c380d9107
Signed-off-by: Bart Van Assche <bvanassche@google.com>
diff --git a/recipes-kernel/linux/files/0001-net-stmmac-Annotate-stat_string-with-__nonstring.patch b/recipes-kernel/linux/files/0001-net-stmmac-Annotate-stat_string-with-__nonstring.patch
new file mode 100644
index 0000000..1f60445
--- /dev/null
+++ b/recipes-kernel/linux/files/0001-net-stmmac-Annotate-stat_string-with-__nonstring.patch
@@ -0,0 +1,41 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Bart Van Assche <bvanassche@google.com>
+Date: Thu, 10 Sep 2026 14:40:00 -0700
+Subject: [PATCH] net: stmmac: Annotate stat_string with __nonstring
+
+In struct stmmac_stats, stat_string is an array of ETH_GSTRING_LEN (32)
+chars used for ethtool statistics names.
+
+The statistic name "ptp_rx_msg_type_pdelay_follow_up" is exactly 32
+characters long. When initialized into stat_string with STMMAC_STAT(),
+the string literal truncates the terminating NUL byte.
+
+With GCC 15 and -Wunterminated-string-initialization (enabled by
+CONFIG_WERROR), this results in a build error:
+error: initializer-string for array of 'char' truncates NUL terminator
+but destination lacks 'nonstring' attribute (33 chars into 32 available)
+[-Werror=unterminated-string-initialization]
+
+Annotate stat_string with __nonstring to declare that the character
+array is not required to be NUL-terminated, resolving the compiler error.
+
+Upstream-Status: Pending
+Signed-off-by: Bart Van Assche <bvanassche@google.com>
+---
+ drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+index 1ade4f6857af..b57da48b6bb4 100644
+--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+@@ -37,7 +37,7 @@
+ #define ETHTOOL_DMA_OFFSET 55
+
+ struct stmmac_stats {
+- char stat_string[ETH_GSTRING_LEN];
++ char stat_string[ETH_GSTRING_LEN] __nonstring;
+ int sizeof_stat;
+ int stat_offset;
+ };
+--
diff --git a/recipes-kernel/linux/linux-gbmc_stable.bb b/recipes-kernel/linux/linux-gbmc_stable.bb
index d29e7e6..fa0595e 100644
--- a/recipes-kernel/linux/linux-gbmc_stable.bb
+++ b/recipes-kernel/linux/linux-gbmc_stable.bb
@@ -20,6 +20,7 @@
file://0001-ARM-dts-nuvoton-Add-MMC-Nodes.patch \
file://0001-i2c-npcm-Add-clock-toggle-recovery.patch \
file://DOWNSTREAM_0001-i2c-npcm-speed-set.patch \
+ file://0001-net-stmmac-Annotate-stat_string-with-__nonstring.patch \
"
# Newer kernels don't have HGPIO in pinctrl names