Re: [PATCH v1 1/2] vsprintf: Add %pR human-readable size

Bjorn Helgaas <[email protected]>
Newsgroups org.kernel.vger.linux-pci,org.kernel.vger.linux-kernel
Message-ID <20260808234530.GA402575@bhelgaas>
On Sat, Aug 08, 2026 at 08:43:30PM +0300, Andy Shevchenko wrote:
> On Sat, Aug 08, 2026 at 12:23:07PM -0500, Bjorn Helgaas wrote:
> > Include human-readable size when printing struct resource memory ranges
> > (not including DMA, bus number, or I/O port ranges) with the %pR format to
> > make it easier to read, e.g.,
> > 
> >   - pci 0000:00:02.0: BAR 0 [mem 0xfea80000-0xfea9ffff]
> >   + pci 0000:00:02.0: BAR 0 [mem 0xfea80000-0xfea9ffff (128 KiB)]
> 
> ...
> 
> >  lib/vsprintf.c | 18 ++++++++++++++----
> >  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> Sorry, we do not accept this without added test cases.

TIL about these tests, they look great and I'll fix this up and update
printk-formats.rst as well, thank you!

> ...
> 
> > +	if (res->flags & IORESOURCE_MEM) {
> 
> Besides we have resource_type() macro, why only this? I would expect
> IO as well as 64-bit MEM version.

We could use resource_type() here, but would have to check other bits
directly (IORESOURCE_PREFETCH, IORESOURCE_MEM_64, etc) since they're
not included.

I considered including IO and certainly could do that.  IO resources
are smaller and it's not as interesting, but maybe we should.

64-bit MEM resources are already included because they have both
IORESOURCE_MEM and IORESOURCE_MEM_64 set.

> > +		*p++ = ' ';
> > +		*p++ = '(';
> > +		string_get_size(resource_size(res), 1, STRING_UNITS_2,
> > +				size_buf, sizeof(size_buf));
> 
> > +		p = string_nocheck(p, pend, size_buf, str_spec);
> 
> Why do you need this? Use returned value from string_get_size() directly.

string_get_size() doesn't return a char * like string_nocheck() et al
do.  We could do something like "p += string_get_size(..., p, pend - p)",
but it's a little messy because the return value is the length that
*would* have been written if it was truncated, so I think we'd have to
check for "p > pend".  I'll ponder this one.

> > +		*p++ = ')';
> > +	}
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
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.