lkml.org 
[lkml]   [2022]   [Aug]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [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'
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);

--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2022-08-30 14:46    [W:0.359 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site