Skip to contentSkip to conversation

pch_phub: re-use native MAC address parser

PATCH RESEND In review Andy Shevchenko 3 participants 6 messages May 28, 2013 – Jun 4, 2013 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 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
maintainer
#1 lore raw
Quoted 4 lines · Andy Shevchenko

We have mac_pton() helper to parse MAC addresses.

Hmm, the patch has appeared in linux-next now, and I'm now getting randconfig build errors when CONFIG_NET is disabled, since mac_pton is undefined then. The easiest solution would be to make the entire driver "depend on NET".

Arnd

#2 lore raw
Quoted 9 lines · Arnd Bergmann
Quoted 4 lines · Andy Shevchenko

We have mac_pton() helper to parse MAC addresses.

Hmm, the patch has appeared in linux-next now, and I'm now getting randconfig build errors when CONFIG_NET is disabled, since mac_pton is undefined then.

Thanks for catching this.

Quoted 2 lines

The easiest solution would be to
make the entire driver "depend on NET".

I don't feel that is good idea. Driver is an abstraction to the ROM, it doesn't mean you can't read ROM without network framework. It seems proper solution is to move mac_pton() outside of CONFIG_NET, though I don't know how to do this easily.

--
With Best Regards,
Andy Shevchenko

maintainer
#3 lore raw
Quoted 5 lines · On Tuesday 04 June 2013 17:21:16 Andy Shevchenko wrote:
Quoted 2 lines

The easiest solution would be to
make the entire driver "depend on NET".

I don't feel that is good idea. Driver is an abstraction to the ROM, it doesn't mean you can't read ROM without network framework.

Right, makes sense.

Quoted 2 lines

It seems proper solution is to move mac_pton() outside of CONFIG_NET, though I don't know how to do this easily.

If we want to use it outside of CONFIG_NET, it cannot be part of net/core/*.c. Maybe we can move the function to lib/mac_pton.c instead and create a Kconfig symbol that gets selected by CONFIG_NET and by any driver lib PCH_PHUB that needs it.

Arnd

#4 lore raw
Quoted 10 lines · Arnd Bergmann
Quoted 5 lines · On Tuesday 04 June 2013 17:21:16 Andy Shevchenko wrote:
Quoted 2 lines

The easiest solution would be to
make the entire driver "depend on NET".

I don't feel that is good idea. Driver is an abstraction to the ROM, it doesn't mean you can't read ROM without network framework.

Right, makes sense.

Quoted 7 lines
Quoted 2 lines

It seems proper solution is to move mac_pton() outside of CONFIG_NET, though I don't know how to do this easily.

If we want to use it outside of CONFIG_NET, it cannot be part of net/core/*.c. Maybe we can move the function to lib/mac_pton.c instead and create a Kconfig symbol that gets selected by CONFIG_NET and by any driver lib PCH_PHUB that needs it.

Sounds like a solution. Would you like me to implement this?

--
With Best Regards,
Andy Shevchenko

maintainer
#5 lore raw
Quoted 6 lines · On Tuesday 04 June 2013 17:57:38 Andy Shevchenko wrote:
Quoted 5 lines · Arnd Bergmann
Quoted 2 lines · On Tuesday 04 June 2013 17:21:16 Andy Shevchenko wrote:

It seems proper solution is to move mac_pton() outside of CONFIG_NET, though I don't know how to do this easily.

Quoted 6 lines
Quoted 4 lines

If we want to use it outside of CONFIG_NET, it cannot be part of net/core/*.c. Maybe we can move the function to lib/mac_pton.c instead and create a Kconfig symbol that gets selected by CONFIG_NET and by any driver lib PCH_PHUB that needs it.

Sounds like a solution. Would you like me to implement this?

Yes, that would be good.

Thanks,

Arnd