Skip to contentSkip to conversation

ozwpan: fix memcmp() test in oz_set_active_pd()

PATCH In review Tomas Winkler 4 participants 6 messages Aug 19, 2012 – Sep 4, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ozwpan: fix memcmp() test in oz_set_active_pd()

"addr" is a pointer so it's either 4 or 8 bytes, but actually we want to compare 6 bytes (ETH_ALEN).

As network stack already provides helper function is_zero_ether_addr() we use that instead of memcmp

Cc Dan Carpenter <[email protected]>
Cc Rupesh Gujare <[email protected]>

---
V1: by Dan Carpenter <[email protected]>
V2: replace memcmp with is_zero_ether_addr
V3: include <linux/etherdevice.h>

 drivers/staging/ozwpan/ozcdev.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/staging/ozwpan/ozcdev.c +2 -1
index d983219..758ce0a 100644
@@ -8,6 +8,7 @@
 #include <linux/cdev.h>
 #include <linux/uaccess.h>
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include "ozconfig.h"
@@ -213,7 +214,7 @@ static int oz_set_active_pd(u8 *addr)
 		if (old_pd)
 			oz_pd_put(old_pd);
 	} else {
-		if (!memcmp(addr, "\0\0\0\0\0\0", sizeof(addr))) {
+		if (is_zero_ether_addr(addr)) {
 			spin_lock_bh(&g_cdev.lock);
 			pd = g_cdev.active_pd;
 			g_cdev.active_pd = 0;
Signature · 1 line
1.7.4.4
#1 lore raw

There seems also to be an opportunity in drivers/scsi/qla2xxx/qla_init.c:

memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))

julia

Quoted 46 lines · Tomas Winkler

"addr" is a pointer so it's either 4 or 8 bytes, but actually we want to compare 6 bytes (ETH_ALEN).

As network stack already provides helper function is_zero_ether_addr() we use that instead of memcmp

Cc Dan Carpenter <[email protected]>
Cc Rupesh Gujare <[email protected]>

---
V1: by Dan Carpenter <[email protected]>
V2: replace memcmp with is_zero_ether_addr
V3: include <linux/etherdevice.h>

drivers/staging/ozwpan/ozcdev.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
drivers/staging/ozwpan/ozcdev.c +2 -1
index d983219..758ce0a 100644
@@ -8,6 +8,7 @@
 #include <linux/cdev.h>
 #include <linux/uaccess.h>
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include "ozconfig.h"
@@ -213,7 +214,7 @@ static int oz_set_active_pd(u8 *addr)
 		if (old_pd)
 			oz_pd_put(old_pd);
 	} else {
-		if (!memcmp(addr, "\0\0\0\0\0\0", sizeof(addr))) {
+		if (is_zero_ether_addr(addr)) {
 			spin_lock_bh(&g_cdev.lock);
 			pd = g_cdev.active_pd;
 			g_cdev.active_pd = 0;
Signature · 6 lines
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to Tomas Winkler
Quoted 4 lines

There seems also to be an opportunity in drivers/scsi/qla2xxx/qla_init.c:

memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))

If you plan do semantic patch then there are also examples of:

./drivers/staging/rtl8712/rtl871x_recv.c:
if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) |

similarly
is_broadcast_ether_addr() to replace memcmp with 6 off 0xFF

and endless number of memcmp that can be replaced with ether_addr_equal()

Thanks
Tomas

Quoted 50 lines

julia

Quoted 46 lines · Tomas Winkler

"addr" is a pointer so it's either 4 or 8 bytes, but actually we want to compare 6 bytes (ETH_ALEN).

As network stack already provides helper function is_zero_ether_addr() we use that instead of memcmp

Cc Dan Carpenter <[email protected]>
Cc Rupesh Gujare <[email protected]>

---
V1: by Dan Carpenter <[email protected]>
V2: replace memcmp with is_zero_ether_addr
V3: include <linux/etherdevice.h>

drivers/staging/ozwpan/ozcdev.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/ozwpan/ozcdev.c index d983219..758ce0a 100644

drivers/staging/ozwpan/ozcdev.c +2 -2
@@ -8,6 +8,7 @@
 #include <linux/cdev.h>
 #include <linux/uaccess.h>
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include "ozconfig.h"
@@ -213,7 +214,7 @@ static int oz_set_active_pd(u8 *addr)
 		if (old_pd)
 			oz_pd_put(old_pd);
 	} else {
-		if (!memcmp(addr, "\0\0\0\0\0\0", sizeof(addr))) {
+		if (is_zero_ether_addr(addr)) {
 			spin_lock_bh(&g_cdev.lock);
 			pd = g_cdev.active_pd;
 			g_cdev.active_pd = 0;
--

1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Tomas Winkler
Quoted 7 lines · Tomas
Quoted 4 lines

There seems also to be an opportunity in drivers/scsi/qla2xxx/qla_init.c:

memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))

If you plan do semantic patch then there are also examples of:

Quoted 8 lines

./drivers/staging/rtl8712/rtl871x_recv.c:
if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) |

similarly
is_broadcast_ether_addr() to replace memcmp with 6 off 0xFF

and endless number of memcmp that can be replaced with ether_addr_equal()

OK, thanks for the suggestions. I will take a look.

julia

Acked-by on v3 1/1
#4 lore raw
In reply to Tomas Winkler

________________________________________
From: Tomas Winkler [[email protected]]
Sent: 19 August 2012 17:36
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Tomas Winkler; Dan Carpenter; Rupesh Gujare
Subject: [staging-next V3] ozwpan: fix memcmp() test in oz_set_active_pd()

"addr" is a pointer so it's either 4 or 8 bytes, but actually we want to compare 6 bytes (ETH_ALEN).

As network stack already provides helper function is_zero_ether_addr() we use that instead of memcmp

Cc Dan Carpenter <[email protected]>
Cc Rupesh Gujare <[email protected]>

---
V1: by Dan Carpenter <[email protected]>
V2: replace memcmp with is_zero_ether_addr
V3: include <linux/etherdevice.h>

--
Regards,
Rupesh Gujare

Acked-by on v3 1/1
#5 lore raw
In reply to Tomas Winkler
Quoted 6 lines · Tomas Winkler

"addr" is a pointer so it's either 4 or 8 bytes, but actually we want to compare 6 bytes (ETH_ALEN).

As network stack already provides helper function is_zero_ether_addr() we use that instead of memcmp

Quoted 8 lines
Cc Dan Carpenter <[email protected]>
Cc Rupesh Gujare <[email protected]>

---
V1: by Dan Carpenter <[email protected]>
V2: replace memcmp with is_zero_ether_addr
V3: include <linux/etherdevice.h>

regards,
dan carpenter