linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: si1133: fix format string warnings
@ 2021-05-14 13:59 Arnd Bergmann
  2021-05-14 17:45 ` Nathan Chancellor
  0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2021-05-14 13:59 UTC (permalink / raw)
  To: Jonathan Cameron, Nathan Chancellor, Nick Desaulniers,
	Maxime Roussin-Bélanger, Jean-Francois Dagenais
  Cc: Arnd Bergmann, Lars-Peter Clausen, Alexandru Ardelean, linux-iio,
	linux-kernel, clang-built-linux

From: Arnd Bergmann <arnd@arndb.de>

clang complains about multiple instances of printing an integer
using the %hhx format string:

drivers/iio/light/si1133.c:982:4: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
                 part_id, rev_id, mfr_id);
                 ^~~~~~~

Print them as a normal integer instead, leaving the "#02"
length modifier.

Fixes: e01e7eaf37d8 ("iio: light: introduce si1133")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/iio/light/si1133.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index c280b4195003..fd302480262b 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev *iio_dev)
 		return err;
 
 	dev_info(&iio_dev->dev,
-		 "Device ID part %#02hhx rev %#02hhx mfr %#02hhx\n",
+		 "Device ID part %#02x rev %#02x mfr %#02x\n",
 		 part_id, rev_id, mfr_id);
 	if (part_id != SI1133_PART_ID) {
 		dev_err(&iio_dev->dev,
-			"Part ID mismatch got %#02hhx, expected %#02x\n",
+			"Part ID mismatch got %#02x, expected %#02x\n",
 			part_id, SI1133_PART_ID);
 		return -ENODEV;
 	}
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: si1133: fix format string warnings
  2021-05-14 13:59 [PATCH] iio: si1133: fix format string warnings Arnd Bergmann
@ 2021-05-14 17:45 ` Nathan Chancellor
  2021-05-16  9:36   ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2021-05-14 17:45 UTC (permalink / raw)
  To: Arnd Bergmann, Jonathan Cameron, Nick Desaulniers,
	Maxime Roussin-Bélanger, Jean-Francois Dagenais
  Cc: Arnd Bergmann, Lars-Peter Clausen, Alexandru Ardelean, linux-iio,
	linux-kernel, clang-built-linux

On 5/14/2021 6:59 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang complains about multiple instances of printing an integer
> using the %hhx format string:
> 
> drivers/iio/light/si1133.c:982:4: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
>                   part_id, rev_id, mfr_id);
>                   ^~~~~~~
> 
> Print them as a normal integer instead, leaving the "#02"
> length modifier.
> 
> Fixes: e01e7eaf37d8 ("iio: light: introduce si1133")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Indeed, use of %hx and %hhx have been discouraged since commit 
cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of unnecessary 
%h[xudi] and %hh[xudi]").

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>   drivers/iio/light/si1133.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
> index c280b4195003..fd302480262b 100644
> --- a/drivers/iio/light/si1133.c
> +++ b/drivers/iio/light/si1133.c
> @@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev *iio_dev)
>   		return err;
>   
>   	dev_info(&iio_dev->dev,
> -		 "Device ID part %#02hhx rev %#02hhx mfr %#02hhx\n",
> +		 "Device ID part %#02x rev %#02x mfr %#02x\n",
>   		 part_id, rev_id, mfr_id);
>   	if (part_id != SI1133_PART_ID) {
>   		dev_err(&iio_dev->dev,
> -			"Part ID mismatch got %#02hhx, expected %#02x\n",
> +			"Part ID mismatch got %#02x, expected %#02x\n",
>   			part_id, SI1133_PART_ID);
>   		return -ENODEV;
>   	}
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: si1133: fix format string warnings
  2021-05-14 17:45 ` Nathan Chancellor
@ 2021-05-16  9:36   ` Jonathan Cameron
  2021-05-27 16:17     ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2021-05-16  9:36 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Arnd Bergmann, Nick Desaulniers, Maxime Roussin-Bélanger,
	Jean-Francois Dagenais, Arnd Bergmann, Lars-Peter Clausen,
	Alexandru Ardelean, linux-iio, linux-kernel, clang-built-linux

On Fri, 14 May 2021 10:45:02 -0700
Nathan Chancellor <nathan@kernel.org> wrote:

> On 5/14/2021 6:59 AM, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> > 
> > clang complains about multiple instances of printing an integer
> > using the %hhx format string:
> > 
> > drivers/iio/light/si1133.c:982:4: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
> >                   part_id, rev_id, mfr_id);
> >                   ^~~~~~~
> > 
> > Print them as a normal integer instead, leaving the "#02"
> > length modifier.
> > 
> > Fixes: e01e7eaf37d8 ("iio: light: introduce si1133")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>  
> 
> Indeed, use of %hx and %hhx have been discouraged since commit 
> cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of unnecessary 
> %h[xudi] and %hh[xudi]").
> 
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to poke at it.

Thanks,

