[PATCH 25/28] EDAC/thunderx: Replace strlcat() with seq_buf

From: Bill Wendling

Date: Tue Sep 15 2026 - 04:44:56 EST


The threaded ISR handlers (thunderx_ocx_com_threaded_isr(),
thunderx_ocx_lnk_threaded_isr(), and thunderx_l2c_threaded_isr()) build
multi-line error reports by formatting register details into a scratch
buffer and appending them to "msg" with strlcat().

In preparation for removing the deprecated strlcat() API[1], refactor the
ISR handlers to construct error messages using struct seq_buf.

Additionally, fix two bugs in decode_register(): initialize "str[0] = '\0'"
so callers do not append stale buffer contents when no error bits match,
and stop iterating if snprintf() truncates the buffer to avoid
underflowing the remaining "size" counter.

Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: codemender-patching+linux@xxxxxxxxxx
Assisted-by: AI:Claude-3-5-Sonnet [editor_update_file, shell_command_run]
Signed-off-by: Bill Wendling <morbo@xxxxxxxxxx>
---
Cc: Russell King <linux@xxxxxxxxxxxxxxx>
Cc: Huacai Chen <chenhuacai@xxxxxxxxxx>
Cc: WANG Xuerui <kernel@xxxxxxxxxx>
Cc: Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>
Cc: "James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>
Cc: Helge Deller <deller@xxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: x86@xxxxxxxxxx
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Tony Luck <tony.luck@xxxxxxxxx>
Cc: Maarten Lankhorst <maarten.lankhorst@xxxxxxxxxxxxxxx>
Cc: Maxime Ripard <mripard@xxxxxxxxxx>
Cc: Thomas Zimmermann <tzimmermann@xxxxxxx>
Cc: David Airlie <airlied@xxxxxxxxx>
Cc: Simona Vetter <simona@xxxxxxxx>
Cc: Matthew Brost <matthew.brost@xxxxxxxxx>
Cc: "Thomas Hellström" <thomas.hellstrom@xxxxxxxxxxxxxxx>
Cc: Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx>
Cc: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
Cc: Matthias Schwarzott <zzam@xxxxxxxxxx>
Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>
Cc: Tony Nguyen <anthony.l.nguyen@xxxxxxxxx>
Cc: Przemek Kitszel <przemyslaw.kitszel@xxxxxxxxx>
Cc: Andrew Lunn <andrew+netdev@xxxxxxx>
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
Cc: Arend van Spriel <arend.vanspriel@xxxxxxxxxxxx>
Cc: Rob Herring <robh@xxxxxxxxxx>
Cc: Saravana Kannan <saravanak@xxxxxxxxxx>
Cc: Krzysztof Kozlowski <krzk@xxxxxxxxxx>
Cc: Sylwester Nawrocki <s.nawrocki@xxxxxxxxxxx>
Cc: Peter Griffin <peter.griffin@xxxxxxxxxx>
Cc: Alim Akhtar <alim.akhtar@xxxxxxxxxxx>
Cc: Linus Walleij <linusw@xxxxxxxxxx>
Cc: Anil Gurumurthy <anil.gurumurthy@xxxxxxxxxx>
Cc: Sudarsana Kalluru <sudarsana.kalluru@xxxxxxxxxx>
Cc: "Martin K. Petersen" <mkp@xxxxxxxxxx>
Cc: Trond Myklebust <trondmy@xxxxxxxxxx>
Cc: Anna Schumaker <anna@xxxxxxxxxx>
Cc: Mike Marshall <hubcap@xxxxxxxxxxxx>
Cc: Martin Brandenburg <martin@xxxxxxxxxxxx>
Cc: Kees Cook <kees@xxxxxxxxxx>
Cc: Jiri Pirko <jiri@xxxxxxxxxxx>
Cc: Simon Horman <horms@xxxxxxxxxx>
Cc: Chuck Lever <cel@xxxxxxxxxx>
Cc: Jeff Layton <jlayton@xxxxxxxxxx>
Cc: NeilBrown <neil@xxxxxxxxxx>
Cc: Olga Kornievskaia <okorniev@xxxxxxxxxx>
Cc: Dai Ngo <Dai.Ngo@xxxxxxxxxx>
Cc: Tom Talpey <tom@xxxxxxxxxx>
Cc: Jaroslav Kysela <perex@xxxxxxxx>
Cc: Takashi Iwai <tiwai@xxxxxxxx>
Cc: Bill Wendling <morbo@xxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: "Mike Rapoport (Microsoft)" <rppt@xxxxxxxxxx>
Cc: Kanglong Wang <wangkanglong@xxxxxxxxxxx>
Cc: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
Cc: Qiang Ma <maqianga@xxxxxxxxxxxxx>
Cc: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>
Cc: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
Cc: Ard Biesheuvel <ardb@xxxxxxxxxx>
Cc: Breno Leitao <leitao@xxxxxxxxxx>
Cc: Thorsten Blum <blum@xxxxxxxxxx>
Cc: Harshit Mogalapalli <harshit.m.mogalapalli@xxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: Lyude Paul <lyude@xxxxxxxxxx>
Cc: Ashutosh Desai <ashutoshdesai993@xxxxxxxxx>
Cc: Imre Deak <imre.deak@xxxxxxxxx>
Cc: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxxxxxxxx>
Cc: Johan Hovold <johan@xxxxxxxxxx>
Cc: Johannes Berg <johannes.berg@xxxxxxxxx>
Cc: Miri Korenblit <miriam.rachel.korenblit@xxxxxxxxx>
Cc: Alexander Stein <alexander.stein@xxxxxxxxxxxxxxx>
Cc: Cryolitia PukNgae <cryolitia@xxxxxxxxxxxxx>
Cc: Jiaming Zhang <r772577952@xxxxxxxxx>
Cc: Will Porter <mrwillporter@xxxxxxxxx>
Cc: Cen Zhang <zzzccc427@xxxxxxxxx>
Cc: "Cássio Gabriel" <cassiogabrielcontato@xxxxxxxxx>
Cc: Rong Zhang <i@xxxxxxxx>
Cc: Arun Raghavan <arunr@xxxxxxxxxxxxxxxxx>
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: loongarch@xxxxxxxxxxxxxxx
Cc: linux-mips@xxxxxxxxxxxxxxx
Cc: linux-parisc@xxxxxxxxxxxxxxx
Cc: linux-edac@xxxxxxxxxxxxxxx
Cc: dri-devel@xxxxxxxxxxxxxxxxxxxxx
Cc: intel-xe@xxxxxxxxxxxxxxxxxxxxx
Cc: linux-input@xxxxxxxxxxxxxxx
Cc: linux-media@xxxxxxxxxxxxxxx
Cc: intel-wired-lan@xxxxxxxxxxxxxxxx
Cc: netdev@xxxxxxxxxxxxxxx
Cc: linux-wireless@xxxxxxxxxxxxxxx
Cc: brcm80211@xxxxxxxxxxxxxxx
Cc: brcm80211-dev-list.pdl@xxxxxxxxxxxx
Cc: devicetree@xxxxxxxxxxxxxxx
Cc: linux-samsung-soc@xxxxxxxxxxxxxxx
Cc: linux-gpio@xxxxxxxxxxxxxxx
Cc: linux-scsi@xxxxxxxxxxxxxxx
Cc: linux-nfs@xxxxxxxxxxxxxxx
Cc: devel@xxxxxxxxxxxxxxxxxx
Cc: linux-hardening@xxxxxxxxxxxxxxx
Cc: linux-sound@xxxxxxxxxxxxxxx
---
drivers/edac/thunderx_edac.c | 64 ++++++++++++++++++++++--------------
1 file changed, 39 insertions(+), 25 deletions(-)

