Skip to contentSkip to conversation

iwlwifi: mvm: fix clang -Wformat warnings

PATCH In review Justin Stitt 4 participants 6 messages Jul 11, 2022 – Aug 4, 2022

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

PATCH 1/1 iwlwifi: mvm: fix clang -Wformat warnings

When building with Clang we encounter these warnings:

| drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c:1108:47: error:
| format specifies type 'unsigned char' but the argument has type 's16'
| (aka 'short') [-Werror,-Wformat] IWL_DEBUG_INFO(mvm, "\tburst index:
| %hhu\n", res->ftm.burst_index);
-
| drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c:1111:47: error:
| format specifies type 'unsigned char' but the argument has type 's32'
| (aka 'int') [-Werror,-Wformat] IWL_DEBUG_INFO(mvm, "\trssi spread:
| %hhu\n", res->ftm.rssi_spread);

The previous format specifier %hhu describes a u8 but our arguments are wider than this which means bits are potentially being lost.

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

As per C11 6.3.1.1:
(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. Thus it makes sense to change %hhu to %d for both instances of the warning.

---
 drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c +2 -2
index 430044bc4755..e8702184c950 100644
@@ -1105,10 +1105,10 @@ static void iwl_mvm_debug_range_resp(struct iwl_mvm *mvm, u8 index,
 	IWL_DEBUG_INFO(mvm, "\tstatus: %d\n", res->status);
 	IWL_DEBUG_INFO(mvm, "\tBSSID: %pM\n", res->addr);
 	IWL_DEBUG_INFO(mvm, "\thost time: %llu\n", res->host_time);
-	IWL_DEBUG_INFO(mvm, "\tburst index: %hhu\n", res->ftm.burst_index);
+	IWL_DEBUG_INFO(mvm, "\tburst index: %d\n", res->ftm.burst_index);
 	IWL_DEBUG_INFO(mvm, "\tsuccess num: %u\n", res->ftm.num_ftmr_successes);
 	IWL_DEBUG_INFO(mvm, "\trssi: %d\n", res->ftm.rssi_avg);
-	IWL_DEBUG_INFO(mvm, "\trssi spread: %hhu\n", res->ftm.rssi_spread);
+	IWL_DEBUG_INFO(mvm, "\trssi spread: %d\n", res->ftm.rssi_spread);
 	IWL_DEBUG_INFO(mvm, "\trtt: %lld\n", res->ftm.rtt_avg);
 	IWL_DEBUG_INFO(mvm, "\trtt var: %llu\n", res->ftm.rtt_variance);
 	IWL_DEBUG_INFO(mvm, "\trtt spread: %llu\n", res->ftm.rtt_spread);
Signature · 1 line
2.37.0.144.g8ac04bfd2-goog
#1 lore raw

Any chance a maintainer could take a look at this patch? I am trying to get it through this cycle and we are so close to enabling the -Wformat option for Clang. There's only a handful of patches remaining until the patch enabling this warning can be sent!

#2 lore raw
Quoted 4 lines · Justin Stitt

Any chance a maintainer could take a look at this patch? I am trying to get it through this cycle and we are so close to enabling the -Wformat option for Clang. There's only a handful of patches remaining until the patch enabling this warning can be sent!

Gregory, can I take this directly to wireless-next? I assigned it to me in patchwork.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw
Quoted 10 lines · Kalle Valo
Quoted 4 lines · Justin Stitt

Any chance a maintainer could take a look at this patch? I am trying to get it through this cycle and we are so close to enabling the -Wformat option for Clang. There's only a handful of patches remaining until the patch enabling this warning can be sent!

Gregory, can I take this directly to wireless-next? I assigned it to me in patchwork.

Sorry for the long delay. Yes, it looks like a good fix. Thanks!

Reviewed-by on v1 1/1
#4 lore raw
In reply to Justin Stitt
Quoted 26 lines · Justin Stitt

When building with Clang we encounter these warnings:

| drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c:1108:47: error:
| format specifies type 'unsigned char' but the argument has type 's16'
| (aka 'short') [-Werror,-Wformat] IWL_DEBUG_INFO(mvm, "\tburst index:
| %hhu\n", res->ftm.burst_index);
-
| drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c:1111:47: error:
| format specifies type 'unsigned char' but the argument has type 's32'
| (aka 'int') [-Werror,-Wformat] IWL_DEBUG_INFO(mvm, "\trssi spread:
| %hhu\n", res->ftm.rssi_spread);

The previous format specifier %hhu describes a u8 but our arguments are wider than this which means bits are potentially being lost.

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

As per C11 6.3.1.1:
(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. Thus it makes sense to change %hhu to %d for both instances of the warning.

Quoted 2 lines

Thanks for the patch!

Quoted 24 lines
---
 drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c +2 -3
index 430044bc4755..e8702184c950 100644
@@ -1105,10 +1105,10 @@ static void iwl_mvm_debug_range_resp(struct iwl_mvm *mvm, u8 index,
        IWL_DEBUG_INFO(mvm, "\tstatus: %d\n", res->status);
        IWL_DEBUG_INFO(mvm, "\tBSSID: %pM\n", res->addr);
        IWL_DEBUG_INFO(mvm, "\thost time: %llu\n", res->host_time);
-       IWL_DEBUG_INFO(mvm, "\tburst index: %hhu\n", res->ftm.burst_index);
+       IWL_DEBUG_INFO(mvm, "\tburst index: %d\n", res->ftm.burst_index);
        IWL_DEBUG_INFO(mvm, "\tsuccess num: %u\n", res->ftm.num_ftmr_successes);
        IWL_DEBUG_INFO(mvm, "\trssi: %d\n", res->ftm.rssi_avg);
-       IWL_DEBUG_INFO(mvm, "\trssi spread: %hhu\n", res->ftm.rssi_spread);
+       IWL_DEBUG_INFO(mvm, "\trssi spread: %d\n", res->ftm.rssi_spread);
        IWL_DEBUG_INFO(mvm, "\trtt: %lld\n", res->ftm.rtt_avg);
        IWL_DEBUG_INFO(mvm, "\trtt var: %llu\n", res->ftm.rtt_variance);
        IWL_DEBUG_INFO(mvm, "\trtt spread: %llu\n", res->ftm.rtt_spread);
--

2.37.0.144.g8ac04bfd2-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw

Re: wifi: iwlwifi: mvm: fix clang -Wformat warnings

In reply to Justin Stitt
Quoted 25 lines · Justin Stitt

When building with Clang we encounter these warnings:

| drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c:1108:47: error:
| format specifies type 'unsigned char' but the argument has type 's16'
| (aka 'short') [-Werror,-Wformat] IWL_DEBUG_INFO(mvm, "\tburst index:
| %hhu\n", res->ftm.burst_index);
-
| drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c:1111:47: error:
| format specifies type 'unsigned char' but the argument has type 's32'
| (aka 'int') [-Werror,-Wformat] IWL_DEBUG_INFO(mvm, "\trssi spread:
| %hhu\n", res->ftm.rssi_spread);

The previous format specifier %hhu describes a u8 but our arguments are wider than this which means bits are potentially being lost.

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

As per C11 6.3.1.1:
(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. Thus it makes sense to change %hhu to %d for both instances of the warning.

Quoted 3 lines

Patch applied to wireless-next.git, thanks.

7819b3d1dab5 wifi: iwlwifi: mvm: fix clang -Wformat warnings

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

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