staging: rtl8723bs: fix comparsion to NULL - coding style
PATCH v2 1/4 staging: rtl8723bs: fix comparsion to NULL - coding style
Fix comparsion to NULL issues found by checkpatch. Use !x instead of x == NULL.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -2
@@ -747,7 +747,7 @@ u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)u8 match = false;u8 eid, wps_oui[4 ] = {0x0 ,0x50 ,0xf2 ,0x04 }; -if (ie_ptr ==NULL ) +if (!ie_ptr)return match; eid = ie_ptr[0 ];
@@ -1163,7 +1163,7 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)const unsigned char *addr;int len; -if (mac_addr ==NULL ) +if (!mac_addr)return ;if (rtw_initmac) {/* Users specify the mac address */
Signature · 1 line
2.18.0
PATCH v2 2/4 staging: rtl8723bs: refactor rtw_macaddr_cfg()
Using is_broadcast_ether_addr() and is_zero_ether_addr() instead of testing each byte of the mac[] array for 0xff and 0x00 shortens the code and improves readability.
If np == NULL, of_get_property() returns NULL, hence the "np" check is not needed.
Instead of a fixed default mac address use a random one to reduce the likelihood of mac address collision.
Thanks to Joe Perches and Dan Carpenter.
--- .../staging/rtl8723bs/core/rtw_ieee80211.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +4 -15
@@ -1177,24 +1177,13 @@ void rtw_macaddr_cfg(struct device *dev, 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 ] ==0x00 ) && (mac[1 ] ==0x00 ) && (mac[2 ] ==0x00 ) && - (mac[3 ] ==0x00 ) && (mac[4 ] ==0x00 ) && (mac[5 ] ==0x00 ))) { -if (np && - (addr =of_get_property (np,"local-mac-address" , &len)) && +if (is_broadcast_ether_addr (mac) ||is_zero_ether_addr (mac)) { +if ((addr =of_get_property (np,"local-mac-address" , &len)) && len ==ETH_ALEN ) {memcpy (mac_addr, addr,ETH_ALEN ); }else { - 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_871X ("MAC Address from efuse error, assign default one !!!\n" ); +eth_random_addr (mac_addr); +DBG_871X ("MAC Address from efuse error, assign random one !!!\n" ); } }
Signature · 1 line
2.18.0
PATCH v2 3/4 staging: rtl8723bs: use ether_addr_copy() in rtw_macaddr_cfg()
In reply to Michael StraubeUse ether_addr_copy() instead of memcpy() to copy the mac address.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +3 -3
@@ -1172,15 +1172,15 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)for (jj =0 , kk =0 ; jj <ETH_ALEN ; jj++, kk +=3 ) { mac[jj] =key_2char2num (rtw_initmac[kk], rtw_initmac[kk +1 ]); } -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)) {if ((addr =of_get_property (np,"local-mac-address" , &len)) && len ==ETH_ALEN ) { -memcpy (mac_addr, addr,ETH_ALEN ); +ether_addr_copy (mac_addr, addr); }else {eth_random_addr (mac_addr);DBG_871X ("MAC Address from efuse error, assign random one !!!\n" );
Signature · 1 line
2.18.0
PATCH v2 4/4 staging: rtl8723bs: use mac_pton() in rtw_macaddr_cfg()
In reply to Michael StraubeUse the mac_pton() helper to convert the mac address string.
The functions key_char2num() and key_2char2num() are not used anywhere else and can be removed.
This also has the benefit of validating the input since mac_pton() returns false if the string is not valid.
--- .../staging/rtl8723bs/core/rtw_ieee80211.c | 30 +++---------------- .../staging/rtl8723bs/os_dep/ioctl_linux.c | 3 -- 2 files changed, 4 insertions(+), 29 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +4 -26
@@ -1137,25 +1137,6 @@ ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len, } -static u8 key_char2num (u8 ch); -static u8 key_char2num (u8 ch) -{ -if ((ch >='0' ) && (ch <='9' )) -return ch -'0' ; -else if ((ch >='a' ) && (ch <='f' )) -return ch -'a' +10 ; -else if ((ch >='A' ) && (ch <='F' )) -return ch -'A' +10 ; -else -return 0xff ; -} - -u8 key_2char2num (u8 hch,u8 lch); -u8 key_2char2num (u8 hch,u8 lch) -{ -return ((key_char2num (hch) <<4 ) |key_char2num (lch)); -} -void rtw_macaddr_cfg (struct device *dev,u8 *mac_addr) {u8 mac[ETH_ALEN ];
@@ -1166,14 +1147,11 @@ void rtw_macaddr_cfg(struct device *dev, 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 */ ether_addr_copy (mac_addr, mac); - }else {/* Use the mac address stored in the Efuse */ + }else { +/* Use the mac address stored in the Efuse */ ether_addr_copy (mac, mac_addr); }
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +0 -3
@@ -32,9 +32,6 @@#define WEXT_CSCAN_HOME_DWELL_SECTION 'H'#define WEXT_CSCAN_TYPE_SECTION 'T' - -extern u8 key_2char2num (u8 hch,u8 lch); -static u32 rtw_rates[] = {1000000 ,2000000 ,5500000 ,11000000 ,6000000 ,9000000 ,12000000 ,18000000 ,24000000 ,36000000 ,48000000 ,54000000 };
Signature · 1 line
2.18.0
Re: [PATCH v2 4/4] staging: rtl8723bs: use mac_pton() in rtw_macaddr_cfg()
drivers/staging/rtl8723bs/core/rtw_ieee80211.c void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1156
Quoted 4 lines · Michael Straube
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2
-0+ }else { +/* Use the mac address stored in the Efuse */ ether_addr_copy (mac, mac_addr); }
} else {
I'll resend the series with this corrected.
Regards,
Michael