* [PATCH v2 1/8] staging: r8188eu: use mac_pton() in rtw_macaddr_cfg()
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
2021-08-30 12:15 ` [PATCH v2 2/8] staging: r8188eu: ensure mac address buffer is properly aligned Michael Straube
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Instead of a custom approach use mac_pton() to convert the mac
address string. With mac_pton() the driver also validates the
input now.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_ieee80211.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
index b3a74198596a..205798b76cf9 100644
--- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
@@ -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);
}
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/8] staging: r8188eu: ensure mac address buffer is properly aligned
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
2021-08-30 12:15 ` [PATCH v2 1/8] staging: r8188eu: use mac_pton() in rtw_macaddr_cfg() Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
2021-08-30 12:15 ` [PATCH v2 3/8] staging: r8188eu: use ETH_ALEN Michael Straube
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Ensure the mac address buffer in struct eeprom_priv is properly
aligned for use with functions from <linux/etherdevice.h>.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/include/rtw_eeprom.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/r8188eu/include/rtw_eeprom.h b/drivers/staging/r8188eu/include/rtw_eeprom.h
index 9f8a9c070339..fb591a764dac 100644
--- a/drivers/staging/r8188eu/include/rtw_eeprom.h
+++ b/drivers/staging/r8188eu/include/rtw_eeprom.h
@@ -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);
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/8] staging: r8188eu: use ETH_ALEN
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
2021-08-30 12:15 ` [PATCH v2 1/8] staging: r8188eu: use mac_pton() in rtw_macaddr_cfg() Michael Straube
2021-08-30 12:15 ` [PATCH v2 2/8] staging: r8188eu: ensure mac address buffer is properly aligned Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
2021-08-30 12:15 ` [PATCH v2 4/8] staging: r8188eu: use is_*_ether_addr() in rtw_macaddr_cfg() Michael Straube
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Use ETH_ALEN instead of hard-coding the value for the mac_addr buffer
in struct eeprom_priv.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/include/rtw_eeprom.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/r8188eu/include/rtw_eeprom.h b/drivers/staging/r8188eu/include/rtw_eeprom.h
index fb591a764dac..d0c812cf5cc2 100644
--- a/drivers/staging/r8188eu/include/rtw_eeprom.h
+++ b/drivers/staging/r8188eu/include/rtw_eeprom.h
@@ -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);
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/8] staging: r8188eu: use is_*_ether_addr() in rtw_macaddr_cfg()
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
` (2 preceding siblings ...)
2021-08-30 12:15 ` [PATCH v2 3/8] staging: r8188eu: use ETH_ALEN Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
2021-08-30 12:15 ` [PATCH v2 5/8] staging: r8188eu: use random default mac address Michael Straube
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Use is_broadcast_ether_addr() and is_zero_ether_addr() in
rtw_macaddr_cfg(). The buffer is properly aligned.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_ieee80211.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
index 205798b76cf9..35a548e1c92e 100644
--- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
@@ -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;
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/8] staging: r8188eu: use random default mac address
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
` (3 preceding siblings ...)
2021-08-30 12:15 ` [PATCH v2 4/8] staging: r8188eu: use is_*_ether_addr() in rtw_macaddr_cfg() Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
2021-08-30 12:15 ` [PATCH v2 6/8] staging: r8188eu: use ether_addr_copy() in rtw_macaddr_cfg() Michael Straube
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Use a random default mac address instead of a fixed one to reduce the
likelihood of mac address collision.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_ieee80211.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
index 35a548e1c92e..370a710ab7cb 100644
--- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
@@ -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));
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/8] staging: r8188eu: use ether_addr_copy() in rtw_macaddr_cfg()
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
` (4 preceding siblings ...)
2021-08-30 12:15 ` [PATCH v2 5/8] staging: r8188eu: use random default mac address Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
2021-08-30 12:15 ` [PATCH v2 7/8] staging: r8188eu: add missing blank line after declarations Michael Straube
2021-08-30 12:15 ` [PATCH v2 8/8] staging: r8188eu: remove unnecessary parentheses Michael Straube
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Use ether_addr_copy() in rtw_macaddr_cfg() to copy the mac address.
The buffers are properly aligned.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_ieee80211.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
index 370a710ab7cb..c37358be631f 100644
--- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
@@ -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)) {
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 7/8] staging: r8188eu: add missing blank line after declarations
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
` (5 preceding siblings ...)
2021-08-30 12:15 ` [PATCH v2 6/8] staging: r8188eu: use ether_addr_copy() in rtw_macaddr_cfg() Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
2021-08-30 12:15 ` [PATCH v2 8/8] staging: r8188eu: remove unnecessary parentheses Michael Straube
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Add a missing blank line after declarations in rtw_macaddr_cfg()
to clear a checkpatch warning.
WARNING: Missing a blank line after declarations
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_ieee80211.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
index c37358be631f..f76c762ccd4b 100644
--- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
@@ -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;
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 8/8] staging: r8188eu: remove unnecessary parentheses
2021-08-30 12:15 [PATCH v2 0/8] staging: r8188eu: refactor rtw_macaddr_cfg() Michael Straube
` (6 preceding siblings ...)
2021-08-30 12:15 ` [PATCH v2 7/8] staging: r8188eu: add missing blank line after declarations Michael Straube
@ 2021-08-30 12:15 ` Michael Straube
7 siblings, 0 replies; 9+ messages in thread
From: Michael Straube @ 2021-08-30 12:15 UTC (permalink / raw)
To: gregkh
Cc: Larry.Finger, phil, martin, fmdefrancesco, linux-staging,
linux-kernel, Michael Straube
Remove unnecessary parentheses around a variable to improve
readability.
Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
index f76c762ccd4b..952ad3eec5bc 100644
--- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
@@ -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)
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread