linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mediatek: mt76: eeprom: fix clang -Wformat warning
@ 2022-07-09  0:15 Justin Stitt
  2022-07-18 11:53 ` wifi: mt7601u: " Kalle Valo
  0 siblings, 1 reply; 2+ messages in thread
From: Justin Stitt @ 2022-07-09  0:15 UTC (permalink / raw)
  To: Jakub Kicinski, Kalle Valo, David S . Miller, Eric Dumazet,
	Paolo Abeni, Matthias Brugger
  Cc: Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-wireless,
	netdev, linux-arm-kernel, linux-mediatek, linux-kernel, llvm,
	Justin Stitt

When building with Clang we encounter the following warning:
| drivers/net/wireless/mediatek/mt7601u/eeprom.c:193:5: error: format
| specifies type 'char' but the argument has type 'int' [-Werror,-Wformat]
| chan_bounds[idx].start + chan_bounds[idx].num - 1);

Variadic functions (printf-like) undergo default argument promotion.
Documentation/core-api/printk-formats.rst specifically recommends using
the promoted-to-type's format flag.

Moreover, C11 6.3.1.1 states:
(https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf) `If an int
can represent all values of the original type ..., the value is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions.`

With this information in hand, we really should stop using `%hh[dxu]` or
`%h[dxu]` as they usually prompt Clang -Wformat warnings as well as go
against documented standard recommendations.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: produced warning with x86 allyesconfig.

 drivers/net/wireless/mediatek/mt7601u/eeprom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt7601u/eeprom.c b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
index aa3b64902cf9..625bebe60538 100644
--- a/drivers/net/wireless/mediatek/mt7601u/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
@@ -188,7 +188,7 @@ mt7601u_set_country_reg(struct mt7601u_dev *dev, u8 *eeprom)
 
 	if (idx != -1)
 		dev_info(dev->dev,
-			 "EEPROM country region %02hhx (channels %hhd-%hhd)\n",
+			 "EEPROM country region %02x (channels %d-%d)\n",
 			 val, chan_bounds[idx].start,
 			 chan_bounds[idx].start + chan_bounds[idx].num - 1);
 	else
-- 
2.37.0.rc0.161.g10f37bed90-goog


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

* Re: wifi: mt7601u: eeprom: fix clang -Wformat warning
  2022-07-09  0:15 [PATCH] mediatek: mt76: eeprom: fix clang -Wformat warning Justin Stitt
@ 2022-07-18 11:53 ` Kalle Valo
  0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2022-07-18 11:53 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Jakub Kicinski, David S . Miller, Eric Dumazet, Paolo Abeni,
	Matthias Brugger, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-wireless, netdev, linux-arm-kernel, linux-mediatek,
	linux-kernel, llvm, Justin Stitt

Justin Stitt <justinstitt@google.com> wrote:

> When building with Clang we encounter the following warning:
> | drivers/net/wireless/mediatek/mt7601u/eeprom.c:193:5: error: format
> | specifies type 'char' but the argument has type 'int' [-Werror,-Wformat]
> | chan_bounds[idx].start + chan_bounds[idx].num - 1);
> 
> Variadic functions (printf-like) undergo default argument promotion.
> Documentation/core-api/printk-formats.rst specifically recommends using
> the promoted-to-type's format flag.
> 
> Moreover, C11 6.3.1.1 states:
> (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf) `If an int
> can represent all values of the original type ..., the value is
> converted to an int; otherwise, it is converted to an unsigned int.
> These are called the integer promotions.`
> 
> With this information in hand, we really should stop using `%hh[dxu]` or
> `%h[dxu]` as they usually prompt Clang -Wformat warnings as well as go
> against documented standard recommendations.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Signed-off-by: Justin Stitt <justinstitt@google.com>

Patch applied to wireless-next.git, thanks.

07db88f11e63 wifi: mt7601u: eeprom: fix clang -Wformat warning

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20220709001527.618593-1-justinstitt@google.com/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


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

end of thread, other threads:[~2022-07-18 11:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-09  0:15 [PATCH] mediatek: mt76: eeprom: fix clang -Wformat warning Justin Stitt
2022-07-18 11:53 ` wifi: mt7601u: " Kalle Valo

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