From: Stefan Wahren wahrenst@gmx.net
[ Upstream commit d2d3f529e7b6ff2aa432b16a2317126621c28058 ]
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 wahrenst@gmx.net Reviewed-by: Andrew Lunn andrew@lunn.ch Link: https://patch.msgid.link/20250912140332.35395-3-wahrenst@gmx.net Signed-off-by: Jakub Kicinski kuba@kernel.org Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
- The change in `net/ethernet/eth.c:614-620` extends `device_get_mac_address()` so that, after the usual firmware-node lookups fail, it falls back to `nvmem_get_mac_address()`; this reuses the existing helper that already validates length and format of the value read from an NVMEM cell. - Several drivers rely on `device_get_ethdev_address()` / `device_get_mac_address()` to supply a non-random hardware address (e.g. `drivers/net/ethernet/adi/adin1110.c:1587`, `drivers/net/ethernet/microchip/lan966x/lan966x_main.c:1096`, `drivers/net/ethernet/socionext/netsec.c:2053`). On platforms where the MAC is only exposed through an `nvmem` cell, these probes currently fail (adin1110 returns the error outright) or fall back to random addresses, so the bug is user-visible. - The fix is tightly scoped to a single fallback call, keeps the preferred firmware-node path unchanged, and relies on an established helper that already handles `-EPROBE_DEFER`, `-EOPNOTSUPP`, etc., so regression risk is low; existing callers that ignore the return code continue to see a non-zero error as before. - No new APIs or architectural shifts are introduced, and the behaviour now mirrors what the OF-specific helper has provided for years, making this an appropriate and low-risk candidate for stable backporting.
net/ethernet/eth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 4e3651101b866..43e211e611b16 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);