Message ID | 20210803144949.79433-2-colin.king@canonical.com (mailing list archive) |
---|---|
State | Awaiting Upstream |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [1/3,RESEND] rtlwifi: rtl8192de: Remove redundant variable initializations | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
On Tue, 2021-08-03 at 15:49 +0100, Colin King wrote: > Don't populate arrays the stack but instead make them static const. Replace > array channel_info with channel_all since it contains the same data as > channel_all. Makes object code smaller by 961 bytes. [] > diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c [] > @@ -160,6 +160,15 @@ static u32 targetchnl_2g[TARGET_CHNL_NUM_2G] = { > 25711, 25658, 25606, 25554, 25502, 25451, 25328 > }; > > +static const u8 channel_all[59] = { I don't believe there is a significant value in sizing the array as 59 instead of letting the compiler count the elements. > + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, > + 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, > + 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, > + 114, 116, 118, 120, 122, 124, 126, 128, 130, > + 132, 134, 136, 138, 140, 149, 151, 153, 155, > + 157, 159, 161, 163, 165 > +};
On 03/08/2021 16:09, Joe Perches wrote: > On Tue, 2021-08-03 at 15:49 +0100, Colin King wrote: >> Don't populate arrays the stack but instead make them static const. Replace >> array channel_info with channel_all since it contains the same data as >> channel_all. Makes object code smaller by 961 bytes. > [] >> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c > [] >> @@ -160,6 +160,15 @@ static u32 targetchnl_2g[TARGET_CHNL_NUM_2G] = { >> 25711, 25658, 25606, 25554, 25502, 25451, 25328 >> }; >> >> +static const u8 channel_all[59] = { > > I don't believe there is a significant value in sizing the array > as 59 instead of letting the compiler count the elements. I was reluctant to remove this as I supposed the original had it in for a purpose, e.g. to ensure that the array was not populated with more data than intended. Does it make much of a difference? > >> + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, >> + 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, >> + 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, >> + 114, 116, 118, 120, 122, 124, 126, 128, 130, >> + 132, 134, 136, 138, 140, 149, 151, 153, 155, >> + 157, 159, 161, 163, 165 >> +}; > >
On Tue, 2021-08-03 at 16:15 +0100, Colin Ian King wrote: > On 03/08/2021 16:09, Joe Perches wrote: > > On Tue, 2021-08-03 at 15:49 +0100, Colin King wrote: > > > Don't populate arrays the stack but instead make them static const. Replace > > > array channel_info with channel_all since it contains the same data as > > > channel_all. Makes object code smaller by 961 bytes. > > [] > > > diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c > > [] > > > @@ -160,6 +160,15 @@ static u32 targetchnl_2g[TARGET_CHNL_NUM_2G] = { > > > 25711, 25658, 25606, 25554, 25502, 25451, 25328 > > > }; > > > > > > +static const u8 channel_all[59] = { > > > > I don't believe there is a significant value in sizing the array > > as 59 instead of letting the compiler count the elements. > > I was reluctant to remove this as I supposed the original had it in for > a purpose, e.g. to ensure that the array was not populated with more > data than intended. Does it make much of a difference? > > > > > > + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, > > > + 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, > > > + 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, > > > + 114, 116, 118, 120, 122, 124, 126, 128, 130, > > > + 132, 134, 136, 138, 140, 149, 151, 153, 155, > > > + 157, 159, 161, 163, 165 > > > +}; Dunno. Maybe not, but I did have to count the elements to see if it really was 59 or the compiler was adding trailing 0's. OK I really did a grep to count the commas and added 1...
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c index 50c2d8f6f9c0..8ae69d914312 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/phy.c @@ -160,6 +160,15 @@ static u32 targetchnl_2g[TARGET_CHNL_NUM_2G] = { 25711, 25658, 25606, 25554, 25502, 25451, 25328 }; +static const u8 channel_all[59] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, + 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, + 114, 116, 118, 120, 122, 124, 126, 128, 130, + 132, 134, 136, 138, 140, 149, 151, 153, 155, + 157, 159, 161, 163, 165 +}; + static u32 _rtl92d_phy_calculate_bit_shift(u32 bitmask) { u32 i = ffs(bitmask); @@ -1354,14 +1363,6 @@ static void _rtl92d_phy_switch_rf_setting(struct ieee80211_hw *hw, u8 channel) u8 rtl92d_get_rightchnlplace_for_iqk(u8 chnl) { - u8 channel_all[59] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, - 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, - 114, 116, 118, 120, 122, 124, 126, 128, 130, - 132, 134, 136, 138, 140, 149, 151, 153, 155, - 157, 159, 161, 163, 165 - }; u8 place = chnl; if (chnl > 14) { @@ -3220,37 +3221,28 @@ void rtl92d_phy_config_macphymode_info(struct ieee80211_hw *hw) u8 rtl92d_get_chnlgroup_fromarray(u8 chnl) { u8 group; - u8 channel_info[59] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, - 58, 60, 62, 64, 100, 102, 104, 106, 108, - 110, 112, 114, 116, 118, 120, 122, 124, - 126, 128, 130, 132, 134, 136, 138, 140, - 149, 151, 153, 155, 157, 159, 161, 163, - 165 - }; - if (channel_info[chnl] <= 3) + if (channel_all[chnl] <= 3) group = 0; - else if (channel_info[chnl] <= 9) + else if (channel_all[chnl] <= 9) group = 1; - else if (channel_info[chnl] <= 14) + else if (channel_all[chnl] <= 14) group = 2; - else if (channel_info[chnl] <= 44) + else if (channel_all[chnl] <= 44) group = 3; - else if (channel_info[chnl] <= 54) + else if (channel_all[chnl] <= 54) group = 4; - else if (channel_info[chnl] <= 64) + else if (channel_all[chnl] <= 64) group = 5; - else if (channel_info[chnl] <= 112) + else if (channel_all[chnl] <= 112) group = 6; - else if (channel_info[chnl] <= 126) + else if (channel_all[chnl] <= 126) group = 7; - else if (channel_info[chnl] <= 140) + else if (channel_all[chnl] <= 140) group = 8; - else if (channel_info[chnl] <= 153) + else if (channel_all[chnl] <= 153) group = 9; - else if (channel_info[chnl] <= 159) + else if (channel_all[chnl] <= 159) group = 10; else group = 11;