[PATCH v6 1/3] lib/vsprintf: Add support for printing V4L2 and DRM fourccs
Andy Shevchenko
andriy.shevchenko at linux.intel.com
Mon Feb 8 20:58:55 UTC 2021
On Mon, Feb 08, 2021 at 10:43:30PM +0200, Andy Shevchenko wrote:
> On Mon, Feb 8, 2021 at 10:11 PM Sakari Ailus
> <sakari.ailus at linux.intel.com> wrote:
...
> > +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)")];
>
> Do we have any evidence / document / standard that the above format is
> what people would find good? From existing practices (I consider other
> printings elsewhere and users in this series) I find '(xx)' form for
> hex numbers is weird. The standard practice is to use \xHH (without
> parentheses).
> > + val = *fourcc & ~BIT(31);
> > +
> > + for (i = 0; i < sizeof(*fourcc); i++) {
> > + unsigned char c = val >> (i * 8);
>
> ...
>
> > + /* Weed out spaces */
> > + if (c == ' ')
> > + continue;
>
> None of the existing users does that. Why?
>
> > + /* Print non-control ASCII characters as-is */
> > + if (isascii(c) && isprint(c)) {
> > + *p++ = c;
> > + continue;
> > + }
> > +
> > + *p++ = '(';
> > + p = hex_byte_pack(p, c);
> > + *p++ = ')';
> > + }
To be on constructive side, I would propose to replace above with something
like:
__le32 val;
val = cpu_to_le32(*fourcc & ~BIT(31));
p += string_escape_mem(&val, sizeof(*fourcc), output, sizeof(output), ESCAPE_NP | ESCAPE_HEX, NULL);
--
With Best Regards,
Andy Shevchenko
More information about the dri-devel
mailing list