diff --git a/drivers/edac/thunderx_edac.c b/drivers/edac/thunderx_edac.c
index e7c335ca0c36..4e3781815b6d 100644
--- a/drivers/edac/thunderx_edac.c
+++ b/drivers/edac/thunderx_edac.c
@@ -20,6 +20,7 @@
#include <linux/atomic.h>
#include <linux/bitfield.h>
#include <linux/circ_buf.h>
+#include <linux/seq_buf.h>

#include <asm/page.h>

@@ -47,12 +48,17 @@ static void decode_register(char *str, size_t size,
{
int ret = 0;

+ if (size > 0)
+ str[0] = '\0';
+
while (descr->type && descr->mask && descr->descr) {
if (reg & descr->mask) {
ret = snprintf(str, size, "\n\t%s, %s",
descr->type == ERR_CORRECTED ?
"Corrected" : "Uncorrected",
descr->descr);
+ if (ret < 0 || ret >= size)
+ break;
str += ret;
size -= ret;
}
@@ -1115,35 +1121,37 @@ static irqreturn_t thunderx_ocx_com_threaded_isr(int irq, void *irq_id)

while (CIRC_CNT(ocx->com_ring_head, ocx->com_ring_tail,
ARRAY_SIZE(ocx->com_err_ctx))) {
+ struct seq_buf s;
+
tail = ring_pos(ocx->com_ring_tail,
ARRAY_SIZE(ocx->com_err_ctx));
ctx = &ocx->com_err_ctx[tail];

- snprintf(msg, OCX_MESSAGE_SIZE, "%s: OCX_COM_INT: %016llx",
- ocx->edac_dev->ctl_name, ctx->reg_com_int);
+ seq_buf_init(&s, msg, OCX_MESSAGE_SIZE);
+
+ seq_buf_printf(&s, "%s: OCX_COM_INT: %016llx",
+ ocx->edac_dev->ctl_name, ctx->reg_com_int);

decode_register(other, OCX_OTHER_SIZE,
ocx_com_errors, ctx->reg_com_int);

- strlcat(msg, other, OCX_MESSAGE_SIZE);
+ seq_buf_puts(&s, other);

for (lane = 0; lane < OCX_RX_LANES; lane++)
if (ctx->reg_com_int & BIT(lane)) {
- snprintf(other, OCX_OTHER_SIZE,
- "\n\tOCX_LNE_INT[%02d]: %016llx OCX_LNE_STAT11[%02d]: %016llx",
- lane, ctx->reg_lane_int[lane],
- lane, ctx->reg_lane_stat11[lane]);
-
- strlcat(msg, other, OCX_MESSAGE_SIZE);
+ seq_buf_printf(&s,
+ "\n\tOCX_LNE_INT[%02d]: %016llx OCX_LNE_STAT11[%02d]: %016llx",
+ lane, ctx->reg_lane_int[lane],
+ lane, ctx->reg_lane_stat11[lane]);

decode_register(other, OCX_OTHER_SIZE,
ocx_lane_errors,
ctx->reg_lane_int[lane]);
- strlcat(msg, other, OCX_MESSAGE_SIZE);
+ seq_buf_puts(&s, other);
}

if (ctx->reg_com_int & OCX_COM_INT_CE)
- edac_device_handle_ce(ocx->edac_dev, 0, 0, msg);
+ edac_device_handle_ce(ocx->edac_dev, 0, 0, seq_buf_str(&s));

ocx->com_ring_tail++;
}
@@ -1196,25 +1204,28 @@ static irqreturn_t thunderx_ocx_lnk_threaded_isr(int irq, void *irq_id)

while (CIRC_CNT(ocx->link_ring_head, ocx->link_ring_tail,
ARRAY_SIZE(ocx->link_err_ctx))) {
+ struct seq_buf s;
+
tail = ring_pos(ocx->link_ring_head,
ARRAY_SIZE(ocx->link_err_ctx));

ctx = &ocx->link_err_ctx[tail];

- snprintf(msg, OCX_MESSAGE_SIZE,
- "%s: OCX_COM_LINK_INT[%d]: %016llx",
- ocx->edac_dev->ctl_name,
- ctx->link, ctx->reg_com_link_int);
+ seq_buf_init(&s, msg, OCX_MESSAGE_SIZE);
+
+ seq_buf_printf(&s, "%s: OCX_COM_LINK_INT[%d]: %016llx",
+ ocx->edac_dev->ctl_name,
+ ctx->link, ctx->reg_com_link_int);

decode_register(other, OCX_OTHER_SIZE,
ocx_com_link_errors, ctx->reg_com_link_int);

- strlcat(msg, other, OCX_MESSAGE_SIZE);
+ seq_buf_puts(&s, other);

if (ctx->reg_com_link_int & OCX_COM_LINK_INT_UE)
- edac_device_handle_ue(ocx->edac_dev, 0, 0, msg);
+ edac_device_handle_ue(ocx->edac_dev, 0, 0, seq_buf_str(&s));
else if (ctx->reg_com_link_int & OCX_COM_LINK_INT_CE)
- edac_device_handle_ce(ocx->edac_dev, 0, 0, msg);
+ edac_device_handle_ce(ocx->edac_dev, 0, 0, seq_buf_str(&s));

ocx->link_ring_tail++;
}
@@ -1880,22 +1891,25 @@ static irqreturn_t thunderx_l2c_threaded_isr(int irq, void *irq_id)

while (CIRC_CNT(l2c->ring_head, l2c->ring_tail,
ARRAY_SIZE(l2c->err_ctx))) {
+ struct seq_buf s;
+
tail = ring_pos(l2c->ring_tail, ARRAY_SIZE(l2c->err_ctx));
ctx = &l2c->err_ctx[tail];

- snprintf(msg, L2C_MESSAGE_SIZE,
- "%s: %s: %016llx, %s: %016llx",
- l2c->edac_dev->ctl_name, reg_int_name, ctx->reg_int,
- ctx->reg_ext_name, ctx->reg_ext);
+ seq_buf_init(&s, msg, L2C_MESSAGE_SIZE);
+
+ seq_buf_printf(&s, "%s: %s: %016llx, %s: %016llx",
+ l2c->edac_dev->ctl_name, reg_int_name, ctx->reg_int,
+ ctx->reg_ext_name, ctx->reg_ext);

decode_register(other, L2C_OTHER_SIZE, l2_errors, ctx->reg_int);

- strlcat(msg, other, L2C_MESSAGE_SIZE);
+ seq_buf_puts(&s, other);

if (ctx->reg_int & mask_ue)
- edac_device_handle_ue(l2c->edac_dev, 0, 0, msg);
+ edac_device_handle_ue(l2c->edac_dev, 0, 0, seq_buf_str(&s));
else if (ctx->reg_int & mask_ce)
- edac_device_handle_ce(l2c->edac_dev, 0, 0, msg);
+ edac_device_handle_ce(l2c->edac_dev, 0, 0, seq_buf_str(&s));

l2c->ring_tail++;
}
--
2.55.0.1032.g73a4cd73de-goog