Skip to contentSkip to conversation

iwlwifi: fw: move memset before early return

PATCH In review Tom Rix 2 participants 2 messages Apr 1, 2022 – Apr 5, 2022

Subsystems (3)
lore
Share & tools
lore

Tom Rix

author
#0 lore raw

PATCH 1/1 iwlwifi: fw: move memset before early return

Clang static analysis reports this representative issue dbg.c:1455:6: warning: Branch condition evaluates to a garbage value
if (!rxf_data.size)

       ^~~~~~~~~~~~~~

This check depends on iwl_ini_get_rxf_data() to clear rxf_data but the function can return early without doing the clear. So move the memset before the early return.

Fixes cc9b6012d34b ("iwlwifi: yoyo: use hweight_long instead of bit manipulating")
---
 drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/fw/dbg.c +2 -2
index abf49022edbe..666de922af61 100644
@@ -1388,13 +1388,13 @@ static void iwl_ini_get_rxf_data(struct iwl_fw_runtime *fwrt,
 	if (!data)
 		return;
 
+	memset(data, 0, sizeof(*data));
+
 	/* make sure only one bit is set in only one fid */
 	if (WARN_ONCE(hweight_long(fid1) + hweight_long(fid2) != 1,
 		      "fid1=%x, fid2=%x\n", fid1, fid2))
 		return;
 
-	memset(data, 0, sizeof(*data));
-
 	if (fid1) {
 		fifo_idx = ffs(fid1) - 1;
 		if (WARN_ONCE(fifo_idx >= MAX_NUM_LMAC, "fifo_idx=%d\n",
Signature · 1 line
2.27.0
#1 lore raw
Quoted 7 lines · Tom Rix

Clang static analysis reports this representative issue dbg.c:1455:6: warning: Branch condition evaluates to a garbage value
if (!rxf_data.size)

       ^~~~~~~~~~~~~~
Quoted 7 lines

This check depends on iwl_ini_get_rxf_data() to clear rxf_data but the function can return early without doing the clear. So move the memset before the early return.

Fixes cc9b6012d34b ("iwlwifi: yoyo: use hweight_long instead of bit manipulating")

Conditional initialization in a helper is a pretty dangerous pattern. How about we move the memset to the two callers of iwl_ini_get_rxf_data?

Quoted 27 lines
---
 drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/fw/dbg.c +2 -3
index abf49022edbe..666de922af61 100644
@@ -1388,13 +1388,13 @@ static void iwl_ini_get_rxf_data(struct iwl_fw_runtime *fwrt,
        if (!data)
                return;
 
+       memset(data, 0, sizeof(*data));
+
        /* make sure only one bit is set in only one fid */
        if (WARN_ONCE(hweight_long(fid1) + hweight_long(fid2) != 1,
                      "fid1=%x, fid2=%x\n", fid1, fid2))
                return;
 
-       memset(data, 0, sizeof(*data));
-
        if (fid1) {
                fifo_idx = ffs(fid1) - 1;
                if (WARN_ONCE(fifo_idx >= MAX_NUM_LMAC, "fifo_idx=%d\n",
--

2.27.0

Signature · 2 lines
Thanks,
~Nick Desaulniers