[PATCH] EDAC: enlarge the DIMM label buffer to cover the worst case
From: Aibing Chen
Date: Thu Nov 26 2026 - 00:09:21 EST
The DIMM labels are assembled with snprintf() into label[EDAC_MC_LABEL_LEN
+ 1], a 32 byte array, with formats such as
"CPU_SrcID#%u_MC#%u_Chan#%u_DIMM#%u" in skx_common.c and
"CPU_SrcID#%u_Ha#%u_Chan#%u_DIMM#%u" in sb_edac.c.
The worst case gcc computes for these formats is 34 characters plus the
terminator, i.e. 35 bytes, while the array only holds 32. The labels fit
in practice, but -Wformat-truncation is enabled for W=1 builds and
COMPILE_TEST configurations turn it into an error through CONFIG_WERROR,
so these two files do not build today:
drivers/edac/skx_common.c:790:87: error: '_DIMM#' directive output may
be truncated writing 6 bytes into a region of size between 0 and 9
[-Werror=format-truncation=]
drivers/edac/skx_common.c:839:79: error: '_DIMM#' directive output may
be truncated writing 6 bytes into a region of size between 0 and 9
[-Werror=format-truncation=]
drivers/edac/sb_edac.c:1670:85: error: 'snprintf' output may be
truncated before the last format character
[-Werror=format-truncation=]
Raise EDAC_MC_LABEL_LEN to 34 so that label[] is 35 bytes and covers the
worst case: struct dimm_info and struct edac_raw_error_desc grow by three
bytes per label, 24 bytes for the eight labels of the latter, and the
stack buffers that the drivers size with this constant grow by the same
three bytes.
No functional change.
Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
---
include/linux/edac.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/edac.h b/include/linux/edac.h
index f7a8218f9..f4c0a9613 100644
--- a/include/linux/edac.h
+++ b/include/linux/edac.h
@@ -45,7 +45,7 @@ static inline void opstate_init(void)
}
/* Max length of a DIMM label*/
-#define EDAC_MC_LABEL_LEN 31
+#define EDAC_MC_LABEL_LEN 34
/* Maximum size of the location string */
#define LOCATION_SIZE 256