Message ID | 20220130223714.6999-1-colin.i.king@gmail.com |
---|---|
State | New |
Headers | show |
Series | rtlwifi: remove redundant initialization of variable ul_encalgo | expand |
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
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?
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
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
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];
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
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.
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 --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) {
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(-)