diff mbox series

rtlwifi: remove redundant initialization of variable ul_encalgo

Message ID 20220130223714.6999-1-colin.i.king@gmail.com
State New
Headers show
Series rtlwifi: remove redundant initialization of variable ul_encalgo | expand

Commit Message

Colin Ian King Jan. 30, 2022, 10:37 p.m. UTC
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.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/net/wireless/realtek/rtlwifi/cam.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ping-Ke Shih Jan. 31, 2022, 2:53 a.m. UTC | #1
On Sun, 2022-01-30 at 22:37 +0000, Colin Ian King wrote:
> 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.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>

Acked-by: Ping-Ke Shih <pkshih@realtek.com>

> ---
>  drivers/net/wireless/realtek/rtlwifi/cam.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtlwifi/cam.c
> b/drivers/net/wireless/realtek/rtlwifi/cam.c
> index 7a0355dc6bab..32970ea4b4e7 100644
> --- a/drivers/net/wireless/realtek/rtlwifi/cam.c
> +++ b/drivers/net/wireless/realtek/rtlwifi/cam.c
> @@ -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
Kalle Valo Feb. 1, 2022, 12:22 p.m. UTC | #2
Pkshih <pkshih@realtek.com> writes:

> On Sun, 2022-01-30 at 22:37 +0000, Colin Ian King wrote:
>> 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.
>> 
>> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
>
> Acked-by: Ping-Ke Shih <pkshih@realtek.com>
>
>> ---
>>  drivers/net/wireless/realtek/rtlwifi/cam.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/net/wireless/realtek/rtlwifi/cam.c
>> b/drivers/net/wireless/realtek/rtlwifi/cam.c
>> index 7a0355dc6bab..32970ea4b4e7 100644
>> --- a/drivers/net/wireless/realtek/rtlwifi/cam.c
>> +++ b/drivers/net/wireless/realtek/rtlwifi/cam.c
>> @@ -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++) {

Yeah, it would be good to have break for consistency. Can someone send a
separate patch for that?
Kalle Valo Feb. 1, 2022, 12:26 p.m. UTC | #3
Colin Ian King <colin.i.king@gmail.com> wrote:

> 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.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> Acked-by: Ping-Ke Shih <pkshih@realtek.com>

Patch applied to wireless-next.git, thanks.

e80affde1720 rtlwifi: remove redundant initialization of variable ul_encalgo
Dan Carpenter Feb. 2, 2022, 5:02 a.m. UTC | #4
On Mon, Jan 31, 2022 at 02:53:40AM +0000, Pkshih wrote:
> 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
> 
> @@ -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
Joe Perches Feb. 2, 2022, 10:10 a.m. UTC | #5
On Wed, 2022-02-02 at 08:02 +0300, Dan Carpenter wrote:
> On Mon, Jan 31, 2022 at 02:53:40AM +0000, Pkshih wrote:
> > 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
> > 
> > @@ -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];
Dan Carpenter Feb. 2, 2022, 11:05 a.m. UTC | #6
On Wed, Feb 02, 2022 at 02:10:40AM -0800, Joe Perches wrote:
> On Wed, 2022-02-02 at 08:02 +0300, Dan Carpenter wrote:
> > On Mon, Jan 31, 2022 at 02:53:40AM +0000, Pkshih wrote:
> > > 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
> > > 
> > > @@ -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];
> 

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
Joe Perches Feb. 2, 2022, 11:21 a.m. UTC | #7
On Wed, 2022-02-02 at 14:05 +0300, Dan Carpenter wrote:
> On Wed, Feb 02, 2022 at 02:10:40AM -0800, Joe Perches wrote:
> > On Wed, 2022-02-02 at 08:02 +0300, Dan Carpenter wrote:
> > > On Mon, Jan 31, 2022 at 02:53:40AM +0000, Pkshih wrote:
> > > > 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
> > > > 
> > > > @@ -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];
> > 
> 
> I doubt that's what Kees had in mind when he wrote that.

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

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

> 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.
Dan Carpenter Feb. 2, 2022, 11:44 a.m. UTC | #8
On Wed, Feb 02, 2022 at 03:21:17AM -0800, Joe Perches wrote:
> > 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
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtlwifi/cam.c b/drivers/net/wireless/realtek/rtlwifi/cam.c
index 7a0355dc6bab..32970ea4b4e7 100644
--- a/drivers/net/wireless/realtek/rtlwifi/cam.c
+++ b/drivers/net/wireless/realtek/rtlwifi/cam.c
@@ -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) {