netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] net: tilegx: Use helpers from linux/etherdevice.h to check/set MAC
@ 2014-05-27 12:04 Tobias Klauser
  2014-05-28 19:43 ` Chris Metcalf
  2014-05-30  7:47 ` [PATCH v2 2/2] net: tile: " Tobias Klauser
  0 siblings, 2 replies; 5+ messages in thread
From: Tobias Klauser @ 2014-05-27 12:04 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: netdev

Use is_valid_ether_addr() to check for a valid MAC address to set on the
device.  This will also check for the device address being multicast,
which would have been possible previously.

Also use ether_addr_copy() instead of a manual memcpy() to set the
address.

Furthermore, get rid of a redundant assignment of dev->addr_len. This is
already set by ether_setup() which is called in tile_net_setup().

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 drivers/net/ethernet/tile/tilegx.c |   17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/tile/tilegx.c b/drivers/net/ethernet/tile/tilegx.c
index 0db40de..6e978f8 100644
--- a/drivers/net/ethernet/tile/tilegx.c
+++ b/drivers/net/ethernet/tile/tilegx.c
@@ -2192,7 +2192,6 @@ static void tile_net_dev_init(const char *name, const uint8_t *mac)
 {
 	int ret;
 	int i;
-	int nz_addr = 0;
 	struct net_device *dev;
 	struct tile_net_priv *priv;
 
@@ -2219,18 +2218,14 @@ static void tile_net_dev_init(const char *name, const uint8_t *mac)
 	init_ptp_dev(priv);
 
 	/* Get the MAC address and set it in the device struct; this must
-	 * be done before the device is opened.  If the MAC is all zeroes,
-	 * we use a random address, since we're probably on the simulator.
+	 * be done before the device is opened.  If the MAC is all zeroes or a
+	 * multicast address, we use a random address, since we're probably on
+	 * the simulator.
 	 */
-	for (i = 0; i < 6; i++)
-		nz_addr |= mac[i];
-
-	if (nz_addr) {
-		memcpy(dev->dev_addr, mac, ETH_ALEN);
-		dev->addr_len = 6;
-	} else {
+	if (is_valid_ether_addr(mac))
+		ether_addr_copy(dev->dev_addr, mac);
+	else
 		eth_hw_addr_random(dev);
-	}
 
 	/* Register the network device. */
 	ret = register_netdev(dev);
-- 
1.7.9.5

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

* Re: [PATCH 2/2] net: tilegx: Use helpers from linux/etherdevice.h to check/set MAC
  2014-05-27 12:04 [PATCH 2/2] net: tilegx: Use helpers from linux/etherdevice.h to check/set MAC Tobias Klauser
@ 2014-05-28 19:43 ` Chris Metcalf
  2014-05-30  7:14   ` Tobias Klauser
  2014-05-30  7:47 ` [PATCH v2 2/2] net: tile: " Tobias Klauser
  1 sibling, 1 reply; 5+ messages in thread
From: Chris Metcalf @ 2014-05-28 19:43 UTC (permalink / raw)
  To: Tobias Klauser; +Cc: netdev

On 5/27/2014 8:04 AM, Tobias Klauser wrote:
> Use is_valid_ether_addr() to check for a valid MAC address to set on the
> device.  This will also check for the device address being multicast,
> which would have been possible previously.

I don't think having a multicast address here is possible (i.e. as returned
by gxio_mpipe_link_enumerate_mac), and it confuses the actual issue, which
is handling the all-zeroes case in a simulator run.  I'd prefer to see
is_zero_ether_addr() instead.

> Also use ether_addr_copy() instead of a manual memcpy() to set the
> address.
>
> Furthermore, get rid of a redundant assignment of dev->addr_len. This is
> already set by ether_setup() which is called in tile_net_setup().
>
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---
>   drivers/net/ethernet/tile/tilegx.c |   17 ++++++-----------
>   1 file changed, 6 insertions(+), 11 deletions(-)

With the change above,

Acked-by: Chris Metcalf <cmetcalf@tilera.com>

-- 
Chris Metcalf, Tilera Corp.
http://www.tilera.com

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

* Re: [PATCH 2/2] net: tilegx: Use helpers from linux/etherdevice.h to check/set MAC
  2014-05-28 19:43 ` Chris Metcalf
@ 2014-05-30  7:14   ` Tobias Klauser
  0 siblings, 0 replies; 5+ messages in thread
From: Tobias Klauser @ 2014-05-30  7:14 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: netdev

On 2014-05-28 at 21:43:33 +0200, Chris Metcalf <cmetcalf@tilera.com> wrote:
> On 5/27/2014 8:04 AM, Tobias Klauser wrote:
> >Use is_valid_ether_addr() to check for a valid MAC address to set on the
> >device.  This will also check for the device address being multicast,
> >which would have been possible previously.
> 
> I don't think having a multicast address here is possible (i.e. as returned
> by gxio_mpipe_link_enumerate_mac), and it confuses the actual issue, which
> is handling the all-zeroes case in a simulator run.  I'd prefer to see
> is_zero_ether_addr() instead.

Ok, I'll send an updated patch which only tests for
!is_zero_ether_addr()

> >Also use ether_addr_copy() instead of a manual memcpy() to set the
> >address.
> >
> >Furthermore, get rid of a redundant assignment of dev->addr_len. This is
> >already set by ether_setup() which is called in tile_net_setup().
> >
> >Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> >---
> >  drivers/net/ethernet/tile/tilegx.c |   17 ++++++-----------
> >  1 file changed, 6 insertions(+), 11 deletions(-)
> 
> With the change above,
> 
> Acked-by: Chris Metcalf <cmetcalf@tilera.com>
> 
> -- 
> Chris Metcalf, Tilera Corp.
> http://www.tilera.com
> 

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

* [PATCH v2 2/2] net: tile: Use helpers from linux/etherdevice.h to check/set MAC
  2014-05-27 12:04 [PATCH 2/2] net: tilegx: Use helpers from linux/etherdevice.h to check/set MAC Tobias Klauser
  2014-05-28 19:43 ` Chris Metcalf
@ 2014-05-30  7:47 ` Tobias Klauser
  2014-05-31  0:06   ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Tobias Klauser @ 2014-05-30  7:47 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: netdev

Use is_zero_ether_addr() to check for the MAC address being all zeros instead of
open coding the check.

Also use ether_addr_copy() instead of a manual memcpy() to set the
netdev->dev_addr.

Furthermore, get rid of a redundant assignment of netdev->addr_len. This is
already set by ether_setup() which is called in tile_net_setup().

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Acked-by: Chris Metcalf <cmetcalf@tilera.com>

---
v2: only check for zero address

 drivers/net/ethernet/tile/tilegx.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/tile/tilegx.c b/drivers/net/ethernet/tile/tilegx.c
index 0db40de..14389f8 100644
--- a/drivers/net/ethernet/tile/tilegx.c
+++ b/drivers/net/ethernet/tile/tilegx.c
@@ -2192,7 +2192,6 @@ static void tile_net_dev_init(const char *name, const uint8_t *mac)
 {
 	int ret;
 	int i;
-	int nz_addr = 0;
 	struct net_device *dev;
 	struct tile_net_priv *priv;
 
@@ -2222,15 +2221,10 @@ static void tile_net_dev_init(const char *name, const uint8_t *mac)
 	 * be done before the device is opened.  If the MAC is all zeroes,
 	 * we use a random address, since we're probably on the simulator.
 	 */
-	for (i = 0; i < 6; i++)
-		nz_addr |= mac[i];
-
-	if (nz_addr) {
-		memcpy(dev->dev_addr, mac, ETH_ALEN);
-		dev->addr_len = 6;
-	} else {
+	if (!is_zero_ether_addr(mac))
+		ether_addr_copy(dev->dev_addr, mac);
+	else
 		eth_hw_addr_random(dev);
-	}
 
 	/* Register the network device. */
 	ret = register_netdev(dev);
-- 
1.7.9.5

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

* Re: [PATCH v2 2/2] net: tile: Use helpers from linux/etherdevice.h to check/set MAC
  2014-05-30  7:47 ` [PATCH v2 2/2] net: tile: " Tobias Klauser
@ 2014-05-31  0:06   ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2014-05-31  0:06 UTC (permalink / raw)
  To: tklauser; +Cc: cmetcalf, netdev

From: Tobias Klauser <tklauser@distanz.ch>
Date: Fri, 30 May 2014 09:47:17 +0200

> Use is_zero_ether_addr() to check for the MAC address being all zeros instead of
> open coding the check.
> 
> Also use ether_addr_copy() instead of a manual memcpy() to set the
> netdev->dev_addr.
> 
> Furthermore, get rid of a redundant assignment of netdev->addr_len. This is
> already set by ether_setup() which is called in tile_net_setup().
> 
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> Acked-by: Chris Metcalf <cmetcalf@tilera.com>

Applied.

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

end of thread, other threads:[~2014-05-31  0:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-27 12:04 [PATCH 2/2] net: tilegx: Use helpers from linux/etherdevice.h to check/set MAC Tobias Klauser
2014-05-28 19:43 ` Chris Metcalf
2014-05-30  7:14   ` Tobias Klauser
2014-05-30  7:47 ` [PATCH v2 2/2] net: tile: " Tobias Klauser
2014-05-31  0:06   ` David Miller

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