linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] staging: rtl8723bs: fix comparsion to NULL - coding style
@ 2018-06-25 15:12 Michael Straube
  2018-06-25 15:12 ` [PATCH v2 2/4] staging: rtl8723bs: refactor rtw_macaddr_cfg() Michael Straube
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Michael Straube @ 2018-06-25 15:12 UTC (permalink / raw)
  To: gregkh
  Cc: devel, linux-kernel, joe, dan.carpenter, andy.shevchenko,
	Michael Straube

Fix comparsion to NULL issues found by checkpatch.
Use !x instead of x == NULL.

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
index 0822e440204e..e55895632921 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
@@ -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 */
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/4] staging: rtl8723bs: refactor rtw_macaddr_cfg()
  2018-06-25 15:12 [PATCH v2 1/4] staging: rtl8723bs: fix comparsion to NULL - coding style Michael Straube
@ 2018-06-25 15:12 ` Michael Straube
  2018-06-25 15:12 ` [PATCH v2 3/4] staging: rtl8723bs: use ether_addr_copy() in rtw_macaddr_cfg() Michael Straube
  2018-06-25 15:12 ` [PATCH v2 4/4] staging: rtl8723bs: use mac_pton() " Michael Straube
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Straube @ 2018-06-25 15:12 UTC (permalink / raw)
  To: gregkh
  Cc: devel, linux-kernel, joe, dan.carpenter, andy.shevchenko,
	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 <straube.linux@gmail.com>
---
 .../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 e55895632921..7aa00d1391f7 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 related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/4] staging: rtl8723bs: use ether_addr_copy() in rtw_macaddr_cfg()
  2018-06-25 15:12 [PATCH v2 1/4] staging: rtl8723bs: fix comparsion to NULL - coding style Michael Straube
  2018-06-25 15:12 ` [PATCH v2 2/4] staging: rtl8723bs: refactor rtw_macaddr_cfg() Michael Straube
@ 2018-06-25 15:12 ` Michael Straube
  2018-06-25 15:12 ` [PATCH v2 4/4] staging: rtl8723bs: use mac_pton() " Michael Straube
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Straube @ 2018-06-25 15:12 UTC (permalink / raw)
  To: gregkh
  Cc: devel, linux-kernel, joe, dan.carpenter, andy.shevchenko,
	Michael Straube

Use ether_addr_copy() instead of memcpy() to copy the mac address.

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
index 7aa00d1391f7..8af4a89e632f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
@@ -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");
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 4/4] staging: rtl8723bs: use mac_pton() in rtw_macaddr_cfg()
  2018-06-25 15:12 [PATCH v2 1/4] staging: rtl8723bs: fix comparsion to NULL - coding style Michael Straube
  2018-06-25 15:12 ` [PATCH v2 2/4] staging: rtl8723bs: refactor rtw_macaddr_cfg() Michael Straube
  2018-06-25 15:12 ` [PATCH v2 3/4] staging: rtl8723bs: use ether_addr_copy() in rtw_macaddr_cfg() Michael Straube
@ 2018-06-25 15:12 ` Michael Straube
  2018-06-26  8:06   ` Michael Straube
  2 siblings, 1 reply; 5+ messages in thread
From: Michael Straube @ 2018-06-25 15:12 UTC (permalink / raw)
  To: gregkh
  Cc: devel, linux-kernel, joe, dan.carpenter, andy.shevchenko,
	Michael Straube

Use 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.

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
 .../staging/rtl8723bs/core/rtw_ieee80211.c    | 30 +++----------------
 .../staging/rtl8723bs/os_dep/ioctl_linux.c    |  3 --
 2 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
index 8af4a89e632f..62d19cfebb06 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c
@@ -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);
 	}
 
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index 39502156f652..4eb51f45b387 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -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};
 
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 4/4] staging: rtl8723bs: use mac_pton() in rtw_macaddr_cfg()
  2018-06-25 15:12 ` [PATCH v2 4/4] staging: rtl8723bs: use mac_pton() " Michael Straube
@ 2018-06-26  8:06   ` Michael Straube
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Straube @ 2018-06-26  8:06 UTC (permalink / raw)
  To: gregkh; +Cc: devel, linux-kernel, joe, dan.carpenter, andy.shevchenko

On 06/25/18 17:12, Michael Straube wrote:

> +	} 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-26  8:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-25 15:12 [PATCH v2 1/4] staging: rtl8723bs: fix comparsion to NULL - coding style Michael Straube
2018-06-25 15:12 ` [PATCH v2 2/4] staging: rtl8723bs: refactor rtw_macaddr_cfg() Michael Straube
2018-06-25 15:12 ` [PATCH v2 3/4] staging: rtl8723bs: use ether_addr_copy() in rtw_macaddr_cfg() Michael Straube
2018-06-25 15:12 ` [PATCH v2 4/4] staging: rtl8723bs: use mac_pton() " Michael Straube
2018-06-26  8:06   ` Michael Straube

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).