Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: net: add a helper for loading netdev->dev_addr

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount
of VLANs...") introduced a rbtree for faster Ethernet address look
up. To maintain netdev->dev_addr in this tree we need to make all
the writes to it got through appropriate helpers.

There are roughly 40 places where netdev->dev_addr is passed
as the destination to a of_get_mac_address() call. Add a helper
which takes a dev pointer instead, so it can call an appropriate
helper.

Note that of_get_mac_address() already assumes the address is
6 bytes long (ETH_ALEN) so use eth_hw_addr_set().

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
d466effe e330fb14

+31
+6
include/linux/of_net.h
··· 14 14 struct net_device; 15 15 extern int of_get_phy_mode(struct device_node *np, phy_interface_t *interface); 16 16 extern int of_get_mac_address(struct device_node *np, u8 *mac); 17 + int of_get_ethdev_address(struct device_node *np, struct net_device *dev); 17 18 extern struct net_device *of_find_net_device_by_node(struct device_node *np); 18 19 #else 19 20 static inline int of_get_phy_mode(struct device_node *np, ··· 24 23 } 25 24 26 25 static inline int of_get_mac_address(struct device_node *np, u8 *mac) 26 + { 27 + return -ENODEV; 28 + } 29 + 30 + static inline int of_get_ethdev_address(struct device_node *np, struct net_device *dev) 27 31 { 28 32 return -ENODEV; 29 33 }
+25
net/core/of_net.c
··· 143 143 return of_get_mac_addr_nvmem(np, addr); 144 144 } 145 145 EXPORT_SYMBOL(of_get_mac_address); 146 + 147 + /** 148 + * of_get_ethdev_address() 149 + * @np: Caller's Device Node 150 + * @dev: Pointer to netdevice which address will be updated 151 + * 152 + * Search the device tree for the best MAC address to use. 153 + * If found set @dev->dev_addr to that address. 154 + * 155 + * See documentation of of_get_mac_address() for more information on how 156 + * the best address is determined. 157 + * 158 + * Return: 0 on success and errno in case of error. 159 + */ 160 + int of_get_ethdev_address(struct device_node *np, struct net_device *dev) 161 + { 162 + u8 addr[ETH_ALEN]; 163 + int ret; 164 + 165 + ret = of_get_mac_address(np, addr); 166 + if (!ret) 167 + eth_hw_addr_set(dev, addr); 168 + return ret; 169 + } 170 + EXPORT_SYMBOL(of_get_ethdev_address);