* [PATCH] staging: rtl8723bs: refactor rtw_macaddr_cfg()
@ 2018-06-23 9:45 Michael Straube
2018-06-25 9:51 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Michael Straube @ 2018-06-23 9:45 UTC (permalink / raw)
To: gregkh; +Cc: devel, linux-kernel, joe, dan.carpenter, Michael Straube
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.
Signed-off-by: Michael Straube <michael.straube@posteo.de>
---
.../staging/rtl8723bs/core/rtw_ieee80211.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
index 0822e440204e..584695df0a48 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
@@ -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");
}
}
--
2.18.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] staging: rtl8723bs: refactor rtw_macaddr_cfg()
2018-06-23 9:45 [PATCH] staging: rtl8723bs: refactor rtw_macaddr_cfg() Michael Straube
@ 2018-06-25 9:51 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2018-06-25 9:51 UTC (permalink / raw)
To: Michael Straube
Cc: Greg Kroah-Hartman, devel, Linux Kernel Mailing List,
Joe Perches, Dan Carpenter
On Sat, Jun 23, 2018 at 12:45 PM, Michael Straube
<michael.straube@posteo.de> wrote:
> 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.
> + if ((addr = of_get_property(np, "local-mac-address", &len)) &&
> len == ETH_ALEN) {
> memcpy(mac_addr, addr, ETH_ALEN);
ether_addr_copy()?
> } else {
> + eth_random_addr(mac_addr);
> + DBG_871X("MAC Address from efuse error, assign random one !!!\n");
> }
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-25 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-23 9:45 [PATCH] staging: rtl8723bs: refactor rtw_macaddr_cfg() Michael Straube
2018-06-25 9:51 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®