[PATCH v5 03/13] EDAC/ghes: Rationalize buffer usage in for mem other_detail helper

From: Pierre Gondois

Date: Mon Nov 30 2026 - 12:08:46 EST


scnprintf() already reserves space for the terminating NULL,
leaving one byte unused and under-flowing the capacity when len=0.
Callers also remove the last character unconditionally, which
can discard valid text after truncation.

Update print_mem_error_other_detail() to fix the above issues.

Signed-off-by: Pierre Gondois <pierre.gondois@xxxxxxx>
---
drivers/edac/ghes_edac.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index e23a80fbdb7c..c274d295221d 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -243,15 +243,14 @@ static void ghes_scan_system(void)
}

static int print_mem_error_other_detail(const struct cper_sec_mem_err *mem, char *msg,
- const char *location, unsigned int len)
+ const char *location, size_t len)
{
u32 n;

- if (!msg)
+ if (!msg || !len)
return 0;

n = 0;
- len -= 1;

n += scnprintf(msg + n, len - n, "APEI location: %s ", location);

@@ -372,8 +371,8 @@ static int ghes_edac_report_mem_error(struct notifier_block *nb,

/* All other fields are mapped on e->other_detail */
p = pvt->other_detail;
- p += print_mem_error_other_detail(mem_err, p, e->location, OTHER_DETAIL_LEN);
- if (p > pvt->other_detail)
+ p += print_mem_error_other_detail(mem_err, p, e->location, sizeof(pvt->other_detail));
+ if (p > pvt->other_detail && p[-1] == ' ')
*(p - 1) = '\0';

edac_raw_mc_handle_error(e);
--
2.43.0