From: Stefan Wahren Date: Fri, 12 Sep 2025 14:03:32 +0000 (+0200) Subject: ethernet: Extend device_get_mac_address() to use NVMEM X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d2d3f529e7b6ff2aa432b16a2317126621c28058;p=users%2Fhch%2Fmisc.git ethernet: Extend device_get_mac_address() to use NVMEM A lot of modern SoC have the ability to store MAC addresses in their NVMEM. So extend the generic function device_get_mac_address() to obtain the MAC address from an nvmem cell named 'mac-address' in case there is no firmware node which contains the MAC address directly. Signed-off-by: Stefan Wahren Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20250912140332.35395-3-wahrenst@gmx.net Signed-off-by: Jakub Kicinski --- diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 4e3651101b86..43e211e611b1 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -613,7 +613,10 @@ EXPORT_SYMBOL(fwnode_get_mac_address); */ int device_get_mac_address(struct device *dev, char *addr) { - return fwnode_get_mac_address(dev_fwnode(dev), addr); + if (!fwnode_get_mac_address(dev_fwnode(dev), addr)) + return 0; + + return nvmem_get_mac_address(dev, addr); } EXPORT_SYMBOL(device_get_mac_address);