Skip to contentSkip to conversation

platform/chrome: cros_ec_typec: fix clang -Wformat warning

PATCH Applied Arnd Bergmann 3 participants 3 messages Mar 22, 2021 – Mar 31, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/chrome: cros_ec_typec: fix clang -Wformat warning

From: Arnd Bergmann <[email protected]>

Clang warns about using the %h format modifier to truncate an integer:

drivers/platform/chrome/cros_ec_typec.c:1031:3: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]

                typec->pd_ctrl_ver);
                ^~~~~~~~~~~~~~~~~~
include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                    ~~~     ^~~~~~~~~~~

Use an explicit bit mask to limit the number to its lower eight bits instead.

Fixes ad7c0510c99e ("platform/chrome: cros_ec_typec: Update port info from EC")
---
 drivers/platform/chrome/cros_ec_typec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +2 -2
index 0811562deecc..f07b7e946560 100644
@@ -1027,8 +1027,8 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
 	else
 		typec->pd_ctrl_ver = 0;
 
-	dev_dbg(typec->dev, "PD Control has version mask 0x%hhx\n",
-		typec->pd_ctrl_ver);
+	dev_dbg(typec->dev, "PD Control has version mask 0x%02x\n",
+		typec->pd_ctrl_ver & 0xff);
 
 	return 0;
 }
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Clang warns about using the %h format modifier to truncate an integer:

drivers/platform/chrome/cros_ec_typec.c:1031:3: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]

                typec->pd_ctrl_ver);
                ^~~~~~~~~~~~~~~~~~
include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                    ~~~     ^~~~~~~~~~~
Quoted 5 lines

Use an explicit bit mask to limit the number to its lower eight bits instead.

Fixes ad7c0510c99e ("platform/chrome: cros_ec_typec: Update port info from EC")
Quoted 23 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +2 -3
index 0811562deecc..f07b7e946560 100644
@@ -1027,8 +1027,8 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
        else
                typec->pd_ctrl_ver = 0;
 
-       dev_dbg(typec->dev, "PD Control has version mask 0x%hhx\n",
-               typec->pd_ctrl_ver);
+       dev_dbg(typec->dev, "PD Control has version mask 0x%02x\n",
+               typec->pd_ctrl_ver & 0xff);
 
        return 0;
 }
--

2.29.2

#2 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

Clang warns about using the %h format modifier to truncate an integer:

drivers/platform/chrome/cros_ec_typec.c:1031:3: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]

                typec->pd_ctrl_ver);
                ^~~~~~~~~~~~~~~~~~
include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                    ~~~     ^~~~~~~~~~~

[...]

Applied, thanks!

[1/1] platform/chrome: cros_ec_typec: fix clang -Wformat warning

      commit: c6e939c63c80c26460b25cf1150ebe8396e8adcf

Best regards,

Signature · 1 line
Enric Balletbo i Serra <[email protected]>