Skip to contentSkip to conversation

rtlwifi: remove redundant initialization of variable ul_encalgo

PATCH In review Colin Ian King 5 participants 9 messages Jan 30, 2022 – Feb 2, 2022

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

PATCH 1/1 rtlwifi: remove redundant initialization of variable ul_encalgo

Variable ul_encalgo is initialized with a value that is never read, it is being re-assigned a new value in every case in the following switch statement. The initialization is redundant and can be removed.

---
 drivers/net/wireless/realtek/rtlwifi/cam.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtlwifi/cam.c +1 -1
index 7a0355dc6bab..32970ea4b4e7 100644
@@ -208,7 +208,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
 
 	u32 ul_command;
 	u32 ul_content;
-	u32 ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+	u32 ul_encalgo;
 	u8 entry_i;
 
 	switch (rtlpriv->sec.pairwise_enc_algorithm) {
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Colin Ian King

Variable ul_encalgo is initialized with a value that is never read, it is being re-assigned a new value in every case in the following switch statement. The initialization is redundant and can be removed.

Quoted 11 lines
---
 drivers/net/wireless/realtek/rtlwifi/cam.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtlwifi/cam.c +0 -0
index 7a0355dc6bab..32970ea4b4e7 100644

drivers/net/wireless/realtek/rtlwifi/cam.c void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index) · line 214

Quoted 8 lines
drivers/net/wireless/realtek/rtlwifi/cam.c +1 -1
@@ -208,7 +208,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
 
 	u32 ul_command;
 	u32 ul_content;
-	u32 ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+	u32 ul_encalgo;
 	u8 entry_i;
 
 	switch (rtlpriv->sec.pairwise_enc_algorithm) {

When I check this patch, I find there is no 'break' for default case. Do we need one? like

@@ -226,6 +226,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)

                break;
        default:
                ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+               break;
        }
 
        for (entry_i = 0; entry_i < CAM_CONTENT_COUNT; entry_i++) {

--
Ping-Ke

#2 lore raw
Quoted 33 lines · Pkshih
Quoted 5 lines · Colin Ian King

Variable ul_encalgo is initialized with a value that is never read, it is being re-assigned a new value in every case in the following switch statement. The initialization is redundant and can be removed.

Quoted 11 lines
---
 drivers/net/wireless/realtek/rtlwifi/cam.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtlwifi/cam.c +0 -0
index 7a0355dc6bab..32970ea4b4e7 100644

drivers/net/wireless/realtek/rtlwifi/cam.c void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index) · line 214

Quoted 8 lines
drivers/net/wireless/realtek/rtlwifi/cam.c +1 -1
@@ -208,7 +208,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
 
 	u32 ul_command;
 	u32 ul_content;
-	u32 ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+	u32 ul_encalgo;
 	u8 entry_i;
 
 	switch (rtlpriv->sec.pairwise_enc_algorithm) {

When I check this patch, I find there is no 'break' for default case. Do we need one? like

Review void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index) · line 232

Quoted 7 lines
(quoted diff) +1 -0
@@ -226,6 +226,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
                break;
        default:
                ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+               break;
        }
 
        for (entry_i = 0; entry_i < CAM_CONTENT_COUNT; entry_i++) {

Yeah, it would be good to have break for consistency. Can someone send a separate patch for that?

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

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw
In reply to Pkshih

Review void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index) · line 229

Quoted 10 lines · Pkshih

On Sun, 2022-01-30 at 22:37 +0000, Colin Ian King wrote:

When I check this patch, I find there is no 'break' for default case. Do we need one? like

(quoted diff) +1 -0
@@ -226,6 +226,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
                break;
        default:
                ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+               break;

No, it's not necessary. The choice of style is up to the original developer.

regards,
dan carpenter

#4 lore raw
Quoted 6 lines · Dan Carpenter
Quoted 5 lines · Pkshih

On Sun, 2022-01-30 at 22:37 +0000, Colin Ian King wrote:

When I check this patch, I find there is no 'break' for default case. Do we need one? like

Quoted 8 lines

Review void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index) · line 229

Quoted 5 lines
(quoted diff) +1 -0
@@ -226,6 +226,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
                break;
        default:
                ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+               break;

No, it's not necessary. The choice of style is up to the original developer.

every case should have one.

Documentation/process/deprecated.rst:

All switch/case blocks must end in one of:

* break;
* fallthrough;
* continue;
* goto <label>;
* return [expression];

#5 lore raw
Quoted 20 lines · Joe Perches
Quoted 6 lines · Dan Carpenter
Quoted 5 lines · Pkshih

On Sun, 2022-01-30 at 22:37 +0000, Colin Ian King wrote:

When I check this patch, I find there is no 'break' for default case. Do we need one? like

Quoted 8 lines

Review void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index) · line 229

Quoted 5 lines
(quoted diff) +1 -0
@@ -226,6 +226,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
                break;
        default:
                ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+               break;

No, it's not necessary. The choice of style is up to the original developer.

every case should have one.

Documentation/process/deprecated.rst:

Quoted 8 lines

All switch/case blocks must end in one of:

* break;
* fallthrough;
* continue;
* goto <label>;
* return [expression];

I doubt that's what Kees had in mind when he wrote that.

The extra break statement doesn't improve readability. It also doesn't hurt readability.

There is no reason to add a break statement after a default case. No one is going to add another case after the default case. And if they do then a dozen static analysis tools will complain about the missing break.

I looked through the code to see if break statements were more common than non-break statement code. Both seem pretty common. I got bored really quickly though and my sample might not have been representative.

regards,
dan carpenter

#6 lore raw
Quoted 23 lines · Dan Carpenter
Quoted 22 lines · Joe Perches
Quoted 6 lines · Dan Carpenter
Quoted 5 lines · Pkshih

On Sun, 2022-01-30 at 22:37 +0000, Colin Ian King wrote:

When I check this patch, I find there is no 'break' for default case. Do we need one? like

Quoted 8 lines

Review void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index) · line 229

Quoted 5 lines
(quoted diff) +1 -0
@@ -226,6 +226,7 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
                break;
        default:
                ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
+               break;

No, it's not necessary. The choice of style is up to the original developer.

every case should have one.

Documentation/process/deprecated.rst:

All switch/case blocks must end in one of:

Quoted 8 lines
Quoted 6 lines

* break;
* fallthrough;
* continue;
* goto <label>;
* return [expression];

I doubt that's what Kees had in mind when he wrote that.

uhh, I wrote that. I think Kees reformatted it for .rst

Quoted 5 lines

The extra break statement doesn't improve readability. It also doesn't hurt readability.

There is no reason to add a break statement after a default case. No one is going to add another case after the default case.

Several hundred switch statements in the kernel use default:
as the first block.

Quoted 3 lines

And if they
do then a dozen static analysis tools will complain about the missing break.

true, doesn't mean that's a good thing.

#7 lore raw
Quoted 3 lines · Joe Perches
Quoted 1 line

I doubt that's what Kees had in mind when he wrote that.

uhh, I wrote that. I think Kees reformatted it for .rst

Heh.

You should have mentioned that you invented that rule! That's like editing Wikipedia to say what you want and then citing it as a source...

regards,
dan carpenter

#8 lore raw
In reply to Colin Ian King
Quoted 6 lines · Colin Ian King

Variable ul_encalgo is initialized with a value that is never read, it is being re-assigned a new value in every case in the following switch statement. The initialization is redundant and can be removed.

Patch applied to wireless-next.git, thanks.

e80affde1720 rtlwifi: remove redundant initialization of variable ul_encalgo

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

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