Skip to contentSkip to conversation

iio: si1133: fix format string warnings

PATCH In review Arnd Bergmann 5 participants 7 messages May 14, 2021 – May 29, 2021 2 messages not in the archive IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: si1133: fix format string warnings

From: Arnd Bergmann <[email protected]>

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")
---
 drivers/iio/light/si1133.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/light/si1133.c +2 -2
index c280b4195003..fd302480262b 100644
@@ -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;
 	}
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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]

Quoted 8 lines
                  part_id, rev_id, mfr_id);
                  ^~~~~~~

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

Fixes e01e7eaf37d8 ("iio: light: introduce si1133")

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]").

Quoted 23 lines
---
  drivers/iio/light/si1133.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/light/si1133.c +2 -2
index c280b4195003..fd302480262b 100644
@@ -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;
  	}
maintainer
#2 lore raw
Quoted 13 lines · On Fri, 14 May 2021 10:45:02 -0700 Nathan Chancellor <[email protected]> wrote:
Quoted 12 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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.

Quoted 8 lines
Quoted 2 lines
Fixes e01e7eaf37d8 ("iio: light: introduce si1133")

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]").

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

Thanks,

Jonathan

Quoted 25 lines
Quoted 24 lines
---
  drivers/iio/light/si1133.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/light/si1133.c +2 -2
index c280b4195003..fd302480262b 100644
@@ -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;
  	}
#3 lore raw
Quoted 8 lines · Jonathan Cameron
Quoted 6 lines · On Fri, 14 May 2021 10:45:02 -0700 Nathan Chancellor <[email protected]> wrote:
Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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.

[]

Quoted 1 line
Quoted 1 line

drivers/iio/light/si1133.c

Quoted 1 line
drivers/iio/light/si1133.c +0 -0

[]

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/iio/light/si1133.c +0 -0
@@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev *iio_dev)
   		return err;

Quoted 8 lines
Quoted 8 lines

drivers/iio/light/si1133.c static int si1133_validate_ids(struct iio_dev *iio_dev) · line 985

Quoted 8 lines

   dev_info(&iio_dev->dev,

drivers/iio/light/si1133.c +1 -1
-		 "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,

drivers/iio/light/si1133.c +1 -1
-			"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

Quoted 1 line
Quoted 1 line
Quoted 1 line

   part_id, SI1133_PART_ID);

A message that is not in the archive (sent off-list or not yet received): CAHp75Vc72vMbj311P3xnxh6ExxzD1=enoETj6wY8dHn+xBJ4+w@mail.gmail.com

#5 lore raw
Quoted 34 lines · Andy Shevchenko
Quoted 33 lines · Joe Perches
Quoted 9 lines · Jonathan Cameron
Quoted 7 lines · On Fri, 14 May 2021 10:45:02 -0700 Nathan Chancellor <[email protected]> wrote:
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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]

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

                  part_id, rev_id, mfr_id);
                  ^~~~~~~

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

[]

Quoted 1 line
Quoted 1 line

drivers/iio/light/si1133.c

Quoted 1 line
drivers/iio/light/si1133.c +0 -0

[]

Quoted 1 line
Quoted 1 line

drivers/iio/light/si1133.c static int si1133_validate_ids(struct iio_dev

Quoted 1 line
drivers/iio/light/si1133.c +0 -0
@@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev

*iio_dev)

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/iio/light/si1133.c +2 -2
                   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",
Quoted 6 lines
Quoted 4 lines

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.

A message that is not in the archive (sent off-list or not yet received): CAHp75VeQdFoJrPhXU2fYdrhLUwvM4NEoPn=Z4WBPkhOa4xK+ig@mail.gmail.com

#7 lore raw
Quoted 1 line · Andy Shevchenko

On Saturday, May 29, 2021, Joe Perches <[email protected]> wrote:

[]

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 4 lines
Quoted 1 line

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.

#8 lore raw
Quoted 2 lines · Joe Perches
Quoted 1 line · Andy Shevchenko

On Saturday, May 29, 2021, Joe Perches <[email protected]> wrote:

...

Quoted 13 lines
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko