Re: [PATCH] PM / devfreq: Convert to seq_buf
From: Geert Uytterhoeven
Date: Fri Aug 07 2026 - 08:20:18 EST
Hi Biju,
On Fri, 7 Aug 2026 at 12:03, Biju <biju.das.au@xxxxxxxxx> wrote:
> From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
>
> The devfreq transition table sysfs attribute (trans_stat_show()) builds
> its output using manual sysfs_emit_at() calls with hand-rolled length
> tracking and PAGE_SIZE bounds checks scattered throughout the loops.
>
> On SoCs with large frequency tables, such as Renesas RZ/G3L, the
> resulting table can exceed PAGE_SIZE. In that case the function bails
> out entirely and returns -EFBIG, logging:
>
> devfreq transition table exceeds PAGE_SIZE. Disabling
>
> which makes the attribute completely unusable on affected platforms.
>
> Convert trans_stat_show() to use struct seq_buf instead. seq_buf_printf()
> tracks the buffer position and handles overflow internally, removing the
> need for manual length checks before every write. If the table still
> overflows PAGE_SIZE, truncate the output to PAGE_SIZE - 1, NUL-terminate
> it, and log a rate-limited warning rather than failing the read outright,
> so the attribute still returns a usable (if truncated) table instead of
> nothing.
>
> Suggested-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
> Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
Thanks for your patch!
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -1661,9 +1662,10 @@ static ssize_t trans_stat_show(struct device *dev,
> + /*
> + * If an overflow occurs, seq_buf_used() can return a value greater
> + * than PAGE_SIZE. Clamp the return length to PAGE_SIZE - 1 and
> + * ensure a null-terminator is written to prevent the sysfs
> + * "bad count" or out-of-bounds warning.
> + */
> + if (seq_buf_has_overflowed(&s)) {
> + pr_warn_ratelimited("devfreq transition table truncated due to PAGE_SIZE limit\n");
> + len = PAGE_SIZE - 1;
> + buf[len] = '\0';
So shouldn't you use seq_file instead of seq_buf, to lift this limitation?
devfreq_summary_show() already uses that.
> }
>
> return len;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds