Skip to contentSkip to conversation

staging: rtl8723bs: do not use assignment in if condition

PATCH In review Michael Straube 4 participants 9 messages Jun 21, 2018 – Jun 25, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: do not use assignment in if condition

Fix checkpatch error 'do not use assignment in if condition'.

---
 drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -3
index e55895632921..87a4ced41028 100644
@@ -1181,9 +1181,8 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
 	     (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)) &&
-		    len == ETH_ALEN) {
+		addr = of_get_property(np, "local-mac-address", &len);
+		if (np && addr && len == ETH_ALEN) {
 			memcpy(mac_addr, addr, ETH_ALEN);
 		} else {
 			mac[0] = 0x00;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 12 lines · Michael Straube

Fix checkpatch error 'do not use assignment in if condition'.

---
 drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0 -0
index e55895632921..87a4ced41028 100644

drivers/staging/rtl8723bs/core/rtw_ieee80211.c void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1185

Quoted 8 lines
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -3
@@ -1181,9 +1181,8 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
 	     (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)) &&
-		    len == ETH_ALEN) {
+		addr = of_get_property(np, "local-mac-address", &len);
+		if (np && addr && len == ETH_ALEN) {

You can remove the "np" check.

		if (addr && len == ETH_ALEN) {

regards,
dan carpenter

#2 lore raw
Quoted 2 lines · Dan Carpenter
Quoted 1 line · Michael Straube

Fix checkpatch error 'do not use assignment in if condition'.

[]

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1183

Quoted 8 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0 -0
index e55895632921..87a4ced41028 100644
@@ -1181,9 +1181,8 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
 	     (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))) {

Should also use is_broadcast_ether_addr and is_zero_ether_addr

Quoted 9 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1185

Quoted 5 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -3
-		if (np &&
-		    (addr = of_get_property(np, "local-mac-address", &len)) &&
-		    len == ETH_ALEN) {
+		addr = of_get_property(np, "local-mac-address", &len);
+		if (np && addr && len == ETH_ALEN) {

You can remove the "np" check.

		if (addr && len == ETH_ALEN) {

It looks more like the rewrite is incorrect
as np is tested before of_get_property

It could be written something like:

	if (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) {
		bool assigned = false;

		if (np) {
			addr = of_get_property(np, "local-mac-address", &len);
			if (len == ETH_ALEN) {
				memcpy(mac_addr, addr, ETH_ALEN);
				assigned = true;
			}
		}
		if (!assigned) {
			mac_addr[0] = 0x00;
			mac_addr[1] = ...
		}
	}
#3 lore raw
Quoted 23 lines · Joe Perches
Quoted 2 lines · Dan Carpenter
Quoted 1 line · Michael Straube

Fix checkpatch error 'do not use assignment in if condition'.

[]

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1183

Quoted 8 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0 -0
index e55895632921..87a4ced41028 100644
@@ -1181,9 +1181,8 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
 	     (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))) {

Should also use is_broadcast_ether_addr and is_zero_ether_addr

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1185

Quoted 5 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -3
-		if (np &&
-		    (addr = of_get_property(np, "local-mac-address", &len)) &&
-		    len == ETH_ALEN) {
+		addr = of_get_property(np, "local-mac-address", &len);
+		if (np && addr && len == ETH_ALEN) {

You can remove the "np" check.

Quoted 5 lines
Quoted 1 line
		if (addr && len == ETH_ALEN) {

It looks more like the rewrite is incorrect
as np is tested before of_get_property

That's what I was worried about too, but if "np" is NULL then of_get_property() just returns NULL so it's fine.

regards,
dan carpenter

regards,
dan carpenter

#4 lore raw
Quoted 24 lines · Dan Carpenter
Quoted 23 lines · Joe Perches
Quoted 2 lines · Dan Carpenter
Quoted 1 line · Michael Straube

Fix checkpatch error 'do not use assignment in if condition'.

[]

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1183

Quoted 8 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0 -0
index e55895632921..87a4ced41028 100644
@@ -1181,9 +1181,8 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
  	     (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))) {

Should also use is_broadcast_ether_addr and is_zero_ether_addr

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1185

Quoted 5 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -3
-		if (np &&
-		    (addr = of_get_property(np, "local-mac-address", &len)) &&
-		    len == ETH_ALEN) {
+		addr = of_get_property(np, "local-mac-address", &len);
+		if (np && addr && len == ETH_ALEN) {

You can remove the "np" check.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
		if (addr && len == ETH_ALEN) {

It looks more like the rewrite is incorrect
as np is tested before of_get_property

That's what I was worried about too, but if "np" is NULL then of_get_property() just returns NULL so it's fine.

So it should be this?

        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)) &&
            (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac))) {
                addr = of_get_property(np, "local-mac-address", &len);
                if (addr && len == ETH_ALEN) {
                        memcpy(mac_addr, addr, ETH_ALEN);
                } else {
                        mac[0] = 0x00;
                        ...
		}
	}

If yes, I'm not sure how to proceed as these are the very first patches I send. Should I send a v2 patch with both changes or just a v2 with "np" removed and another one for adding 'is_broadcast_ether_addr' and 'is_zero_ether_addr' checks?

Regards,
Michael

#5 lore raw
Quoted 34 lines · Michael Straube
Quoted 24 lines · Dan Carpenter
Quoted 23 lines · Joe Perches
Quoted 2 lines · Dan Carpenter
Quoted 1 line · Michael Straube

Fix checkpatch error 'do not use assignment in if condition'.

[]

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1183

Quoted 8 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0 -0
index e55895632921..87a4ced41028 100644
@@ -1181,9 +1181,8 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
  	     (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))) {

Should also use is_broadcast_ether_addr and is_zero_ether_addr

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1185

Quoted 5 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -3
-		if (np &&
-		    (addr = of_get_property(np, "local-mac-address", &len)) &&
-		    len == ETH_ALEN) {
+		addr = of_get_property(np, "local-mac-address", &len);
+		if (np && addr && len == ETH_ALEN) {

You can remove the "np" check.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
		if (addr && len == ETH_ALEN) {

It looks more like the rewrite is incorrect
as np is tested before of_get_property

That's what I was worried about too, but if "np" is NULL then of_get_property() just returns NULL so it's fine.

Quoted 7 lines

So it should be this?

         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)) &&
             (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac))) {

No as the mac[] tests are the same as is_<foo>_ether_addr and there's nothing really objectionable about embedding the assignment in the if here.

Output from checkpatch is not gospel and can be ignored whenever appropriate.

I think the below is ok:

	if ((is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) &&
	    ((addr = of_get_property(np, "local-mac-address", &len)) &&
	     len == ETH_ALEN))
		memcpy(mac_addr, addr, ETH_ALEN);
	else
		memcpy(mac_addr, ""\x00\xe0\x4c\x87\x00\x00", ETH_ALEN);

Although the last memcpy of a fixed mac address could probably use eth_random_addr to reduce the likelihood of mac address collision so maybe

	if ((is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) &&
	    ((addr = of_get_property(np, "local-mac-address", &len)) &&
	
     len == ETH_ALEN))
		memcpy(mac_addr, addr, ETH_ALEN);
	else
		eth_random_addr(mac_addr);
Quoted 3 lines

If yes, I'm not sure how to proceed as these are the very first patches I send. Should I send a v2 patch with both changes or just a v2 with "np" removed and another one for adding 'is_broadcast_ether_addr' and 'is_zero_ether_addr' checks?

I'd send 1 patch.

#6 lore raw
Quoted 37 lines · Joe Perches
Quoted 36 lines · Michael Straube
Quoted 24 lines · Dan Carpenter
Quoted 23 lines · Joe Perches
Quoted 2 lines · Dan Carpenter
Quoted 1 line · Michael Straube

Fix checkpatch error 'do not use assignment in if condition'.

[]

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1183

Quoted 8 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0 -0
index e55895632921..87a4ced41028 100644
@@ -1181,9 +1181,8 @@ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
   	     (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))) {

Should also use is_broadcast_ether_addr and is_zero_ether_addr

Quoted 8 lines

b/ void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) · line 1185

Quoted 5 lines
b/ renamed from drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -3
-		if (np &&
-		    (addr = of_get_property(np, "local-mac-address", &len)) &&
-		    len == ETH_ALEN) {
+		addr = of_get_property(np, "local-mac-address", &len);
+		if (np && addr && len == ETH_ALEN) {

You can remove the "np" check.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
		if (addr && len == ETH_ALEN) {

It looks more like the rewrite is incorrect
as np is tested before of_get_property

That's what I was worried about too, but if "np" is NULL then of_get_property() just returns NULL so it's fine.

So it should be this?

Quoted 7 lines
Quoted 5 lines
          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)) &&
              (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac))) {

No as the mac[] tests are the same as is_<foo>_ether_addr

Ok, I understand now.

Quoted 5 lines

and there's nothing really objectionable about embedding the assignment in the if here.

Output from checkpatch is not gospel and can be ignored whenever appropriate.

Ok, good to know.

Quoted 7 lines
		memcpy(mac_addr, ""\x00\xe0\x4c\x87\x00\x00", ETH_ALEN);

Although the last memcpy of a fixed mac address could probably use eth_random_addr to reduce the likelihood of mac address collision so maybe

		eth_random_addr(mac_addr);

Using a random address would be preffered?

Thanks for your help and patience.
Michael

#7 lore raw
Quoted 6 lines · Michael Straube
Quoted 4 lines · Joe Perches

Although the last memcpy of a fixed mac address could probably use eth_random_addr to reduce the likelihood of mac address collision so maybe

		eth_random_addr(mac_addr);

Using a random address would be preffered?

mac address duplication is bad, so if there
were 2 instances of this device on the same
ethernet network, yes.

Quoted 3 lines

Thanks for your help and patience.
Michael

#8 lore raw
In reply to Joe Perches
Quoted 15 lines · Joe Perches
Quoted 1 line · Michael Straube

On 06/22/18 12:57, Dan Carpenter wrote:

Output from checkpatch is not gospel and can be ignored whenever appropriate.

I think the below is ok:

        if ((is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) &&
            ((addr = of_get_property(np, "local-mac-address", &len)) &&
             len == ETH_ALEN))
                memcpy(mac_addr, addr, ETH_ALEN);
        else
                memcpy(mac_addr, ""\x00\xe0\x4c\x87\x00\x00", ETH_ALEN);
Quoted 3 lines

Although the last memcpy of a fixed mac address could probably use eth_random_addr to reduce the likelihood of mac address collision

...and first one looks like ether_addr_copy().

Quoted 13 lines

so maybe

        if ((is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) &&
            ((addr = of_get_property(np, "local-mac-address", &len)) &&

     len == ETH_ALEN))
                memcpy(mac_addr, addr, ETH_ALEN);
        else
                eth_random_addr(mac_addr);
Quoted 3 lines

If yes, I'm not sure how to proceed as these are the very first patches I send. Should I send a v2 patch with both changes or just a v2 with "np" removed and another one for adding 'is_broadcast_ether_addr' and 'is_zero_ether_addr' checks?

Signature · 2 lines
With Best Regards,
Andy Shevchenko