Re: [PATCH] EDAC/mce_amd: Do not print a stray newline

From: Borislav Petkov

Date: Wed Aug 12 2026 - 19:59:12 EST


On Tue, Jul 14, 2026 at 09:04:55AM -0400, Yazen Ghannam wrote:
> - pr_emerg(HW_ERR "%s Ext. Error Code: %d", smca_get_long_name(bank_type), xec);
> + memset(buf, 0, sizeof(buf));
> + p = buf;
> + end = buf + sizeof(buf);
> +
> + p += scnprintf(p, end - p, "%s Ext. Error Code: %d", smca_get_long_name(bank_type), xec);
> +
> + pr_emerg(HW_ERR "%s", buf);

Yes, I think this is the right idea, albeit with a couple of improvements:

1. We should define our own vararg log() function - static, used only in this
file, which gets a format string and params and vscnprintf()s into our
local, heap-allocated string array of 256 initially, we can grow it later
if needed

2. Function will be a fire-and-forget and should not care about ptr
advancement, buffer size, yadda yadda - log() will do that

3. When string buffer is full, log() will complain ofc.

4. When logging is done, we will have log_print() which goes over the whole
string array and splits it into, say, 100-ish chars and breaks the lines
then, during printing. We would use a space " " so that we can mark where
we can break the string

5. No locking yet - we can do that later, if really needed

This way we'll be able to handle all kinds of error record formats but still
keep them compact enough so that they can go out in a couple of printk()
calls.

The other advantage when having a buffer like that is, if you look at kdump
memory image, you can find the buffer in memory and actually dump its contents
- one more way to get to the error.

Thoughts?

Lemme know if you have cycles to do this. If not, I can take a stab at it
myself.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette