rtlwifi: Fix reusable codes in core.c
PATCH 1/1 rtlwifi: Fix reusable codes in core.c
rtl_*_delay() functions were reused same codes about addr variable. So i have converted to rtl_addr_delay() from code about addr variable.
Conditional codes in rtl_addr_delay() were improved in readability and performance by using switch codes.
--- drivers/net/wireless/realtek/rtlwifi/core.c | 48 +++++++++++------------------ 1 file changed, 18 insertions(+), 30 deletions(-)
drivers/net/wireless/realtek/rtlwifi/core.c +18 -30
@@ -37,36 +37,34 @@void rtl_addr_delay (u32 addr) { -if (addr ==0xfe ) +switch (addr) { +case 0xfe :mdelay (50 ); -else if (addr ==0xfd ) +break ; +case 0xfd :mdelay (5 ); -else if (addr ==0xfc ) +break ; +case 0xfc :mdelay (1 ); -else if (addr ==0xfb ) +break ; +case 0xfb :udelay (50 ); -else if (addr ==0xfa ) +break ; +case 0xfa :udelay (5 ); -else if (addr ==0xf9 ) +break ; +case 0xf9 :udelay (1 ); +break ; + }; }EXPORT_SYMBOL (rtl_addr_delay);void rtl_rfreg_delay (struct ieee80211_hw *hw,enum radio_path rfpath,u32 addr,u32 mask,u32 data) { -if (addr ==0xfe ) { -mdelay (50 ); - }else if (addr ==0xfd ) { -mdelay (5 ); - }else if (addr ==0xfc ) { -mdelay (1 ); - }else if (addr ==0xfb ) { -udelay (50 ); - }else if (addr ==0xfa ) { -udelay (5 ); - }else if (addr ==0xf9 ) { -udelay (1 ); +if (addr >=0xf9 && addr <=0xfe ) { +rtl_addr_delay (addr); }else {rtl_set_rfreg (hw, rfpath, addr, mask, data);udelay (1 );
@@ -76,18 +74,8 @@ EXPORT_SYMBOL(rtl_rfreg_delay);void rtl_bb_delay (struct ieee80211_hw *hw,u32 addr,u32 data) { -if (addr ==0xfe ) { -mdelay (50 ); - }else if (addr ==0xfd ) { -mdelay (5 ); - }else if (addr ==0xfc ) { -mdelay (1 ); - }else if (addr ==0xfb ) { -udelay (50 ); - }else if (addr ==0xfa ) { -udelay (5 ); - }else if (addr ==0xf9 ) { -udelay (1 ); +if (addr >=0xf9 && addr <=0xfe ) { +rtl_addr_delay (addr); }else {rtl_set_bbreg (hw, addr,MASKDWORD , data);udelay (1 );
Signature · 1 line
2.5.0
Hi Byeoungwook,
Quoted 35 lines · Byeoungwook Kim
rtl_*_delay() functions were reused same codes about addr variable. So i have converted to
rtl_addr_delay()from code about addr variable.Conditional codes in
rtl_addr_delay()were improved in readability and performance by using switch codes.Signed-off-by Byeoungwook Kim <[email protected]>--- drivers/net/wireless/realtek/rtlwifi/core.c | 48 +++++++++++------------------ 1 file changed, 18 insertions(+), 30 deletions(-)drivers/net/wireless/realtek/rtlwifi/core.c +8
-4@@ -37,36 +37,34 @@void rtl_addr_delay (u32 addr) { -if (addr ==0xfe ) +switch (addr) { +case 0xfe :mdelay (50 ); -else if (addr ==0xfd ) +break ; +case 0xfd :mdelay (5 ); -else if (addr ==0xfc ) +break ; +case 0xfc :mdelay (1 ); -else if (addr ==0xfb ) +break ; +case 0xfb :udelay (50 );
drivers/net/wireless/realtek/rtlwifi/core.c line 59
Quoted 10 lines
drivers/net/wireless/realtek/rtlwifi/core.c +6
-2-else if (addr ==0xfa ) +break ; +case 0xfa :udelay (5 ); -else if (addr ==0xf9 ) +break ; +case 0xf9 :udelay (1 ); +break ; + };
As you're introducing a case statement here, you could consolidate the addresses that have the same delays, i.e.
case 0xfe:
case 0xfb:
mdelay(50);
break;also, you should arguably be doing this cleanup in a separate patch, i.e.
1. Convert open coded instances to use this function (i.e. the changes below this comment)
2. Improve the function
Quoted 34 lines
drivers/net/wireless/realtek/rtlwifi/core.c +2
-19}EXPORT_SYMBOL (rtl_addr_delay);void rtl_rfreg_delay (struct ieee80211_hw *hw,enum radio_path rfpath,u32 addr,u32 mask,u32 data) { -if (addr ==0xfe ) { -mdelay (50 ); - }else if (addr ==0xfd ) { -mdelay (5 ); - }else if (addr ==0xfc ) { -mdelay (1 ); - }else if (addr ==0xfb ) { -udelay (50 ); - }else if (addr ==0xfa ) { -udelay (5 ); - }else if (addr ==0xf9 ) { -udelay (1 ); +if (addr >=0xf9 && addr <=0xfe ) { +rtl_addr_delay (addr); }else {rtl_set_rfreg (hw, rfpath, addr, mask, data);udelay (1 );@@ -76,18 +74,8 @@ EXPORT_SYMBOL(rtl_rfreg_delay);void rtl_bb_delay (struct ieee80211_hw *hw,u32 addr,u32 data) { -if (addr ==0xfe ) { -mdelay (50 ); - }else if (addr ==0xfd ) { -mdelay (5 ); - }else if (addr ==0xfc ) { -mdelay (1 ); - }else if (addr ==0xfb ) {
drivers/net/wireless/realtek/rtlwifi/core.c EXPORT_SYMBOL(rtl_rfreg_delay); · line 81
Quoted 10 lines
drivers/net/wireless/realtek/rtlwifi/core.c +2
-5-udelay (50 ); - }else if (addr ==0xfa ) { -udelay (5 ); - }else if (addr ==0xf9 ) { -udelay (1 ); +if (addr >=0xf9 && addr <=0xfe ) { +rtl_addr_delay (addr); }else {rtl_set_bbreg (hw, addr,MASKDWORD , data);udelay (1 );
Thanks,
Signature · 4 lines
Julian Calaby Email: [email protected] Profile: http://www.google.com/profiles/julian.calaby/
A message that is not in the archive (sent off-list or not yet received): CAOxTRzoGkNUy2FRUQLg_01D5p6Bjxfs+w8iEJJrkM2pTdkdC5Q@mail.gmail.com
Hi ByeoungWook,
Quoted 5 lines · ByeoungWook Kim
Hi Julian,
0xfeand0xfbwas not same codes.0xfeis udelay(50). and0xfbis mdelay(50).
It same code likeudelay((n) * 1000).
I'm clearly blind! Sorry about that!
Quoted 3 lines
but i agree with your answers of some parts. I think that i should divide into separate patch.
Thanks for your assists!
Not a problem!
Thanks,
Signature · 4 lines
Julian Calaby Email: [email protected] Profile: http://www.google.com/profiles/julian.calaby/