Jonathan
> 
> > ---
> >   drivers/iio/light/si1133.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
> > index c280b4195003..fd302480262b 100644
> > --- a/drivers/iio/light/si1133.c
> > +++ b/drivers/iio/light/si1133.c
> > @@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev *iio_dev)
> >   		return err;
> >   
> >   	dev_info(&iio_dev->dev,
> > -		 "Device ID part %#02hhx rev %#02hhx mfr %#02hhx\n",
> > +		 "Device ID part %#02x rev %#02x mfr %#02x\n",
> >   		 part_id, rev_id, mfr_id);
> >   	if (part_id != SI1133_PART_ID) {
> >   		dev_err(&iio_dev->dev,
> > -			"Part ID mismatch got %#02hhx, expected %#02x\n",
> > +			"Part ID mismatch got %#02x, expected %#02x\n",
> >   			part_id, SI1133_PART_ID);
> >   		return -ENODEV;
> >   	}
> >   
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: si1133: fix format string warnings
  2021-05-16  9:36   ` Jonathan Cameron
@ 2021-05-27 16:17     ` Joe Perches
       [not found]       ` <CAHp75Vc72vMbj311P3xnxh6ExxzD1=enoETj6wY8dHn+xBJ4+w@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2021-05-27 16:17 UTC (permalink / raw)
  To: Jonathan Cameron, Nathan Chancellor
  Cc: Arnd Bergmann, Nick Desaulniers, Maxime Roussin-Bélanger,
	Jean-Francois Dagenais, Arnd Bergmann, Lars-Peter Clausen,
	Alexandru Ardelean, linux-iio, linux-kernel, clang-built-linux

On Sun, 2021-05-16 at 10:36 +0100, Jonathan Cameron wrote:
> On Fri, 14 May 2021 10:45:02 -0700
> Nathan Chancellor <nathan@kernel.org> wrote:
> > On 5/14/2021 6:59 AM, Arnd Bergmann wrote:
> > > From: Arnd Bergmann <arnd@arndb.de>
> > > 
> > > clang complains about multiple instances of printing an integer
> > > using the %hhx format string:
> > > 
> > > drivers/iio/light/si1133.c:982:4: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
> > >                   part_id, rev_id, mfr_id);
> > >                   ^~~~~~~
> > > 
> > > Print them as a normal integer instead, leaving the "#02"
> > > length modifier.
[]
> > > diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
[]
> > > @@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev *iio_dev)
> > >   		return err;
> > >   
> > > 
> > >   	dev_info(&iio_dev->dev,
> > > -		 "Device ID part %#02hhx rev %#02hhx mfr %#02hhx\n",
> > > +		 "Device ID part %#02x rev %#02x mfr %#02x\n",
> > >   		 part_id, rev_id, mfr_id);
> > >   	if (part_id != SI1133_PART_ID) {
> > >   		dev_err(&iio_dev->dev,
> > > -			"Part ID mismatch got %#02hhx, expected %#02x\n",
> > > +			"Part ID mismatch got %#02x, expected %#02x\n",

which is almost certainly wrong.
the length specification includes the # which is already 2 bytes.

Likely these should be 0x%02x

> > >   			part_id, SI1133_PART_ID);



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: si1133: fix format string warnings
       [not found]       ` <CAHp75Vc72vMbj311P3xnxh6ExxzD1=enoETj6wY8dHn+xBJ4+w@mail.gmail.com>
@ 2021-05-28 21:10         ` Joe Perches
       [not found]           ` <CAHp75VeQdFoJrPhXU2fYdrhLUwvM4NEoPn=Z4WBPkhOa4xK+ig@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2021-05-28 21:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Nathan Chancellor, Arnd Bergmann,
	Nick Desaulniers, Maxime Roussin-Bélanger,
	Jean-Francois Dagenais, Arnd Bergmann, Lars-Peter Clausen,
	Alexandru Ardelean, linux-iio, linux-kernel, clang-built-linux

