Re: [PATCH linux-next] genirq: use sysfs_emit() instead of scnprintf().

From: Jiri Slaby
Date: Mon Mar 17 2025 - 02:17:16 EST


On 17. 03. 25, 7:12, Jiri Slaby wrote:
--- a/kernel/irq/irqdesc.c

+++ b/kernel/irq/irqdesc.c

@@ -257,11 +257,11 @@ static ssize_t per_cpu_count_show(struct kobject *kobj,

for_each_possible_cpu(cpu) {

unsigned int c = irq_desc_kstat_cpu(desc, cpu);

-ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s%u", p, c);

+ret += sysfs_emit(buf + ret, "%s%u", p, c);

Well, so the PAGE_SIZE boundary is never checked for this stacking write now, right?

^^^ not really clear what I mean, so:

If you advance buf by ret every time, sysfs_emit() still would only check if buf is not written more than "PAGE_SIZE" bytes. But the original code performs this proper "PAGE_SIZE - ret" check.

Apparently, sysfs_emit_at() is your friend here.

thanks,
--
js
suse labs