RE: [PATCH] PM / devfreq: Convert to seq_buf
Biju Das <[email protected]>
| Newsgroups | org.kernel.vger.linux-renesas-soc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pm |
|---|---|
| Message-ID | <TY3PR01MB11346F56AC074292B976E47FE86D12@TY3PR01MB11346.jpnprd01.prod.outlook.com> |
Hi Geert, Thanks for the feedback. > -----Original Message----- > From: Geert Uytterhoeven <[email protected]> > Sent: 07 August 2026 13:19 > Subject: Re: [PATCH] PM / devfreq: Convert to seq_buf > > 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. I have explored this option and got this response from AI. Here it is sysfs, not debugfs. The limitation comes from sysfs's one-page buffer contract not from the choice of seq_buf/seq_file. To actually lift the limitation, this attribute would need to move off sysfs device_attribute entirely. The problem is that trans_stat_show() is a sysfs device_attribute show() callback, not a debugfs file opened through single_open()/seq_read(). Sysfs attribute reads are fundamentally capped at PAGE_SIZE — the buf passed in is a single, fixed-size page, and there's no .read()/.open() VFS machinery driving repeated .show() calls with buffer growth. So even switching to struct seq_file, we'd have to hand-initialize it over that same fixed PAGE_SIZE buffer. I am agreeing to AI response. Please correct me, if it is not the case. Cheers, Biju