staging: r8188eu: refactor rtw_macaddr_cfg()
cover staging: r8188eu: refactor rtw_macaddr_cfg()
This series refactors rtw_macaddr_cfg().
- use mac_pton() instead of custom approach
- use *_ether_addr() functions to copy the mac address and check if it is a broadcast or zero address
- assign random default mac address instead of fixed one
- clean up minor style issues
Michael Straube (8):
staging: r8188eu use mac_pton() in rtw_macaddr_cfg()
staging: r8188eu: ensure mac address buffer is properly aligned
staging: r8188eu: use ETH_ALEN
staging: r8188eu: use is_*_ether_addr() in rtw_macaddr_cfg()
staging: r8188eu: use random default mac address
staging: r8188eu: use ether_addr_copy() in rtw_macaddr_cfg()
staging: r8188eu: add missing blank line after declarations
staging: r8188eu: remove unnecessary parentheses
drivers/staging/r8188eu/core/rtw_ieee80211.c | 33 +++++++------------- drivers/staging/r8188eu/include/rtw_eeprom.h | 2 +- 2 files changed, 12 insertions(+), 23 deletions(-)
Signature · 1 line
2.33.0
PATCH 1/8 staging: r8188eu use mac_pton() in rtw_macaddr_cfg()
Instead of a custom approach use mac_pton() to convert the mac address string. With mac_pton() the driver also validates the input now.
--- drivers/staging/r8188eu/core/rtw_ieee80211.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +4 -6
@@ -1024,13 +1024,11 @@ void rtw_macaddr_cfg(u8 *mac_addr)if (!mac_addr)return ; -if (rtw_initmac) {/* Users specify the mac address */ -int jj, kk; - -for (jj =0 , kk =0 ; jj <ETH_ALEN ; jj++, kk +=3 ) - mac[jj] =key_2char2num (rtw_initmac[kk], rtw_initmac[kk +1 ]); +if (rtw_initmac &&mac_pton (rtw_initmac, mac)) { +/* Users specify the mac address */ memcpy (mac_addr, mac,ETH_ALEN ); - }else {/* Use the mac address stored in the Efuse */ + }else { +/* Use the mac address stored in the Efuse */ memcpy (mac, mac_addr,ETH_ALEN ); }
Signature · 1 line
2.33.0
PATCH 2/8 staging: r8188eu: ensure mac address buffer is properly aligned
In reply to Michael StraubeEnsure the mac address buffer in struct eeprom_priv is properly aligned for use with functions from <linux/etherdevice.h>.
--- drivers/staging/r8188eu/include/rtw_eeprom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/include/rtw_eeprom.h +1 -1
@@ -99,7 +99,7 @@ struct eeprom_priv {u8 bautoload_fail_flag;u8 bloadfile_fail_flag;u8 bloadmac_fail_flag; -u8 mac_addr[6 ];/* PermanentAddress */ +u8 mac_addr[6 ]__aligned(2) ;/* PermanentAddress */ u16 channel_plan;u8 EepromOrEfuse;u8 efuse_eeprom_data[HWSET_MAX_SIZE_512 ]__aligned(4) ;
Signature · 1 line
2.33.0
PATCH 3/8 staging: r8188eu: use ETH_ALEN
In reply to Michael StraubeUse ETH_ALEN instead of hard-coding the value for the mac_addr buffer in struct eeprom_priv.
--- drivers/staging/r8188eu/include/rtw_eeprom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/include/rtw_eeprom.h +1 -1
@@ -99,7 +99,7 @@ struct eeprom_priv {u8 bautoload_fail_flag;u8 bloadfile_fail_flag;u8 bloadmac_fail_flag; -u8 mac_addr[6 ]__aligned(2) ;/* PermanentAddress */ +u8 mac_addr[ETH_ALEN ]__aligned(2) ;/* PermanentAddress */ u16 channel_plan;u8 EepromOrEfuse;u8 efuse_eeprom_data[HWSET_MAX_SIZE_512 ]__aligned(4) ;
Signature · 1 line
2.33.0
PATCH 4/8 staging: r8188eu: use is_*_ether_addr() in rtw_macaddr_cfg()
In reply to Michael StraubeUse is_broadcast_ether_addr() and is_zero_ether_addr() in rtw_macaddr_cfg(). The buffer is properly aligned.
--- drivers/staging/r8188eu/core/rtw_ieee80211.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -4
@@ -1032,10 +1032,7 @@ void rtw_macaddr_cfg(u8 *mac_addr)memcpy (mac, mac_addr,ETH_ALEN ); } -if (((mac[0 ] ==0xff ) && (mac[1 ] ==0xff ) && (mac[2 ] ==0xff ) && - (mac[3 ] ==0xff ) && (mac[4 ] ==0xff ) && (mac[5 ] ==0xff )) || - ((mac[0 ] ==0x0 ) && (mac[1 ] ==0x0 ) && (mac[2 ] ==0x0 ) && - (mac[3 ] ==0x0 ) && (mac[4 ] ==0x0 ) && (mac[5 ] ==0x0 ))) { +if (is_broadcast_ether_addr (mac) ||is_zero_ether_addr (mac)) { mac[0 ] =0x00 ; mac[1 ] =0xe0 ; mac[2 ] =0x4c ;
Signature · 1 line
2.33.0
PATCH 5/8 staging: r8188eu: use random default mac address
In reply to Michael StraubeUse a random default mac address instead of a fixed one to reduce the likelihood of mac address collision.
--- drivers/staging/r8188eu/core/rtw_ieee80211.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +2 -9
@@ -1033,15 +1033,8 @@ void rtw_macaddr_cfg(u8 *mac_addr) }if (is_broadcast_ether_addr (mac) ||is_zero_ether_addr (mac)) { - mac[0 ] =0x00 ; - mac[1 ] =0xe0 ; - mac[2 ] =0x4c ; - mac[3 ] =0x87 ; - mac[4 ] =0x00 ; - mac[5 ] =0x00 ; -/* use default mac addresss */ -memcpy (mac_addr, mac,ETH_ALEN ); -DBG_88E ("MAC Address from efuse error, assign default one !!!\n" ); +eth_random_addr (mac_addr); +DBG_88E ("MAC Address from efuse error, assign random one !!!\n" ); }DBG_88E ("rtw_macaddr_cfg MAC Address = %pM\n" , (mac_addr));
Signature · 1 line
2.33.0
PATCH 6/8 staging: r8188eu: use ether_addr_copy() in rtw_macaddr_cfg()
In reply to Michael StraubeUse ether_addr_copy() in rtw_macaddr_cfg() to copy the mac address. The buffers are properly aligned.
--- drivers/staging/r8188eu/core/rtw_ieee80211.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +2 -2
@@ -1026,10 +1026,10 @@ void rtw_macaddr_cfg(u8 *mac_addr)if (rtw_initmac &&mac_pton (rtw_initmac, mac)) {/* Users specify the mac address */ -memcpy (mac_addr, mac,ETH_ALEN ); +ether_addr_copy (mac_addr, mac); }else {/* Use the mac address stored in the Efuse */ -memcpy (mac, mac_addr,ETH_ALEN ); +ether_addr_copy (mac, mac_addr); }if (is_broadcast_ether_addr (mac) ||is_zero_ether_addr (mac)) {
Signature · 1 line
2.33.0
PATCH 7/8 staging: r8188eu: add missing blank line after declarations
In reply to Michael StraubeAdd a missing blank line after declarations in rtw_macaddr_cfg() to clear a checkpatch warning.
WARNING: Missing a blank line after declarations
--- drivers/staging/r8188eu/core/rtw_ieee80211.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -0
@@ -1021,6 +1021,7 @@ u8 key_2char2num(u8 hch, u8 lch)void rtw_macaddr_cfg (u8 *mac_addr) {u8 mac[ETH_ALEN ]; +if (!mac_addr)return ;
Signature · 1 line
2.33.0
PATCH 8/8 staging: r8188eu: remove unnecessary parentheses
In reply to Michael StraubeRemove unnecessary parentheses around a variable to improve readability.
--- drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -1
@@ -1038,7 +1038,7 @@ void rtw_macaddr_cfg(u8 *mac_addr)DBG_88E ("MAC Address from efuse error, assign random one !!!\n" ); } -DBG_88E ("rtw_macaddr_cfg MAC Address = %pM\n" , (mac_addr)); +DBG_88E ("rtw_macaddr_cfg MAC Address = %pM\n" , mac_addr); }void dump_ies (u8 *buf,u32 buf_len)
Signature · 1 line
2.33.0