Re: [jic23-iio:testing 124/129] drivers/iio/accel/msa311.c:993:24: warning: format specifies type 'unsigned char' but the argument has type 'unsigned int'

Andy Shevchenko
2022-08-30T12:51:40Z

On Tue, Aug 30, 2022 at 3:45 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Tue, Aug 30, 2022 at 1:03 PM Jonathan Cameron
> <Jonathan.Cameron@huawei.com> wrote:
> > On Mon, 29 Aug 2022 06:25:53 +0800
> > kernel test robot <lkp@intel.com> wrote:
>
> ...
>
> > > >> drivers/iio/accel/msa311.c:993:24: warning: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Wformat]
> > > "msa311-%hhx", partid);
> > > ~~~~ ^~~~~~
> > > %x
> > > 1 warning generated.
>
> > > 992 msa311->chip_name = devm_kasprintf(dev, GFP_KERNEL,
> > > > 993 "msa311-%hhx", partid);
>
> > I'm thinking intent here was to limit range of what was printed. Maybe better to use
> > local u8 variable or cast?
> >
> > I can fix it up if that's fine with you - or even better send me a patch that fixes
> > it however you prefer!
>
> Looking back at what Linus said about those specifiers, I would rather
> go with simple %x or %02x.
>
> P.S. Surprisingly many C developers don't know the difference between
> %hhx and %02x, which is easy to check by
>
> char a = -1;
> printf("%hhx <==> %02x\n", a, a);
> a = 217;
> printf("%hhx <==> %02x\n", a, a);

And additional part

unsigned int b = 7, c = 1027;
printf("%02x(b) %02x(c)\n", b, c);

--
With Best Regards,
Andy Shevchenko