linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iwlwifi: work around clang -Wuninitialized warning
@ 2019-03-22 14:13 Arnd Bergmann
  2019-03-23  6:11 ` Luca Coelho
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:13 UTC (permalink / raw)
  To: Johannes Berg
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Arnd Bergmann, Emmanuel Grumbach, Luca Coelho,
	Intel Linux Wireless, Kalle Valo, David S. Miller, Sara Sharon,
	Avraham Stern, linux-wireless, netdev, linux-kernel

Clang incorrectly warns about an uninitialized variable:

drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2114:12: error: variable 'queue' is used uninitialized whenever 'if'
      condition is false [-Werror,-Wsometimes-uninitialized]
                else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/bug.h:130:36: note: expanded from macro 'WARN'
 #define WARN(condition, format...) ({                                   \
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2119:33: note: uninitialized use occurs here
                iwl_mvm_enable_txq(mvm, NULL, queue, 0, &cfg, wdg_timeout);
                                              ^~~~~
drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2114:8: note: remove the 'if' if its condition is always true
                else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2094:11: note: initialize the variable 'queue' to silence this warning
        int queue;
                 ^
                  = 0
1 error generated.

This cannot happen because the if/else if/else if block always
has one code path that is entered. However, we can simply
rearrange the code to let clang see this as well.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/wireless/intel/iwlwifi/mvm/sta.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
index 498c315291cf..91ce56d2ebb8 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
@@ -2107,12 +2107,14 @@ int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
 
 	if (!iwl_mvm_has_new_tx_api(mvm)) {
 		if (vif->type == NL80211_IFTYPE_AP ||
-		    vif->type == NL80211_IFTYPE_ADHOC)
+		    vif->type == NL80211_IFTYPE_ADHOC) {
 			queue = mvm->probe_queue;
-		else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
+		} else if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
 			queue = mvm->p2p_dev_queue;
-		else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
+		} else {
+			WARN(1, "Missing required TXQ for adding bcast STA\n");
 			return -EINVAL;
+		}
 
 		bsta->tfd_queue_msk |= BIT(queue);
 
-- 
2.20.0


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

* Re: [PATCH] iwlwifi: work around clang -Wuninitialized warning
  2019-03-22 14:13 [PATCH] iwlwifi: work around clang -Wuninitialized warning Arnd Bergmann
@ 2019-03-23  6:11 ` Luca Coelho
  2019-03-23 11:28   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Luca Coelho @ 2019-03-23  6:11 UTC (permalink / raw)
  To: Arnd Bergmann, Johannes Berg
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Emmanuel Grumbach, Intel Linux Wireless, Kalle Valo,
	David S. Miller, Sara Sharon, Avraham Stern, linux-wireless,
	netdev, linux-kernel

On Fri, 2019-03-22 at 15:13 +0100, Arnd Bergmann wrote:
> Clang incorrectly warns about an uninitialized variable:
> 
> drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2114:12: error: variable
> 'queue' is used uninitialized whenever 'if'
>       condition is false [-Werror,-Wsometimes-uninitialized]
>                 else if (WARN(1, "Missing required TXQ for adding
> bcast STA\n"))
>                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~
> include/asm-generic/bug.h:130:36: note: expanded from macro 'WARN'
>  #define WARN(condition, format...)
> ({                                   \
>                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~
> drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2119:33: note:
> uninitialized use occurs here
>                 iwl_mvm_enable_txq(mvm, NULL, queue, 0, &cfg,
> wdg_timeout);
>                                               ^~~~~
> drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2114:8: note: remove the
> 'if' if its condition is always true
>                 else if (WARN(1, "Missing required TXQ for adding
> bcast STA\n"))
>                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~
> drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2094:11: note:
> initialize the variable 'queue' to silence this warning
>         int queue;
>                  ^
>                   = 0
> 1 error generated.
> 
> This cannot happen because the if/else if/else if block always
> has one code path that is entered. However, we can simply
> rearrange the code to let clang see this as well.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---

Thanks for the patch, Arnd! But I have already queued up an equivalent
patch for v5.2 (should probably reach linux-next by the end of next
week or so):

https://patchwork.kernel.org/patch/10844025/

--
Cheers,
Luca.


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

* Re: [PATCH] iwlwifi: work around clang -Wuninitialized warning
  2019-03-23  6:11 ` Luca Coelho
@ 2019-03-23 11:28   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-23 11:28 UTC (permalink / raw)
  To: Luca Coelho
  Cc: Johannes Berg, clang-built-linux, Nick Desaulniers,
	Nathan Chancellor, Emmanuel Grumbach, Intel Linux Wireless,
	Kalle Valo, David S. Miller, Sara Sharon, Avraham Stern,
	linux-wireless, Networking, Linux Kernel Mailing List

On Sat, Mar 23, 2019 at 7:11 AM Luca Coelho <luca@coelho.fi> wrote:
>
> On Fri, 2019-03-22 at 15:13 +0100, Arnd Bergmann wrote:
> > Clang incorrectly warns about an uninitialized variable:
> >
> >
> > This cannot happen because the if/else if/else if block always
> > has one code path that is entered. However, we can simply
> > rearrange the code to let clang see this as well.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
>
> Thanks for the patch, Arnd! But I have already queued up an equivalent
> patch for v5.2 (should probably reach linux-next by the end of next
> week or so):
>
> https://patchwork.kernel.org/patch/10844025/

Thanks, and sorry for the duplicate. I forgot to check for the
patches that Nathan had already done when I started sending
out my own series on the same issues.

       Arnd

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

end of thread, other threads:[~2019-03-23 11:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 14:13 [PATCH] iwlwifi: work around clang -Wuninitialized warning Arnd Bergmann
2019-03-23  6:11 ` Luca Coelho
2019-03-23 11:28   ` Arnd Bergmann

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