Re: [PATCH v2] net: Add eth_platform_get_mac_address() helper.
flat view
From: Joe Perches <joe@perches.com>
Date: 2016-01-06 23:12:49
On Wed, 2016-01-06 at 16:33 -0500, David Miller wrote:
A repeating pattern in drivers has become to use OF node information and, if not found, platform specific host information to extract the ethernet address for a given device.
[]
quoted hunk ↗ jump to hunk
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
[]
quoted hunk ↗ jump to hunk
@@ -485,3 +487,32 @@ static int __init eth_offload_init(void)} fs_initcall(eth_offload_init); + +unsigned char * __weak arch_get_platform_mac_address(void) +{ + return NULL;
WARN_ON_ONCE ?
quoted hunk ↗ jump to hunk
+} + +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) +{ + const unsigned char *addr; + struct device_node *dp; + + if (dev_is_pci(dev)) + dp = pci_device_to_OF_node(to_pci_dev(dev)); + else + dp = dev->of_node; + + addr = NULL; + if (dp) + addr = of_get_mac_address(dp); + if (!addr) + addr = arch_get_platform_mac_address(); + + if (!addr) + return -ENODEV; + + ether_addr_copy(mac_addr, addr);
Couldn't some oddball arch have an unaligned addr?