[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1452121966.24575.52.camel@perches.com>
Date: Wed, 06 Jan 2016 15:12:46 -0800
From: Joe Perches <joe@...ches.com>
To: David Miller <davem@...emloft.net>, netdev@...r.kernel.org
Cc: sowmini.varadhan@...cle.com
Subject: Re: [PATCH v2] net: Add eth_platform_get_mac_address() helper.
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.
[]
> diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
[]
> @@ -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 ?
> +}
> +
> +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?
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists