Skip to contentSkip to conversation

pch_phub: re-use native MAC address parser

PATCH Superseded Andy Shevchenko 2 participants 3 messages Apr 23, 2013 – May 28, 2013 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pch_phub: re-use native MAC address parser

We have mac_pton() helper to parse MAC addresses.

---
 drivers/misc/pch_phub.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/misc/pch_phub.c +2 -6
index 931e635..8b4d4fb 100644
@@ -633,17 +633,13 @@ static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr,
 static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
 			     const char *buf, size_t count)
 {
-	u8 mac[6];
+	u8 mac[ETH_ALEN];
 	ssize_t rom_size;
 	struct pch_phub_reg *chip = dev_get_drvdata(dev);
 
-	if (count != 18)
+	if (!mac_pton(buf, mac))
 		return -EINVAL;
 
-	sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
-		(u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3],
-		(u32 *)&mac[4], (u32 *)&mac[5]);
-
 	chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
 	if (!chip->pch_phub_extrom_base_address)
 		return -ENOMEM;
Signature · 1 line
1.8.2.rc0.22.gb3600c3
#1 lore raw
Quoted 21 lines · Andy Shevchenko

We have mac_pton() helper to parse MAC addresses.

---
 drivers/misc/pch_phub.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/misc/pch_phub.c +1 -2
index 931e635..8b4d4fb 100644
@@ -633,17 +633,13 @@ static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr,
 static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
 			     const char *buf, size_t count)
 {
-	u8 mac[6];
+	u8 mac[ETH_ALEN];
 	ssize_t rom_size;
 	struct pch_phub_reg *chip = dev_get_drvdata(dev);
 
-	if (count != 18)

drivers/misc/pch_phub.c static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr, · line 645

Quoted 10 lines
drivers/misc/pch_phub.c +1 -4
+	if (!mac_pton(buf, mac))
 		return -EINVAL;
 
-	sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
-		(u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3],
-		(u32 *)&mac[4], (u32 *)&mac[5]);
-
 	chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
 	if (!chip->pch_phub_extrom_base_address)
 		return -ENOMEM;

Arnd, do you have any comment on this one?

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy