[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VfA=w+Q2ccdTiQXeWRw0wSjbkUf6J3+tp-kE50mxdkTNg@mail.gmail.com>
Date: Tue, 30 Aug 2022 15:45:12 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Jonathan Cameron <Jonathan.Cameron@...wei.com>
Cc: kernel test robot <lkp@...el.com>,
Dmitry Rokosov <DDRokosov@...rdevices.ru>,
llvm@...ts.linux.dev, kbuild-all@...ts.01.org,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: 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'
On Tue, Aug 30, 2022 at 1:03 PM Jonathan Cameron
<Jonathan.Cameron@...wei.com> wrote:
> On Mon, 29 Aug 2022 06:25:53 +0800
> kernel test robot <lkp@...el.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
Powered by blists - more mailing lists