[PATCH 2/2] net: of: Support adding offset to nvmem MAC addresses
From: Linus Walleij
Date: Fri Dec 20 2024 - 14:18:59 EST
If a lower-byte MAC address offset is encoded into the device
tree, make sure to add this to the returned address when
looking up a MAC address from NVMEM.
Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
---
net/core/of_net.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/net/core/of_net.c b/net/core/of_net.c
index 93ea425b9248a23f4f95a336e9cdbf0053248e32..c98000ec13377ea4b541e182a66be8b1010edc40 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -64,6 +64,7 @@ int of_get_mac_address_nvmem(struct device_node *np, u8 *addr)
struct nvmem_cell *cell;
const void *mac;
size_t len;
+ u32 offset;
int ret;
/* Try lookup by device first, there might be a nvmem_cell_lookup
@@ -72,7 +73,7 @@ int of_get_mac_address_nvmem(struct device_node *np, u8 *addr)
if (pdev) {
ret = nvmem_get_mac_address(&pdev->dev, addr);
put_device(&pdev->dev);
- return ret;
+ goto add_offset_exit;
}
cell = of_nvmem_cell_get(np, "mac-address");
@@ -92,8 +93,13 @@ int of_get_mac_address_nvmem(struct device_node *np, u8 *addr)
memcpy(addr, mac, ETH_ALEN);
kfree(mac);
+ ret = 0;
- return 0;
+add_offset_exit:
+ if (!ret && !of_property_read_u32(np, "nvmem-mac-minor-offset", &offset))
+ addr[ETH_ALEN - 1] += offset;
+
+ return ret;
}
EXPORT_SYMBOL(of_get_mac_address_nvmem);
--
2.47.1