Re: [PATCH] PM / devfreq: Convert to seq_buf

Geert Uytterhoeven <[email protected]>
Newsgroups org.kernel.vger.linux-renesas-soc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pm
Message-ID <CAMuHMdVGfR58UodRRjr1=vzsxLBiNsNkiwu8A7FNi-dXVSMH+Q@mail.gmail.com>
Hi Biju,

On Fri, 7 Aug 2026 at 12:03, Biju <[email protected]> wrote:
> From: Biju Das <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Biju Das <[email protected]>

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 -- [email protected]

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.