[PATCH v4 1/1] lib/vsprintf: Add support for printing V4L2 and DRM fourccs

Joe Perches joe at perches.com
Tue Nov 3 16:49:36 UTC 2020


On Tue, 2020-11-03 at 16:56 +0200, Sakari Ailus wrote:
> On Tue, Nov 03, 2020 at 04:47:47PM +0200, Andy Shevchenko wrote:
> > On Tue, Nov 03, 2020 at 03:34:00PM +0200, Sakari Ailus wrote:
> > > Add a printk modifier %p4cc (for pixel format) for printing V4L2 and DRM
> > > pixel formats denoted by fourccs. The fourcc encoding is the same for both
> > > so the same implementation can be used.
> > 
> > ...
> > 
> > > +static noinline_for_stack
> > > +char *fourcc_string(char *buf, char *end, const u32 *fourcc,
> > > +		    struct printf_spec spec, const char *fmt)
> > > +{
> > > +	char output[sizeof("(xx)(xx)(xx)(xx) little-endian (0x01234567)")];
> > 
> > I would add a comment that there is another possibility, i.e. big-endian, but
> > it occupies less space.

I think it's unnecessary as it's obvious and similarly done in other
<foo>_string type functions.

> > > +	p = special_hex_number(p, output + sizeof(output) - 2, *fourcc,
> > > +			       sizeof(u32));
> > 
> > I would go with one line here.
> 
> It's wrapped since the result would be over 80 otherwise.

Perhaps simpler as

	p = special_hex_number(p, p + 10, *fourcc, sizeof(u32));

> > The (theoretical) problem is here that the case when buffer size is not enough
> > to print a value will be like '(0xabc)' but should be rather '(0xabcd' like
> > snprintf() does in general.

Isn't the stack buffer known to be large enough?

> > > +	*p++ = ')';
> > > +	*p = '\0';
> > > +
> > > +	return string(buf, end, output, spec);

Isn't the actual output buffer used here truncating output?

If the general problem is someone using a limited length pointer
output like %10p4cc, then all the output is getting truncated no?




More information about the dri-devel mailing list