Re: [PATCH] EDAC: enlarge the DIMM label buffer to cover the worst case
From: Borislav Petkov
Date: Wed Dec 02 2026 - 16:14:47 EST
On Thu, Nov 26, 2026 at 01:09:04PM +0800, Aibing Chen wrote:
> 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.
So you're basically saying that we should "fix" the code in order to
accomodate gcc's wrong estimate? I.e., wag the dog?
And a W= build should be -Werror?
That second one sounds particularly nuts. A W= build is there to issue
those additional, false positive warnings and -Werror should be explicitly off there.
IMNSVHO.