2
0

683-of_net-add-mac-address-to-of-tree.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 8585756342caa6d27008d1ad0c18023e4211a40a Mon Sep 17 00:00:00 2001
  2. From: OpenWrt community <[email protected]>
  3. Date: Wed, 13 Jul 2022 12:22:48 +0200
  4. Subject: [PATCH] of/of_net: write back netdev MAC-address to device-tree
  5. The label-mac logic relies on the mac-address property of a netdev
  6. devices of-node. However, the mac address can also be stored as a
  7. different property or read from e.g. an mtd device.
  8. Create this node when reading a mac-address from OF if it does not
  9. already exist and copy the mac-address used for the device to this
  10. property. This way, the MAC address can be accessed using procfs.
  11. ---
  12. net/core/of_net.c | 22 ++++++++++++++++++++++
  13. 1 file changed, 22 insertions(+)
  14. --- a/net/core/of_net.c
  15. +++ b/net/core/of_net.c
  16. @@ -95,6 +95,27 @@ static int of_get_mac_addr_nvmem(struct
  17. return 0;
  18. }
  19. +static int of_add_mac_address(struct device_node *np, u8* addr)
  20. +{
  21. + struct property *prop;
  22. +
  23. + prop = kzalloc(sizeof(*prop), GFP_KERNEL);
  24. + if (!prop)
  25. + return -ENOMEM;
  26. +
  27. + prop->name = "mac-address";
  28. + prop->length = ETH_ALEN;
  29. + prop->value = kmemdup(addr, ETH_ALEN, GFP_KERNEL);
  30. + if (!prop->value || of_update_property(np, prop))
  31. + goto free;
  32. +
  33. + return 0;
  34. +free:
  35. + kfree(prop->value);
  36. + kfree(prop);
  37. + return -ENOMEM;
  38. +}
  39. +
  40. /**
  41. * of_get_mac_address()
  42. * @np: Caller's Device Node
  43. @@ -130,17 +151,23 @@ int of_get_mac_address(struct device_nod
  44. ret = of_get_mac_addr(np, "mac-address", addr);
  45. if (!ret)
  46. - return 0;
  47. + goto found;
  48. ret = of_get_mac_addr(np, "local-mac-address", addr);
  49. if (!ret)
  50. - return 0;
  51. + goto found;
  52. ret = of_get_mac_addr(np, "address", addr);
  53. if (!ret)
  54. - return 0;
  55. + goto found;
  56. - return of_get_mac_addr_nvmem(np, addr);
  57. + ret = of_get_mac_addr_nvmem(np, addr);
  58. + if (ret)
  59. + return ret;
  60. +
  61. +found:
  62. + ret = of_add_mac_address(np, addr);
  63. + return ret;
  64. }
  65. EXPORT_SYMBOL(of_get_mac_address);