Skip to contentSkip to conversation

bgmac: validate MAC addr

PATCH Superseded Rafał Miłecki 3 participants 6 messages Feb 6, 2013 – Feb 8, 2013

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

PATCH 1/1 bgmac: validate MAC addr

---
 drivers/net/ethernet/broadcom/bgmac.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/broadcom/bgmac.c +5 -0
index af149a3..9f95089 100644
@@ -1290,6 +1290,11 @@ static int bgmac_probe(struct bcma_device *core)
 		return -ENOTSUPP;
 	}
 
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
+		return -EADDRNOTAVAIL;
+	}
+
 	/* Allocation and references */
 	net_dev = alloc_etherdev(sizeof(*bgmac));
 	if (!net_dev)
Signature · 1 line
1.7.10.4
#1 lore raw

Hello Rafal,

Quoted 11 lines · Rafał Miłecki
---
  drivers/net/ethernet/broadcom/bgmac.c |    5 +++++
  1 file changed, 5 insertions(+)
drivers/net/ethernet/broadcom/bgmac.c +0 -0
index af149a3..9f95089 100644

drivers/net/ethernet/broadcom/bgmac.c static int bgmac_probe(struct bcma_device *core) · line 1296

Quoted 7 lines
drivers/net/ethernet/broadcom/bgmac.c +4 -0
@@ -1290,6 +1290,11 @@ static int bgmac_probe(struct bcma_device *core)
  		return -ENOTSUPP;
  	}
 
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
+		return -EADDRNOTAVAIL;
+	}

Rather generate an random one, thus making the interface usable, but keep the warning to help users track this down. --
Florian

#2 lore raw

PATCH v2 1/1 bgmac: validate MAC addr

In reply to Rafał Miłecki

---
V2: generate random addr

---
 drivers/net/ethernet/broadcom/bgmac.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/broadcom/bgmac.c +6 -0
index d08a4af..f90d1dc 100644
@@ -1318,6 +1318,12 @@ static int bgmac_probe(struct bcma_device *core)
 		return -ENOTSUPP;
 	}
 
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
+		eth_random_addr(mac);
+		dev_warn(&core->dev, "Using random MAC: %pM\n", mac);
+	}
+
 	/* Allocation and references */
 	net_dev = alloc_etherdev(sizeof(*bgmac));
 	if (!net_dev)
Signature · 1 line
1.7.10.4
#3 lore raw
Quoted 1 line · Rafał Miłecki

This is looking good, however some commit message is desirable, especially as you are no longer just validating the ethernet MAC address, but also generating a new one. Something along those lines would probably be enough:

"This patch changes bgmac_probe() to check for a valid Ethernet MAC address and in case it is not, will generate a valid random one, such that the adapter is still usable."

Thanks!

Quoted 23 lines

---
V2: generate random addr

---
  drivers/net/ethernet/broadcom/bgmac.c |    6 ++++++
  1 file changed, 6 insertions(+)
drivers/net/ethernet/broadcom/bgmac.c +6 -0
index d08a4af..f90d1dc 100644
@@ -1318,6 +1318,12 @@ static int bgmac_probe(struct bcma_device *core)
  		return -ENOTSUPP;
  	}
 
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
+		eth_random_addr(mac);
+		dev_warn(&core->dev, "Using random MAC: %pM\n", mac);
+	}
+
  	/* Allocation and references */
  	net_dev = alloc_etherdev(sizeof(*bgmac));
  	if (!net_dev)
#4 lore raw

PATCH v3 1/1 bgmac: validate (and random if needed) MAC addr

In reply to Rafał Miłecki

This adds check for a valid Ethernet MAC address and in case it is not, it will generate a valid random one, such that the adapter is still usable.

---
V2: generate random addr
V3: update commit message

---
 drivers/net/ethernet/broadcom/bgmac.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/broadcom/bgmac.c +6 -0
index d08a4af..f90d1dc 100644
@@ -1318,6 +1318,12 @@ static int bgmac_probe(struct bcma_device *core)
 		return -ENOTSUPP;
 	}
 
+	if (!is_valid_ether_addr(mac)) {
+		dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
+		eth_random_addr(mac);
+		dev_warn(&core->dev, "Using random MAC: %pM\n", mac);
+	}
+
 	/* Allocation and references */
 	net_dev = alloc_etherdev(sizeof(*bgmac));
 	if (!net_dev)
Signature · 1 line
1.7.10.4
maintainer Applied
#5 lore raw

Re: [PATCH V3] bgmac: validate (and random if needed) MAC addr

From: Rafał Miłecki <[email protected]>
Date: Thu, 7 Feb 2013 11:27:17 +0100

Quoted 5 lines

This adds check for a valid Ethernet MAC address and in case it is not, it will generate a valid random one, such that the adapter is still usable.

Applied, thanks.