On Fri, 2021-05-28 at 23:59 +0300, Andy Shevchenko wrote:
> On Thursday, May 27, 2021, Joe Perches <joe@perches.com> wrote:
> > On Sun, 2021-05-16 at 10:36 +0100, Jonathan Cameron wrote:
> > > On Fri, 14 May 2021 10:45:02 -0700
> > > Nathan Chancellor <nathan@kernel.org> wrote:
> > > > On 5/14/2021 6:59 AM, Arnd Bergmann wrote:
> > > > > From: Arnd Bergmann <arnd@arndb.de>
> > > > > 
> > > > > clang complains about multiple instances of printing an integer
> > > > > using the %hhx format string:
> > > > > 
> > > > > drivers/iio/light/si1133.c:982:4: error: format specifies type
> > 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
> > > > >                   part_id, rev_id, mfr_id);
> > > > >                   ^~~~~~~
> > > > > 
> > > > > Print them as a normal integer instead, leaving the "#02"
> > > > > length modifier.
> > []
> > > > > diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
> > []
> > > > > @@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev
> > *iio_dev)
> > > > >                   return err;
> > > > > 
> > > > > 
> > > > >           dev_info(&iio_dev->dev,
> > > > > -          "Device ID part %#02hhx rev %#02hhx mfr %#02hhx\n",
> > > > > +          "Device ID part %#02x rev %#02x mfr %#02x\n",
> > > > >                    part_id, rev_id, mfr_id);
> > > > >           if (part_id != SI1133_PART_ID) {
> > > > >                   dev_err(&iio_dev->dev,
> > > > > -                 "Part ID mismatch got %#02hhx, expected %#02x\n",
> > > > > +                 "Part ID mismatch got %#02x, expected %#02x\n",
> > 
> > which is almost certainly wrong.
> > the length specification includes the # which is already 2 bytes.
> > 
> > Likely these should be 0x%02x
> 
> What’s the difference (except printing 0)?

(assuming the argument is unsigned char/u8)

%#02x will always emit more than the specified length (3 or 4 chars)
values < 16 are 0x<hexdigit>, values >= 16 are 0x<hexdigit><hexdigit>

0x%02x will always emit 4 chars

It's very likely the writer didn't know the difference and assumed
that the # did not count in the specified width.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: si1133: fix format string warnings
       [not found]           ` <CAHp75VeQdFoJrPhXU2fYdrhLUwvM4NEoPn=Z4WBPkhOa4xK+ig@mail.gmail.com>
@ 2021-05-28 21:35             ` Joe Perches
  2021-05-29  7:52               ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2021-05-28 21:35 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Nathan Chancellor, Arnd Bergmann,
	Nick Desaulniers, Maxime Roussin-Bélanger,
	Jean-Francois Dagenais, Arnd Bergmann, Lars-Peter Clausen,
	Alexandru Ardelean, linux-iio, linux-kernel, clang-built-linux

On Sat, 2021-05-29 at 00:16 +0300, Andy Shevchenko wrote:
> On Saturday, May 29, 2021, Joe Perches <joe@perches.com> wrote:
[]
> > > > Likely these should be 0x%02x
> > > 
> > > What’s the difference (except printing 0)?
> > 
> > (assuming the argument is unsigned char/u8)
> > 
> > %#02x will always emit more than the specified length (3 or 4 chars)
> > values < 16 are 0x<hexdigit>, values >= 16 are 0x<hexdigit><hexdigit>
> 
> 0 will be 0, btw.

Hey Andy.  Right.

> > 0x%02x will always emit 4 chars
> 
> *Minimum* or at least 4 characters. There is an upper limit of sizeof(int)
> * 2 + 2.

I did write assuming the argument is unsigned char/u8.
For the general unsigned int arg case, you are of course correct.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: si1133: fix format string warnings
  2021-05-28 21:35             ` Joe Perches
@ 2021-05-29  7:52               ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2021-05-29  7:52 UTC (permalink / raw)
  To: Joe Perches
  Cc: Jonathan Cameron, Nathan Chancellor, Arnd Bergmann,
	Nick Desaulniers, Maxime Roussin-Bélanger,
	Jean-Francois Dagenais, Arnd Bergmann, Lars-Peter Clausen,
	Alexandru Ardelean, linux-iio, linux-kernel, clang-built-linux

On Sat, May 29, 2021 at 12:35 AM Joe Perches <joe@perches.com> wrote:
> On Sat, 2021-05-29 at 00:16 +0300, Andy Shevchenko wrote:
> > On Saturday, May 29, 2021, Joe Perches <joe@perches.com> wrote:

...

> > > > > Likely these should be 0x%02x
> > > >
> > > > What’s the difference (except printing 0)?
> > >
> > > (assuming the argument is unsigned char/u8)
> > >
> > > %#02x will always emit more than the specified length (3 or 4 chars)
> > > values < 16 are 0x<hexdigit>, values >= 16 are 0x<hexdigit><hexdigit>
> >
> > 0 will be 0, btw.
>
> Hey Andy.  Right.
>
> > > 0x%02x will always emit 4 chars
> >
> > *Minimum* or at least 4 characters. There is an upper limit of sizeof(int)
> > * 2 + 2.
>
> I did write assuming the argument is unsigned char/u8.
> For the general unsigned int arg case, you are of course correct.

Signed char also.  Basically for all signed types and unsigned int cases.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-29  7:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 13:59 [PATCH] iio: si1133: fix format string warnings Arnd Bergmann
2021-05-14 17:45 ` Nathan Chancellor
2021-05-16  9:36   ` Jonathan Cameron
2021-05-27 16:17     ` Joe Perches
     [not found]       ` <CAHp75Vc72vMbj311P3xnxh6ExxzD1=enoETj6wY8dHn+xBJ4+w@mail.gmail.com>
2021-05-28 21:10         ` Joe Perches
     [not found]           ` <CAHp75VeQdFoJrPhXU2fYdrhLUwvM4NEoPn=Z4WBPkhOa4xK+ig@mail.gmail.com>
2021-05-28 21:35             ` Joe Perches
2021-05-29  7:52               ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).