732-net-next-1-of-net-pass-the-dst-buffer-to-of_get_mac_address.patch 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935
  1. From 83216e3988cd196183542937c9bd58b279f946af Mon Sep 17 00:00:00 2001
  2. From: Michael Walle <[email protected]>
  3. Date: Mon, 12 Apr 2021 19:47:17 +0200
  4. Subject: of: net: pass the dst buffer to of_get_mac_address()
  5. of_get_mac_address() returns a "const void*" pointer to a MAC address.
  6. Lately, support to fetch the MAC address by an NVMEM provider was added.
  7. But this will only work with platform devices. It will not work with
  8. PCI devices (e.g. of an integrated root complex) and esp. not with DSA
  9. ports.
  10. There is an of_* variant of the nvmem binding which works without
  11. devices. The returned data of a nvmem_cell_read() has to be freed after
  12. use. On the other hand the return of_get_mac_address() points to some
  13. static data without a lifetime. The trick for now, was to allocate a
  14. device resource managed buffer which is then returned. This will only
  15. work if we have an actual device.
  16. Change it, so that the caller of of_get_mac_address() has to supply a
  17. buffer where the MAC address is written to. Unfortunately, this will
  18. touch all drivers which use the of_get_mac_address().
  19. Usually the code looks like:
  20. const char *addr;
  21. addr = of_get_mac_address(np);
  22. if (!IS_ERR(addr))
  23. ether_addr_copy(ndev->dev_addr, addr);
  24. This can then be simply rewritten as:
  25. of_get_mac_address(np, ndev->dev_addr);
  26. Sometimes is_valid_ether_addr() is used to test the MAC address.
  27. of_get_mac_address() already makes sure, it just returns a valid MAC
  28. address. Thus we can just test its return code. But we have to be
  29. careful if there are still other sources for the MAC address before the
  30. of_get_mac_address(). In this case we have to keep the
  31. is_valid_ether_addr() call.
  32. The following coccinelle patch was used to convert common cases to the
  33. new style. Afterwards, I've manually gone over the drivers and fixed the
  34. return code variable: either used a new one or if one was already
  35. available use that. Mansour Moufid, thanks for that coccinelle patch!
  36. <spml>
  37. @a@
  38. identifier x;
  39. expression y, z;
  40. @@
  41. - x = of_get_mac_address(y);
  42. + x = of_get_mac_address(y, z);
  43. <...
  44. - ether_addr_copy(z, x);
  45. ...>
  46. @@
  47. identifier a.x;
  48. @@
  49. - if (<+... x ...+>) {}
  50. @@
  51. identifier a.x;
  52. @@
  53. if (<+... x ...+>) {
  54. ...
  55. }
  56. - else {}
  57. @@
  58. identifier a.x;
  59. expression e;
  60. @@
  61. - if (<+... x ...+>@e)
  62. - {}
  63. - else
  64. + if (!(e))
  65. {...}
  66. @@
  67. expression x, y, z;
  68. @@
  69. - x = of_get_mac_address(y, z);
  70. + of_get_mac_address(y, z);
  71. ... when != x
  72. </spml>
  73. All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
  74. compile-time tested.
  75. Suggested-by: Andrew Lunn <[email protected]>
  76. Signed-off-by: Michael Walle <[email protected]>
  77. Reviewed-by: Andrew Lunn <[email protected]>
  78. Signed-off-by: David S. Miller <[email protected]>
  79. ---
  80. arch/arm/mach-mvebu/kirkwood.c | 3 +-
  81. arch/powerpc/sysdev/tsi108_dev.c | 5 +-
  82. drivers/net/ethernet/aeroflex/greth.c | 6 +--
  83. drivers/net/ethernet/allwinner/sun4i-emac.c | 10 ++--
  84. drivers/net/ethernet/altera/altera_tse_main.c | 7 +--
  85. drivers/net/ethernet/arc/emac_main.c | 8 +--
  86. drivers/net/ethernet/atheros/ag71xx.c | 7 +--
  87. drivers/net/ethernet/broadcom/bcm4908_enet.c | 7 +--
  88. drivers/net/ethernet/broadcom/bcmsysport.c | 7 +--
  89. drivers/net/ethernet/broadcom/bgmac-bcma.c | 10 ++--
  90. drivers/net/ethernet/broadcom/bgmac-platform.c | 11 ++--
  91. drivers/net/ethernet/cadence/macb_main.c | 11 ++--
  92. drivers/net/ethernet/cavium/octeon/octeon_mgmt.c | 8 +--
  93. drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 5 +-
  94. drivers/net/ethernet/davicom/dm9000.c | 10 ++--
  95. drivers/net/ethernet/ethoc.c | 6 +--
  96. drivers/net/ethernet/ezchip/nps_enet.c | 7 +--
  97. drivers/net/ethernet/freescale/fec_main.c | 7 +--
  98. drivers/net/ethernet/freescale/fec_mpc52xx.c | 7 +--
  99. drivers/net/ethernet/freescale/fman/mac.c | 9 ++--
  100. .../net/ethernet/freescale/fs_enet/fs_enet-main.c | 5 +-
  101. drivers/net/ethernet/freescale/gianfar.c | 8 +--
  102. drivers/net/ethernet/freescale/ucc_geth.c | 5 +-
  103. drivers/net/ethernet/hisilicon/hisi_femac.c | 7 +--
  104. drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 7 +--
  105. drivers/net/ethernet/lantiq_xrx200.c | 7 +--
  106. drivers/net/ethernet/marvell/mv643xx_eth.c | 5 +-
  107. drivers/net/ethernet/marvell/mvneta.c | 6 +--
  108. .../net/ethernet/marvell/prestera/prestera_main.c | 11 ++--
  109. drivers/net/ethernet/marvell/pxa168_eth.c | 9 +---
  110. drivers/net/ethernet/marvell/sky2.c | 8 ++-
  111. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 11 ++--
  112. drivers/net/ethernet/micrel/ks8851_common.c | 7 ++-
  113. drivers/net/ethernet/microchip/lan743x_main.c | 5 +-
  114. drivers/net/ethernet/nxp/lpc_eth.c | 4 +-
  115. drivers/net/ethernet/qualcomm/qca_spi.c | 10 ++--
  116. drivers/net/ethernet/qualcomm/qca_uart.c | 9 +---
  117. drivers/net/ethernet/renesas/ravb_main.c | 12 +++--
  118. drivers/net/ethernet/renesas/sh_eth.c | 5 +-
  119. .../net/ethernet/samsung/sxgbe/sxgbe_platform.c | 13 ++---
  120. drivers/net/ethernet/socionext/sni_ave.c | 10 ++--
  121. .../net/ethernet/stmicro/stmmac/dwmac-anarion.c | 2 +-
  122. .../ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 +-
  123. .../net/ethernet/stmicro/stmmac/dwmac-generic.c | 2 +-
  124. drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c | 2 +-
  125. .../net/ethernet/stmicro/stmmac/dwmac-intel-plat.c | 2 +-
  126. .../net/ethernet/stmicro/stmmac/dwmac-ipq806x.c | 2 +-
  127. .../net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 2 +-
  128. .../net/ethernet/stmicro/stmmac/dwmac-mediatek.c | 2 +-
  129. drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c | 2 +-
  130. .../net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 2 +-
  131. drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 2 +-
  132. .../ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 2 +-
  133. drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 2 +-
  134. .../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 2 +-
  135. drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 2 +-
  136. drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 2 +-
  137. drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 +-
  138. drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 2 +-
  139. .../net/ethernet/stmicro/stmmac/dwmac-visconti.c | 2 +-
  140. drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +-
  141. drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
  142. .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 14 ++---
  143. .../net/ethernet/stmicro/stmmac/stmmac_platform.h | 2 +-
  144. drivers/net/ethernet/ti/am65-cpsw-nuss.c | 19 ++++---
  145. drivers/net/ethernet/ti/cpsw.c | 7 +--
  146. drivers/net/ethernet/ti/cpsw_new.c | 7 +--
  147. drivers/net/ethernet/ti/davinci_emac.c | 8 +--
  148. drivers/net/ethernet/ti/netcp_core.c | 7 +--
  149. drivers/net/ethernet/wiznet/w5100-spi.c | 8 ++-
  150. drivers/net/ethernet/wiznet/w5100.c | 2 +-
  151. drivers/net/ethernet/xilinx/ll_temac_main.c | 8 +--
  152. drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 15 +++---
  153. drivers/net/ethernet/xilinx/xilinx_emaclite.c | 8 +--
  154. drivers/net/wireless/ath/ath9k/init.c | 5 +-
  155. drivers/net/wireless/mediatek/mt76/eeprom.c | 9 +---
  156. drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 6 +--
  157. drivers/of/of_net.c | 60 ++++++++++------------
  158. drivers/staging/octeon/ethernet.c | 10 ++--
  159. drivers/staging/wfx/main.c | 7 ++-
  160. include/linux/of_net.h | 6 +--
  161. include/net/dsa.h | 2 +-
  162. net/dsa/dsa2.c | 2 +-
  163. net/dsa/slave.c | 2 +-
  164. net/ethernet/eth.c | 11 ++--
  165. 85 files changed, 218 insertions(+), 364 deletions(-)
  166. --- a/arch/arm/mach-mvebu/kirkwood.c
  167. +++ b/arch/arm/mach-mvebu/kirkwood.c
  168. @@ -84,6 +84,7 @@ static void __init kirkwood_dt_eth_fixup
  169. struct device_node *pnp = of_get_parent(np);
  170. struct clk *clk;
  171. struct property *pmac;
  172. + u8 tmpmac[ETH_ALEN];
  173. void __iomem *io;
  174. u8 *macaddr;
  175. u32 reg;
  176. @@ -93,7 +94,7 @@ static void __init kirkwood_dt_eth_fixup
  177. /* skip disabled nodes or nodes with valid MAC address*/
  178. if (!of_device_is_available(pnp) ||
  179. - !IS_ERR(of_get_mac_address(np)))
  180. + !of_get_mac_address(np, tmpmac))
  181. goto eth_fixup_skip;
  182. clk = of_clk_get(pnp, 0);
  183. --- a/arch/powerpc/sysdev/tsi108_dev.c
  184. +++ b/arch/powerpc/sysdev/tsi108_dev.c
  185. @@ -73,7 +73,6 @@ static int __init tsi108_eth_of_init(voi
  186. struct device_node *phy, *mdio;
  187. hw_info tsi_eth_data;
  188. const unsigned int *phy_id;
  189. - const void *mac_addr;
  190. const phandle *ph;
  191. memset(r, 0, sizeof(r));
  192. @@ -101,9 +100,7 @@ static int __init tsi108_eth_of_init(voi
  193. goto err;
  194. }
  195. - mac_addr = of_get_mac_address(np);
  196. - if (!IS_ERR(mac_addr))
  197. - ether_addr_copy(tsi_eth_data.mac_addr, mac_addr);
  198. + of_get_mac_address(np, tsi_eth_data.mac_addr);
  199. ph = of_get_property(np, "mdio-handle", NULL);
  200. mdio = of_find_node_by_phandle(*ph);
  201. --- a/drivers/net/ethernet/aeroflex/greth.c
  202. +++ b/drivers/net/ethernet/aeroflex/greth.c
  203. @@ -1449,10 +1449,10 @@ static int greth_of_probe(struct platfor
  204. break;
  205. }
  206. if (i == 6) {
  207. - const u8 *addr;
  208. + u8 addr[ETH_ALEN];
  209. - addr = of_get_mac_address(ofdev->dev.of_node);
  210. - if (!IS_ERR(addr)) {
  211. + err = of_get_mac_address(ofdev->dev.of_node, addr);
  212. + if (!err) {
  213. for (i = 0; i < 6; i++)
  214. macaddr[i] = (unsigned int) addr[i];
  215. } else {
  216. --- a/drivers/net/ethernet/allwinner/sun4i-emac.c
  217. +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
  218. @@ -790,7 +790,6 @@ static int emac_probe(struct platform_de
  219. struct emac_board_info *db;
  220. struct net_device *ndev;
  221. int ret = 0;
  222. - const char *mac_addr;
  223. ndev = alloc_etherdev(sizeof(struct emac_board_info));
  224. if (!ndev) {
  225. @@ -853,12 +852,9 @@ static int emac_probe(struct platform_de
  226. }
  227. /* Read MAC-address from DT */
  228. - mac_addr = of_get_mac_address(np);
  229. - if (!IS_ERR(mac_addr))
  230. - ether_addr_copy(ndev->dev_addr, mac_addr);
  231. -
  232. - /* Check if the MAC address is valid, if not get a random one */
  233. - if (!is_valid_ether_addr(ndev->dev_addr)) {
  234. + ret = of_get_mac_address(np, ndev->dev_addr);
  235. + if (ret) {
  236. + /* if the MAC address is invalid get a random one */
  237. eth_hw_addr_random(ndev);
  238. dev_warn(&pdev->dev, "using random MAC address %pM\n",
  239. ndev->dev_addr);
  240. --- a/drivers/net/ethernet/altera/altera_tse_main.c
  241. +++ b/drivers/net/ethernet/altera/altera_tse_main.c
  242. @@ -1351,7 +1351,6 @@ static int altera_tse_probe(struct platf
  243. struct resource *control_port;
  244. struct resource *dma_res;
  245. struct altera_tse_private *priv;
  246. - const unsigned char *macaddr;
  247. void __iomem *descmap;
  248. const struct of_device_id *of_id = NULL;
  249. @@ -1525,10 +1524,8 @@ static int altera_tse_probe(struct platf
  250. priv->rx_dma_buf_sz = ALTERA_RXDMABUFFER_SIZE;
  251. /* get default MAC address from device tree */
  252. - macaddr = of_get_mac_address(pdev->dev.of_node);
  253. - if (!IS_ERR(macaddr))
  254. - ether_addr_copy(ndev->dev_addr, macaddr);
  255. - else
  256. + ret = of_get_mac_address(pdev->dev.of_node, ndev->dev_addr);
  257. + if (ret)
  258. eth_hw_addr_random(ndev);
  259. /* get phy addr and create mdio */
  260. --- a/drivers/net/ethernet/arc/emac_main.c
  261. +++ b/drivers/net/ethernet/arc/emac_main.c
  262. @@ -857,7 +857,6 @@ int arc_emac_probe(struct net_device *nd
  263. struct device_node *phy_node;
  264. struct phy_device *phydev = NULL;
  265. struct arc_emac_priv *priv;
  266. - const char *mac_addr;
  267. unsigned int id, clock_frequency, irq;
  268. int err;
  269. @@ -942,11 +941,8 @@ int arc_emac_probe(struct net_device *nd
  270. }
  271. /* Get MAC address from device tree */
  272. - mac_addr = of_get_mac_address(dev->of_node);
  273. -
  274. - if (!IS_ERR(mac_addr))
  275. - ether_addr_copy(ndev->dev_addr, mac_addr);
  276. - else
  277. + err = of_get_mac_address(dev->of_node, ndev->dev_addr);
  278. + if (err)
  279. eth_hw_addr_random(ndev);
  280. arc_emac_set_address_internal(ndev);
  281. --- a/drivers/net/ethernet/atheros/ag71xx.c
  282. +++ b/drivers/net/ethernet/atheros/ag71xx.c
  283. @@ -1856,7 +1856,6 @@ static int ag71xx_probe(struct platform_
  284. const struct ag71xx_dcfg *dcfg;
  285. struct net_device *ndev;
  286. struct resource *res;
  287. - const void *mac_addr;
  288. int tx_size, err, i;
  289. struct ag71xx *ag;
  290. @@ -1957,10 +1956,8 @@ static int ag71xx_probe(struct platform_
  291. ag->stop_desc->ctrl = 0;
  292. ag->stop_desc->next = (u32)ag->stop_desc_dma;
  293. - mac_addr = of_get_mac_address(np);
  294. - if (!IS_ERR(mac_addr))
  295. - memcpy(ndev->dev_addr, mac_addr, ETH_ALEN);
  296. - if (IS_ERR(mac_addr) || !is_valid_ether_addr(ndev->dev_addr)) {
  297. + err = of_get_mac_address(np, ndev->dev_addr);
  298. + if (err) {
  299. netif_err(ag, probe, ndev, "invalid MAC address, using random address\n");
  300. eth_random_addr(ndev->dev_addr);
  301. }
  302. --- a/drivers/net/ethernet/broadcom/bcmsysport.c
  303. +++ b/drivers/net/ethernet/broadcom/bcmsysport.c
  304. @@ -2465,7 +2465,6 @@ static int bcm_sysport_probe(struct plat
  305. struct bcm_sysport_priv *priv;
  306. struct device_node *dn;
  307. struct net_device *dev;
  308. - const void *macaddr;
  309. u32 txq, rxq;
  310. int ret;
  311. @@ -2560,12 +2559,10 @@ static int bcm_sysport_probe(struct plat
  312. }
  313. /* Initialize netdevice members */
  314. - macaddr = of_get_mac_address(dn);
  315. - if (IS_ERR(macaddr)) {
  316. + ret = of_get_mac_address(dn, dev->dev_addr);
  317. + if (ret) {
  318. dev_warn(&pdev->dev, "using random Ethernet MAC\n");
  319. eth_hw_addr_random(dev);
  320. - } else {
  321. - ether_addr_copy(dev->dev_addr, macaddr);
  322. }
  323. SET_NETDEV_DEV(dev, &pdev->dev);
  324. --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
  325. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
  326. @@ -115,7 +115,7 @@ static int bgmac_probe(struct bcma_devic
  327. struct ssb_sprom *sprom = &core->bus->sprom;
  328. struct mii_bus *mii_bus;
  329. struct bgmac *bgmac;
  330. - const u8 *mac = NULL;
  331. + const u8 *mac;
  332. int err;
  333. bgmac = bgmac_alloc(&core->dev);
  334. @@ -128,11 +128,10 @@ static int bgmac_probe(struct bcma_devic
  335. bcma_set_drvdata(core, bgmac);
  336. - if (bgmac->dev->of_node)
  337. - mac = of_get_mac_address(bgmac->dev->of_node);
  338. + err = of_get_mac_address(bgmac->dev->of_node, bgmac->net_dev->dev_addr);
  339. /* If no MAC address assigned via device tree, check SPROM */
  340. - if (IS_ERR_OR_NULL(mac)) {
  341. + if (err) {
  342. switch (core->core_unit) {
  343. case 0:
  344. mac = sprom->et0mac;
  345. @@ -149,10 +148,9 @@ static int bgmac_probe(struct bcma_devic
  346. err = -ENOTSUPP;
  347. goto err;
  348. }
  349. + ether_addr_copy(bgmac->net_dev->dev_addr, mac);
  350. }
  351. - ether_addr_copy(bgmac->net_dev->dev_addr, mac);
  352. -
  353. /* On BCM4706 we need common core to access PHY */
  354. if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
  355. !core->bus->drv_gmac_cmn.core) {
  356. --- a/drivers/net/ethernet/broadcom/bgmac-platform.c
  357. +++ b/drivers/net/ethernet/broadcom/bgmac-platform.c
  358. @@ -173,7 +173,7 @@ static int bgmac_probe(struct platform_d
  359. struct device_node *np = pdev->dev.of_node;
  360. struct bgmac *bgmac;
  361. struct resource *regs;
  362. - const u8 *mac_addr;
  363. + int ret;
  364. bgmac = bgmac_alloc(&pdev->dev);
  365. if (!bgmac)
  366. @@ -192,11 +192,10 @@ static int bgmac_probe(struct platform_d
  367. bgmac->dev = &pdev->dev;
  368. bgmac->dma_dev = &pdev->dev;
  369. - mac_addr = of_get_mac_address(np);
  370. - if (!IS_ERR(mac_addr))
  371. - ether_addr_copy(bgmac->net_dev->dev_addr, mac_addr);
  372. - else
  373. - dev_warn(&pdev->dev, "MAC address not present in device tree\n");
  374. + ret = of_get_mac_address(np, bgmac->net_dev->dev_addr);
  375. + if (ret)
  376. + dev_warn(&pdev->dev,
  377. + "MAC address not present in device tree\n");
  378. bgmac->irq = platform_get_irq(pdev, 0);
  379. if (bgmac->irq < 0)
  380. --- a/drivers/net/ethernet/cadence/macb_main.c
  381. +++ b/drivers/net/ethernet/cadence/macb_main.c
  382. @@ -4456,7 +4456,6 @@ static int macb_probe(struct platform_de
  383. struct net_device *dev;
  384. struct resource *regs;
  385. void __iomem *mem;
  386. - const char *mac;
  387. struct macb *bp;
  388. int err, val;
  389. @@ -4569,15 +4568,11 @@ static int macb_probe(struct platform_de
  390. if (bp->caps & MACB_CAPS_NEEDS_RSTONUBR)
  391. bp->rx_intr_mask |= MACB_BIT(RXUBR);
  392. - mac = of_get_mac_address(np);
  393. - if (PTR_ERR(mac) == -EPROBE_DEFER) {
  394. - err = -EPROBE_DEFER;
  395. + err = of_get_mac_address(np, bp->dev->dev_addr);
  396. + if (err == -EPROBE_DEFER)
  397. goto err_out_free_netdev;
  398. - } else if (!IS_ERR_OR_NULL(mac)) {
  399. - ether_addr_copy(bp->dev->dev_addr, mac);
  400. - } else {
  401. + else if (err)
  402. macb_get_hwaddr(bp);
  403. - }
  404. err = of_get_phy_mode(np, &interface);
  405. if (err)
  406. --- a/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c
  407. +++ b/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c
  408. @@ -1385,7 +1385,6 @@ static int octeon_mgmt_probe(struct plat
  409. struct net_device *netdev;
  410. struct octeon_mgmt *p;
  411. const __be32 *data;
  412. - const u8 *mac;
  413. struct resource *res_mix;
  414. struct resource *res_agl;
  415. struct resource *res_agl_prt_ctl;
  416. @@ -1502,11 +1501,8 @@ static int octeon_mgmt_probe(struct plat
  417. netdev->min_mtu = 64 - OCTEON_MGMT_RX_HEADROOM;
  418. netdev->max_mtu = 16383 - OCTEON_MGMT_RX_HEADROOM - VLAN_HLEN;
  419. - mac = of_get_mac_address(pdev->dev.of_node);
  420. -
  421. - if (!IS_ERR(mac))
  422. - ether_addr_copy(netdev->dev_addr, mac);
  423. - else
  424. + result = of_get_mac_address(pdev->dev.of_node, netdev->dev_addr);
  425. + if (result)
  426. eth_hw_addr_random(netdev);
  427. p->phy_np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
  428. --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
  429. +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
  430. @@ -1474,7 +1474,6 @@ static int bgx_init_of_phy(struct bgx *b
  431. device_for_each_child_node(&bgx->pdev->dev, fwn) {
  432. struct phy_device *pd;
  433. struct device_node *phy_np;
  434. - const char *mac;
  435. /* Should always be an OF node. But if it is not, we
  436. * cannot handle it, so exit the loop.
  437. @@ -1483,9 +1482,7 @@ static int bgx_init_of_phy(struct bgx *b
  438. if (!node)
  439. break;
  440. - mac = of_get_mac_address(node);
  441. - if (!IS_ERR(mac))
  442. - ether_addr_copy(bgx->lmac[lmac].mac, mac);
  443. + of_get_mac_address(node, bgx->lmac[lmac].mac);
  444. SET_NETDEV_DEV(&bgx->lmac[lmac].netdev, &bgx->pdev->dev);
  445. bgx->lmac[lmac].lmacid = lmac;
  446. --- a/drivers/net/ethernet/davicom/dm9000.c
  447. +++ b/drivers/net/ethernet/davicom/dm9000.c
  448. @@ -1388,7 +1388,7 @@ static struct dm9000_plat_data *dm9000_p
  449. {
  450. struct dm9000_plat_data *pdata;
  451. struct device_node *np = dev->of_node;
  452. - const void *mac_addr;
  453. + int ret;
  454. if (!IS_ENABLED(CONFIG_OF) || !np)
  455. return ERR_PTR(-ENXIO);
  456. @@ -1402,11 +1402,9 @@ static struct dm9000_plat_data *dm9000_p
  457. if (of_find_property(np, "davicom,no-eeprom", NULL))
  458. pdata->flags |= DM9000_PLATF_NO_EEPROM;
  459. - mac_addr = of_get_mac_address(np);
  460. - if (!IS_ERR(mac_addr))
  461. - ether_addr_copy(pdata->dev_addr, mac_addr);
  462. - else if (PTR_ERR(mac_addr) == -EPROBE_DEFER)
  463. - return ERR_CAST(mac_addr);
  464. + ret = of_get_mac_address(np, pdata->dev_addr);
  465. + if (ret == -EPROBE_DEFER)
  466. + return ERR_PTR(ret);
  467. return pdata;
  468. }
  469. --- a/drivers/net/ethernet/ethoc.c
  470. +++ b/drivers/net/ethernet/ethoc.c
  471. @@ -1151,11 +1151,7 @@ static int ethoc_probe(struct platform_d
  472. ether_addr_copy(netdev->dev_addr, pdata->hwaddr);
  473. priv->phy_id = pdata->phy_id;
  474. } else {
  475. - const void *mac;
  476. -
  477. - mac = of_get_mac_address(pdev->dev.of_node);
  478. - if (!IS_ERR(mac))
  479. - ether_addr_copy(netdev->dev_addr, mac);
  480. + of_get_mac_address(pdev->dev.of_node, netdev->dev_addr);
  481. priv->phy_id = -1;
  482. }
  483. --- a/drivers/net/ethernet/ezchip/nps_enet.c
  484. +++ b/drivers/net/ethernet/ezchip/nps_enet.c
  485. @@ -575,7 +575,6 @@ static s32 nps_enet_probe(struct platfor
  486. struct net_device *ndev;
  487. struct nps_enet_priv *priv;
  488. s32 err = 0;
  489. - const char *mac_addr;
  490. if (!dev->of_node)
  491. return -ENODEV;
  492. @@ -602,10 +601,8 @@ static s32 nps_enet_probe(struct platfor
  493. dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs_base);
  494. /* set kernel MAC address to dev */
  495. - mac_addr = of_get_mac_address(dev->of_node);
  496. - if (!IS_ERR(mac_addr))
  497. - ether_addr_copy(ndev->dev_addr, mac_addr);
  498. - else
  499. + err = of_get_mac_address(dev->of_node, ndev->dev_addr);
  500. + if (err)
  501. eth_hw_addr_random(ndev);
  502. /* Get IRQ number */
  503. --- a/drivers/net/ethernet/freescale/fec_main.c
  504. +++ b/drivers/net/ethernet/freescale/fec_main.c
  505. @@ -1666,6 +1666,7 @@ static void fec_get_mac(struct net_devic
  506. struct fec_enet_private *fep = netdev_priv(ndev);
  507. struct fec_platform_data *pdata = dev_get_platdata(&fep->pdev->dev);
  508. unsigned char *iap, tmpaddr[ETH_ALEN];
  509. + int ret;
  510. /*
  511. * try to get mac address in following order:
  512. @@ -1681,9 +1682,9 @@ static void fec_get_mac(struct net_devic
  513. if (!is_valid_ether_addr(iap)) {
  514. struct device_node *np = fep->pdev->dev.of_node;
  515. if (np) {
  516. - const char *mac = of_get_mac_address(np);
  517. - if (!IS_ERR(mac))
  518. - iap = (unsigned char *) mac;
  519. + ret = of_get_mac_address(np, tmpaddr);
  520. + if (!ret)
  521. + iap = tmpaddr;
  522. }
  523. }
  524. --- a/drivers/net/ethernet/freescale/fec_mpc52xx.c
  525. +++ b/drivers/net/ethernet/freescale/fec_mpc52xx.c
  526. @@ -813,7 +813,6 @@ static int mpc52xx_fec_probe(struct plat
  527. const u32 *prop;
  528. int prop_size;
  529. struct device_node *np = op->dev.of_node;
  530. - const char *mac_addr;
  531. phys_addr_t rx_fifo;
  532. phys_addr_t tx_fifo;
  533. @@ -891,10 +890,8 @@ static int mpc52xx_fec_probe(struct plat
  534. *
  535. * First try to read MAC address from DT
  536. */
  537. - mac_addr = of_get_mac_address(np);
  538. - if (!IS_ERR(mac_addr)) {
  539. - ether_addr_copy(ndev->dev_addr, mac_addr);
  540. - } else {
  541. + rv = of_get_mac_address(np, ndev->dev_addr);
  542. + if (rv) {
  543. struct mpc52xx_fec __iomem *fec = priv->fec;
  544. /*
  545. --- a/drivers/net/ethernet/freescale/fman/mac.c
  546. +++ b/drivers/net/ethernet/freescale/fman/mac.c
  547. @@ -605,7 +605,6 @@ static int mac_probe(struct platform_dev
  548. struct platform_device *of_dev;
  549. struct resource res;
  550. struct mac_priv_s *priv;
  551. - const u8 *mac_addr;
  552. u32 val;
  553. u8 fman_id;
  554. phy_interface_t phy_if;
  555. @@ -723,11 +722,9 @@ static int mac_probe(struct platform_dev
  556. priv->cell_index = (u8)val;
  557. /* Get the MAC address */
  558. - mac_addr = of_get_mac_address(mac_node);
  559. - if (IS_ERR(mac_addr))
  560. + err = of_get_mac_address(mac_node, mac_dev->addr);
  561. + if (err)
  562. dev_warn(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
  563. - else
  564. - ether_addr_copy(mac_dev->addr, mac_addr);
  565. /* Get the port handles */
  566. nph = of_count_phandle_with_args(mac_node, "fsl,fman-ports", NULL);
  567. @@ -853,7 +850,7 @@ static int mac_probe(struct platform_dev
  568. if (err < 0)
  569. dev_err(dev, "fman_set_mac_active_pause() = %d\n", err);
  570. - if (!IS_ERR(mac_addr))
  571. + if (!is_zero_ether_addr(mac_dev->addr))
  572. dev_info(dev, "FMan MAC address: %pM\n", mac_dev->addr);
  573. priv->eth_dev = dpaa_eth_add_device(fman_id, mac_dev);
  574. --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
  575. +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
  576. @@ -918,7 +918,6 @@ static int fs_enet_probe(struct platform
  577. const u32 *data;
  578. struct clk *clk;
  579. int err;
  580. - const u8 *mac_addr;
  581. const char *phy_connection_type;
  582. int privsize, len, ret = -ENODEV;
  583. @@ -1006,9 +1005,7 @@ static int fs_enet_probe(struct platform
  584. spin_lock_init(&fep->lock);
  585. spin_lock_init(&fep->tx_lock);
  586. - mac_addr = of_get_mac_address(ofdev->dev.of_node);
  587. - if (!IS_ERR(mac_addr))
  588. - ether_addr_copy(ndev->dev_addr, mac_addr);
  589. + of_get_mac_address(ofdev->dev.of_node, ndev->dev_addr);
  590. ret = fep->ops->allocate_bd(ndev);
  591. if (ret)
  592. --- a/drivers/net/ethernet/freescale/gianfar.c
  593. +++ b/drivers/net/ethernet/freescale/gianfar.c
  594. @@ -641,7 +641,6 @@ static phy_interface_t gfar_get_interfac
  595. static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
  596. {
  597. const char *model;
  598. - const void *mac_addr;
  599. int err = 0, i;
  600. phy_interface_t interface;
  601. struct net_device *dev = NULL;
  602. @@ -783,11 +782,8 @@ static int gfar_of_init(struct platform_
  603. if (stash_len || stash_idx)
  604. priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
  605. - mac_addr = of_get_mac_address(np);
  606. -
  607. - if (!IS_ERR(mac_addr)) {
  608. - ether_addr_copy(dev->dev_addr, mac_addr);
  609. - } else {
  610. + err = of_get_mac_address(np, dev->dev_addr);
  611. + if (err) {
  612. eth_hw_addr_random(dev);
  613. dev_info(&ofdev->dev, "Using random MAC address: %pM\n", dev->dev_addr);
  614. }
  615. --- a/drivers/net/ethernet/freescale/ucc_geth.c
  616. +++ b/drivers/net/ethernet/freescale/ucc_geth.c
  617. @@ -3696,7 +3696,6 @@ static int ucc_geth_probe(struct platfor
  618. int err, ucc_num, max_speed = 0;
  619. const unsigned int *prop;
  620. const char *sprop;
  621. - const void *mac_addr;
  622. phy_interface_t phy_interface;
  623. static const int enet_to_speed[] = {
  624. SPEED_10, SPEED_10, SPEED_10,
  625. @@ -3906,9 +3905,7 @@ static int ucc_geth_probe(struct platfor
  626. goto err_free_netdev;
  627. }
  628. - mac_addr = of_get_mac_address(np);
  629. - if (!IS_ERR(mac_addr))
  630. - ether_addr_copy(dev->dev_addr, mac_addr);
  631. + of_get_mac_address(np, dev->dev_addr);
  632. ugeth->ug_info = ug_info;
  633. ugeth->dev = device;
  634. --- a/drivers/net/ethernet/hisilicon/hisi_femac.c
  635. +++ b/drivers/net/ethernet/hisilicon/hisi_femac.c
  636. @@ -772,7 +772,6 @@ static int hisi_femac_drv_probe(struct p
  637. struct net_device *ndev;
  638. struct hisi_femac_priv *priv;
  639. struct phy_device *phy;
  640. - const char *mac_addr;
  641. int ret;
  642. ndev = alloc_etherdev(sizeof(*priv));
  643. @@ -842,10 +841,8 @@ static int hisi_femac_drv_probe(struct p
  644. (unsigned long)phy->phy_id,
  645. phy_modes(phy->interface));
  646. - mac_addr = of_get_mac_address(node);
  647. - if (!IS_ERR(mac_addr))
  648. - ether_addr_copy(ndev->dev_addr, mac_addr);
  649. - if (!is_valid_ether_addr(ndev->dev_addr)) {
  650. + ret = of_get_mac_address(node, ndev->dev_addr);
  651. + if (ret) {
  652. eth_hw_addr_random(ndev);
  653. dev_warn(dev, "using random MAC address %pM\n",
  654. ndev->dev_addr);
  655. --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
  656. +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
  657. @@ -1098,7 +1098,6 @@ static int hix5hd2_dev_probe(struct plat
  658. struct net_device *ndev;
  659. struct hix5hd2_priv *priv;
  660. struct mii_bus *bus;
  661. - const char *mac_addr;
  662. int ret;
  663. ndev = alloc_etherdev(sizeof(struct hix5hd2_priv));
  664. @@ -1220,10 +1219,8 @@ static int hix5hd2_dev_probe(struct plat
  665. goto out_phy_node;
  666. }
  667. - mac_addr = of_get_mac_address(node);
  668. - if (!IS_ERR(mac_addr))
  669. - ether_addr_copy(ndev->dev_addr, mac_addr);
  670. - if (!is_valid_ether_addr(ndev->dev_addr)) {
  671. + ret = of_get_mac_address(node, ndev->dev_addr);
  672. + if (ret) {
  673. eth_hw_addr_random(ndev);
  674. netdev_warn(ndev, "using random MAC address %pM\n",
  675. ndev->dev_addr);
  676. --- a/drivers/net/ethernet/lantiq_xrx200.c
  677. +++ b/drivers/net/ethernet/lantiq_xrx200.c
  678. @@ -440,7 +440,6 @@ static int xrx200_probe(struct platform_
  679. struct resource *res;
  680. struct xrx200_priv *priv;
  681. struct net_device *net_dev;
  682. - const u8 *mac;
  683. int err;
  684. /* alloc the network device */
  685. @@ -484,10 +483,8 @@ static int xrx200_probe(struct platform_
  686. return PTR_ERR(priv->clk);
  687. }
  688. - mac = of_get_mac_address(np);
  689. - if (!IS_ERR(mac))
  690. - ether_addr_copy(net_dev->dev_addr, mac);
  691. - else
  692. + err = of_get_mac_address(np, net_dev->dev_addr);
  693. + if (err)
  694. eth_hw_addr_random(net_dev);
  695. /* bring up the dma engine and IP core */
  696. --- a/drivers/net/ethernet/marvell/mv643xx_eth.c
  697. +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
  698. @@ -2700,7 +2700,6 @@ static int mv643xx_eth_shared_of_add_por
  699. struct platform_device *ppdev;
  700. struct mv643xx_eth_platform_data ppd;
  701. struct resource res;
  702. - const char *mac_addr;
  703. int ret;
  704. int dev_num = 0;
  705. @@ -2731,9 +2730,7 @@ static int mv643xx_eth_shared_of_add_por
  706. return -EINVAL;
  707. }
  708. - mac_addr = of_get_mac_address(pnp);
  709. - if (!IS_ERR(mac_addr))
  710. - ether_addr_copy(ppd.mac_addr, mac_addr);
  711. + of_get_mac_address(pnp, ppd.mac_addr);
  712. mv643xx_eth_property(pnp, "tx-queue-size", ppd.tx_queue_size);
  713. mv643xx_eth_property(pnp, "tx-sram-addr", ppd.tx_sram_addr);
  714. --- a/drivers/net/ethernet/marvell/mvneta.c
  715. +++ b/drivers/net/ethernet/marvell/mvneta.c
  716. @@ -5062,7 +5062,6 @@ static int mvneta_probe(struct platform_
  717. struct net_device *dev;
  718. struct phylink *phylink;
  719. struct phy *comphy;
  720. - const char *dt_mac_addr;
  721. char hw_mac_addr[ETH_ALEN];
  722. phy_interface_t phy_mode;
  723. const char *mac_from;
  724. @@ -5158,10 +5157,9 @@ static int mvneta_probe(struct platform_
  725. goto err_free_ports;
  726. }
  727. - dt_mac_addr = of_get_mac_address(dn);
  728. - if (!IS_ERR(dt_mac_addr)) {
  729. + err = of_get_mac_address(dn, dev->dev_addr);
  730. + if (!err) {
  731. mac_from = "device tree";
  732. - ether_addr_copy(dev->dev_addr, dt_mac_addr);
  733. } else {
  734. mvneta_get_mac_addr(pp, hw_mac_addr);
  735. if (is_valid_ether_addr(hw_mac_addr)) {
  736. --- a/drivers/net/ethernet/marvell/prestera/prestera_main.c
  737. +++ b/drivers/net/ethernet/marvell/prestera/prestera_main.c
  738. @@ -462,20 +462,17 @@ static int prestera_switch_set_base_mac_
  739. {
  740. struct device_node *base_mac_np;
  741. struct device_node *np;
  742. - const char *base_mac;
  743. + int ret;
  744. np = of_find_compatible_node(NULL, NULL, "marvell,prestera");
  745. base_mac_np = of_parse_phandle(np, "base-mac-provider", 0);
  746. - base_mac = of_get_mac_address(base_mac_np);
  747. - of_node_put(base_mac_np);
  748. - if (!IS_ERR(base_mac))
  749. - ether_addr_copy(sw->base_mac, base_mac);
  750. -
  751. - if (!is_valid_ether_addr(sw->base_mac)) {
  752. + ret = of_get_mac_address(base_mac_np, sw->base_mac);
  753. + if (ret) {
  754. eth_random_addr(sw->base_mac);
  755. dev_info(prestera_dev(sw), "using random base mac address\n");
  756. }
  757. + of_node_put(base_mac_np);
  758. return prestera_hw_switch_mac_set(sw, sw->base_mac);
  759. }
  760. --- a/drivers/net/ethernet/marvell/pxa168_eth.c
  761. +++ b/drivers/net/ethernet/marvell/pxa168_eth.c
  762. @@ -1392,7 +1392,6 @@ static int pxa168_eth_probe(struct platf
  763. struct resource *res;
  764. struct clk *clk;
  765. struct device_node *np;
  766. - const unsigned char *mac_addr = NULL;
  767. int err;
  768. printk(KERN_NOTICE "PXA168 10/100 Ethernet Driver\n");
  769. @@ -1435,12 +1434,8 @@ static int pxa168_eth_probe(struct platf
  770. INIT_WORK(&pep->tx_timeout_task, pxa168_eth_tx_timeout_task);
  771. - if (pdev->dev.of_node)
  772. - mac_addr = of_get_mac_address(pdev->dev.of_node);
  773. -
  774. - if (!IS_ERR_OR_NULL(mac_addr)) {
  775. - ether_addr_copy(dev->dev_addr, mac_addr);
  776. - } else {
  777. + err = of_get_mac_address(pdev->dev.of_node, dev->dev_addr);
  778. + if (err) {
  779. /* try reading the mac address, if set by the bootloader */
  780. pxa168_eth_get_mac_address(dev, dev->dev_addr);
  781. if (!is_valid_ether_addr(dev->dev_addr)) {
  782. --- a/drivers/net/ethernet/marvell/sky2.c
  783. +++ b/drivers/net/ethernet/marvell/sky2.c
  784. @@ -4725,7 +4725,7 @@ static struct net_device *sky2_init_netd
  785. {
  786. struct sky2_port *sky2;
  787. struct net_device *dev = alloc_etherdev(sizeof(*sky2));
  788. - const void *iap;
  789. + int ret;
  790. if (!dev)
  791. return NULL;
  792. @@ -4795,10 +4795,8 @@ static struct net_device *sky2_init_netd
  793. * 1) from device tree data
  794. * 2) from internal registers set by bootloader
  795. */
  796. - iap = of_get_mac_address(hw->pdev->dev.of_node);
  797. - if (!IS_ERR(iap))
  798. - ether_addr_copy(dev->dev_addr, iap);
  799. - else
  800. + ret = of_get_mac_address(hw->pdev->dev.of_node, dev->dev_addr);
  801. + if (ret)
  802. memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8,
  803. ETH_ALEN);
  804. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  805. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  806. @@ -2580,14 +2580,11 @@ static int __init mtk_init(struct net_de
  807. {
  808. struct mtk_mac *mac = netdev_priv(dev);
  809. struct mtk_eth *eth = mac->hw;
  810. - const char *mac_addr;
  811. + int ret;
  812. - mac_addr = of_get_mac_address(mac->of_node);
  813. - if (!IS_ERR(mac_addr))
  814. - ether_addr_copy(dev->dev_addr, mac_addr);
  815. -
  816. - /* If the mac address is invalid, use random mac address */
  817. - if (!is_valid_ether_addr(dev->dev_addr)) {
  818. + ret = of_get_mac_address(mac->of_node, dev->dev_addr);
  819. + if (ret) {
  820. + /* If the mac address is invalid, use random mac address */
  821. eth_hw_addr_random(dev);
  822. dev_err(eth->dev, "generated random MAC address %pM\n",
  823. dev->dev_addr);
  824. --- a/drivers/net/ethernet/micrel/ks8851_common.c
  825. +++ b/drivers/net/ethernet/micrel/ks8851_common.c
  826. @@ -194,11 +194,10 @@ static void ks8851_read_mac_addr(struct
  827. static void ks8851_init_mac(struct ks8851_net *ks, struct device_node *np)
  828. {
  829. struct net_device *dev = ks->netdev;
  830. - const u8 *mac_addr;
  831. + int ret;
  832. - mac_addr = of_get_mac_address(np);
  833. - if (!IS_ERR(mac_addr)) {
  834. - ether_addr_copy(dev->dev_addr, mac_addr);
  835. + ret = of_get_mac_address(np, dev->dev_addr);
  836. + if (!ret) {
  837. ks8851_write_mac_addr(dev);
  838. return;
  839. }
  840. --- a/drivers/net/ethernet/microchip/lan743x_main.c
  841. +++ b/drivers/net/ethernet/microchip/lan743x_main.c
  842. @@ -2835,7 +2835,6 @@ static int lan743x_pcidev_probe(struct p
  843. {
  844. struct lan743x_adapter *adapter = NULL;
  845. struct net_device *netdev = NULL;
  846. - const void *mac_addr;
  847. int ret = -ENODEV;
  848. netdev = devm_alloc_etherdev(&pdev->dev,
  849. @@ -2852,9 +2851,7 @@ static int lan743x_pcidev_probe(struct p
  850. NETIF_MSG_IFDOWN | NETIF_MSG_TX_QUEUED;
  851. netdev->max_mtu = LAN743X_MAX_FRAME_SIZE;
  852. - mac_addr = of_get_mac_address(pdev->dev.of_node);
  853. - if (!IS_ERR(mac_addr))
  854. - ether_addr_copy(adapter->mac_address, mac_addr);
  855. + of_get_mac_address(pdev->dev.of_node, adapter->mac_address);
  856. ret = lan743x_pci_init(adapter, pdev);
  857. if (ret)
  858. --- a/drivers/net/ethernet/nxp/lpc_eth.c
  859. +++ b/drivers/net/ethernet/nxp/lpc_eth.c
  860. @@ -1347,9 +1347,7 @@ static int lpc_eth_drv_probe(struct plat
  861. __lpc_get_mac(pldat, ndev->dev_addr);
  862. if (!is_valid_ether_addr(ndev->dev_addr)) {
  863. - const char *macaddr = of_get_mac_address(np);
  864. - if (!IS_ERR(macaddr))
  865. - ether_addr_copy(ndev->dev_addr, macaddr);
  866. + of_get_mac_address(np, ndev->dev_addr);
  867. }
  868. if (!is_valid_ether_addr(ndev->dev_addr))
  869. eth_hw_addr_random(ndev);
  870. --- a/drivers/net/ethernet/qualcomm/qca_spi.c
  871. +++ b/drivers/net/ethernet/qualcomm/qca_spi.c
  872. @@ -885,7 +885,7 @@ qca_spi_probe(struct spi_device *spi)
  873. struct net_device *qcaspi_devs = NULL;
  874. u8 legacy_mode = 0;
  875. u16 signature;
  876. - const char *mac;
  877. + int ret;
  878. if (!spi->dev.of_node) {
  879. dev_err(&spi->dev, "Missing device tree\n");
  880. @@ -962,12 +962,8 @@ qca_spi_probe(struct spi_device *spi)
  881. spi_set_drvdata(spi, qcaspi_devs);
  882. - mac = of_get_mac_address(spi->dev.of_node);
  883. -
  884. - if (!IS_ERR(mac))
  885. - ether_addr_copy(qca->net_dev->dev_addr, mac);
  886. -
  887. - if (!is_valid_ether_addr(qca->net_dev->dev_addr)) {
  888. + ret = of_get_mac_address(spi->dev.of_node, qca->net_dev->dev_addr);
  889. + if (ret) {
  890. eth_hw_addr_random(qca->net_dev);
  891. dev_info(&spi->dev, "Using random MAC address: %pM\n",
  892. qca->net_dev->dev_addr);
  893. --- a/drivers/net/ethernet/qualcomm/qca_uart.c
  894. +++ b/drivers/net/ethernet/qualcomm/qca_uart.c
  895. @@ -323,7 +323,6 @@ static int qca_uart_probe(struct serdev_
  896. {
  897. struct net_device *qcauart_dev = alloc_etherdev(sizeof(struct qcauart));
  898. struct qcauart *qca;
  899. - const char *mac;
  900. u32 speed = 115200;
  901. int ret;
  902. @@ -348,12 +347,8 @@ static int qca_uart_probe(struct serdev_
  903. of_property_read_u32(serdev->dev.of_node, "current-speed", &speed);
  904. - mac = of_get_mac_address(serdev->dev.of_node);
  905. -
  906. - if (!IS_ERR(mac))
  907. - ether_addr_copy(qca->net_dev->dev_addr, mac);
  908. -
  909. - if (!is_valid_ether_addr(qca->net_dev->dev_addr)) {
  910. + ret = of_get_mac_address(serdev->dev.of_node, qca->net_dev->dev_addr);
  911. + if (ret) {
  912. eth_hw_addr_random(qca->net_dev);
  913. dev_info(&serdev->dev, "Using random MAC address: %pM\n",
  914. qca->net_dev->dev_addr);
  915. --- a/drivers/net/ethernet/renesas/ravb_main.c
  916. +++ b/drivers/net/ethernet/renesas/ravb_main.c
  917. @@ -109,11 +109,13 @@ static void ravb_set_buffer_align(struct
  918. * Ethernet AVB device doesn't have ROM for MAC address.
  919. * This function gets the MAC address that was used by a bootloader.
  920. */
  921. -static void ravb_read_mac_address(struct net_device *ndev, const u8 *mac)
  922. +static void ravb_read_mac_address(struct device_node *np,
  923. + struct net_device *ndev)
  924. {
  925. - if (!IS_ERR(mac)) {
  926. - ether_addr_copy(ndev->dev_addr, mac);
  927. - } else {
  928. + int ret;
  929. +
  930. + ret = of_get_mac_address(np, ndev->dev_addr);
  931. + if (ret) {
  932. u32 mahr = ravb_read(ndev, MAHR);
  933. u32 malr = ravb_read(ndev, MALR);
  934. @@ -2189,7 +2191,7 @@ static int ravb_probe(struct platform_de
  935. priv->msg_enable = RAVB_DEF_MSG_ENABLE;
  936. /* Read and set MAC address */
  937. - ravb_read_mac_address(ndev, of_get_mac_address(np));
  938. + ravb_read_mac_address(np, ndev);
  939. if (!is_valid_ether_addr(ndev->dev_addr)) {
  940. dev_warn(&pdev->dev,
  941. "no valid MAC address supplied, using a random one\n");
  942. --- a/drivers/net/ethernet/renesas/sh_eth.c
  943. +++ b/drivers/net/ethernet/renesas/sh_eth.c
  944. @@ -3145,7 +3145,6 @@ static struct sh_eth_plat_data *sh_eth_p
  945. struct device_node *np = dev->of_node;
  946. struct sh_eth_plat_data *pdata;
  947. phy_interface_t interface;
  948. - const char *mac_addr;
  949. int ret;
  950. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  951. @@ -3157,9 +3156,7 @@ static struct sh_eth_plat_data *sh_eth_p
  952. return NULL;
  953. pdata->phy_interface = interface;
  954. - mac_addr = of_get_mac_address(np);
  955. - if (!IS_ERR(mac_addr))
  956. - ether_addr_copy(pdata->mac_addr, mac_addr);
  957. + of_get_mac_address(np, pdata->mac_addr);
  958. pdata->no_ether_link =
  959. of_property_read_bool(np, "renesas,no-ether-link");
  960. --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
  961. +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
  962. @@ -25,8 +25,7 @@
  963. #ifdef CONFIG_OF
  964. static int sxgbe_probe_config_dt(struct platform_device *pdev,
  965. - struct sxgbe_plat_data *plat,
  966. - const char **mac)
  967. + struct sxgbe_plat_data *plat)
  968. {
  969. struct device_node *np = pdev->dev.of_node;
  970. struct sxgbe_dma_cfg *dma_cfg;
  971. @@ -35,7 +34,6 @@ static int sxgbe_probe_config_dt(struct
  972. if (!np)
  973. return -ENODEV;
  974. - *mac = of_get_mac_address(np);
  975. err = of_get_phy_mode(np, &plat->interface);
  976. if (err && err != -ENODEV)
  977. return err;
  978. @@ -63,8 +61,7 @@ static int sxgbe_probe_config_dt(struct
  979. }
  980. #else
  981. static int sxgbe_probe_config_dt(struct platform_device *pdev,
  982. - struct sxgbe_plat_data *plat,
  983. - const char **mac)
  984. + struct sxgbe_plat_data *plat)
  985. {
  986. return -ENOSYS;
  987. }
  988. @@ -85,7 +82,6 @@ static int sxgbe_platform_probe(struct p
  989. void __iomem *addr;
  990. struct sxgbe_priv_data *priv = NULL;
  991. struct sxgbe_plat_data *plat_dat = NULL;
  992. - const char *mac = NULL;
  993. struct net_device *ndev = platform_get_drvdata(pdev);
  994. struct device_node *node = dev->of_node;
  995. @@ -101,7 +97,7 @@ static int sxgbe_platform_probe(struct p
  996. if (!plat_dat)
  997. return -ENOMEM;
  998. - ret = sxgbe_probe_config_dt(pdev, plat_dat, &mac);
  999. + ret = sxgbe_probe_config_dt(pdev, plat_dat);
  1000. if (ret) {
  1001. pr_err("%s: main dt probe failed\n", __func__);
  1002. return ret;
  1003. @@ -122,8 +118,7 @@ static int sxgbe_platform_probe(struct p
  1004. }
  1005. /* Get MAC address if available (DT) */
  1006. - if (!IS_ERR_OR_NULL(mac))
  1007. - ether_addr_copy(priv->dev->dev_addr, mac);
  1008. + of_get_mac_address(node, priv->dev->dev_addr);
  1009. /* Get the TX/RX IRQ numbers */
  1010. for (i = 0, chan = 1; i < SXGBE_TX_QUEUES; i++) {
  1011. --- a/drivers/net/ethernet/socionext/sni_ave.c
  1012. +++ b/drivers/net/ethernet/socionext/sni_ave.c
  1013. @@ -1559,7 +1559,6 @@ static int ave_probe(struct platform_dev
  1014. struct ave_private *priv;
  1015. struct net_device *ndev;
  1016. struct device_node *np;
  1017. - const void *mac_addr;
  1018. void __iomem *base;
  1019. const char *name;
  1020. int i, irq, ret;
  1021. @@ -1600,12 +1599,9 @@ static int ave_probe(struct platform_dev
  1022. ndev->max_mtu = AVE_MAX_ETHFRAME - (ETH_HLEN + ETH_FCS_LEN);
  1023. - mac_addr = of_get_mac_address(np);
  1024. - if (!IS_ERR(mac_addr))
  1025. - ether_addr_copy(ndev->dev_addr, mac_addr);
  1026. -
  1027. - /* if the mac address is invalid, use random mac address */
  1028. - if (!is_valid_ether_addr(ndev->dev_addr)) {
  1029. + ret = of_get_mac_address(np, ndev->dev_addr);
  1030. + if (ret) {
  1031. + /* if the mac address is invalid, use random mac address */
  1032. eth_hw_addr_random(ndev);
  1033. dev_warn(dev, "Using random MAC address: %pM\n",
  1034. ndev->dev_addr);
  1035. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c
  1036. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c
  1037. @@ -115,7 +115,7 @@ static int anarion_dwmac_probe(struct pl
  1038. if (IS_ERR(gmac))
  1039. return PTR_ERR(gmac);
  1040. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1041. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1042. if (IS_ERR(plat_dat))
  1043. return PTR_ERR(plat_dat);
  1044. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
  1045. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
  1046. @@ -444,7 +444,7 @@ static int dwc_eth_dwmac_probe(struct pl
  1047. if (IS_ERR(stmmac_res.addr))
  1048. return PTR_ERR(stmmac_res.addr);
  1049. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1050. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1051. if (IS_ERR(plat_dat))
  1052. return PTR_ERR(plat_dat);
  1053. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
  1054. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
  1055. @@ -27,7 +27,7 @@ static int dwmac_generic_probe(struct pl
  1056. return ret;
  1057. if (pdev->dev.of_node) {
  1058. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1059. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1060. if (IS_ERR(plat_dat)) {
  1061. dev_err(&pdev->dev, "dt configuration failed\n");
  1062. return PTR_ERR(plat_dat);
  1063. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c
  1064. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c
  1065. @@ -226,7 +226,7 @@ static int imx_dwmac_probe(struct platfo
  1066. if (!dwmac)
  1067. return -ENOMEM;
  1068. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1069. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1070. if (IS_ERR(plat_dat))
  1071. return PTR_ERR(plat_dat);
  1072. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
  1073. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
  1074. @@ -88,7 +88,7 @@ static int intel_eth_plat_probe(struct p
  1075. if (ret)
  1076. return ret;
  1077. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1078. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1079. if (IS_ERR(plat_dat)) {
  1080. dev_err(&pdev->dev, "dt configuration failed\n");
  1081. return PTR_ERR(plat_dat);
  1082. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
  1083. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
  1084. @@ -255,7 +255,7 @@ static int ipq806x_gmac_probe(struct pla
  1085. if (val)
  1086. return val;
  1087. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1088. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1089. if (IS_ERR(plat_dat))
  1090. return PTR_ERR(plat_dat);
  1091. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
  1092. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
  1093. @@ -37,7 +37,7 @@ static int lpc18xx_dwmac_probe(struct pl
  1094. if (ret)
  1095. return ret;
  1096. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1097. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1098. if (IS_ERR(plat_dat))
  1099. return PTR_ERR(plat_dat);
  1100. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
  1101. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
  1102. @@ -407,7 +407,7 @@ static int mediatek_dwmac_probe(struct p
  1103. if (ret)
  1104. return ret;
  1105. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1106. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1107. if (IS_ERR(plat_dat))
  1108. return PTR_ERR(plat_dat);
  1109. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
  1110. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
  1111. @@ -52,7 +52,7 @@ static int meson6_dwmac_probe(struct pla
  1112. if (ret)
  1113. return ret;
  1114. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1115. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1116. if (IS_ERR(plat_dat))
  1117. return PTR_ERR(plat_dat);
  1118. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
  1119. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
  1120. @@ -372,7 +372,7 @@ static int meson8b_dwmac_probe(struct pl
  1121. if (ret)
  1122. return ret;
  1123. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1124. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1125. if (IS_ERR(plat_dat))
  1126. return PTR_ERR(plat_dat);
  1127. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
  1128. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
  1129. @@ -118,7 +118,7 @@ static int oxnas_dwmac_probe(struct plat
  1130. if (ret)
  1131. return ret;
  1132. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1133. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1134. if (IS_ERR(plat_dat))
  1135. return PTR_ERR(plat_dat);
  1136. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
  1137. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
  1138. @@ -461,7 +461,7 @@ static int qcom_ethqos_probe(struct plat
  1139. if (ret)
  1140. return ret;
  1141. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1142. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1143. if (IS_ERR(plat_dat)) {
  1144. dev_err(&pdev->dev, "dt configuration failed\n");
  1145. return PTR_ERR(plat_dat);
  1146. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
  1147. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
  1148. @@ -1396,7 +1396,7 @@ static int rk_gmac_probe(struct platform
  1149. if (ret)
  1150. return ret;
  1151. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1152. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1153. if (IS_ERR(plat_dat))
  1154. return PTR_ERR(plat_dat);
  1155. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
  1156. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
  1157. @@ -398,7 +398,7 @@ static int socfpga_dwmac_probe(struct pl
  1158. if (ret)
  1159. return ret;
  1160. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1161. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1162. if (IS_ERR(plat_dat))
  1163. return PTR_ERR(plat_dat);
  1164. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
  1165. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
  1166. @@ -325,7 +325,7 @@ static int sti_dwmac_probe(struct platfo
  1167. if (ret)
  1168. return ret;
  1169. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1170. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1171. if (IS_ERR(plat_dat))
  1172. return PTR_ERR(plat_dat);
  1173. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
  1174. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
  1175. @@ -371,7 +371,7 @@ static int stm32_dwmac_probe(struct plat
  1176. if (ret)
  1177. return ret;
  1178. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1179. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1180. if (IS_ERR(plat_dat))
  1181. return PTR_ERR(plat_dat);
  1182. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
  1183. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
  1184. @@ -1202,7 +1202,7 @@ static int sun8i_dwmac_probe(struct plat
  1185. if (ret)
  1186. return -EINVAL;
  1187. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1188. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1189. if (IS_ERR(plat_dat))
  1190. return PTR_ERR(plat_dat);
  1191. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
  1192. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
  1193. @@ -108,7 +108,7 @@ static int sun7i_gmac_probe(struct platf
  1194. if (ret)
  1195. return ret;
  1196. - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1197. + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  1198. if (IS_ERR(plat_dat))
  1199. return PTR_ERR(plat_dat);
  1200. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
  1201. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
  1202. @@ -25,7 +25,7 @@
  1203. struct stmmac_resources {
  1204. void __iomem *addr;
  1205. - const char *mac;
  1206. + u8 mac[ETH_ALEN];
  1207. int wol_irq;
  1208. int lpi_irq;
  1209. int irq;
  1210. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
  1211. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
  1212. @@ -4904,7 +4904,7 @@ int stmmac_dvr_probe(struct device *devi
  1213. priv->wol_irq = res->wol_irq;
  1214. priv->lpi_irq = res->lpi_irq;
  1215. - if (!IS_ERR_OR_NULL(res->mac))
  1216. + if (!is_zero_ether_addr(res->mac))
  1217. memcpy(priv->dev->dev_addr, res->mac, ETH_ALEN);
  1218. dev_set_drvdata(device, priv->dev);
  1219. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
  1220. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
  1221. @@ -394,7 +394,7 @@ static int stmmac_of_get_mac_mode(struct
  1222. * set some private fields that will be used by the main at runtime.
  1223. */
  1224. struct plat_stmmacenet_data *
  1225. -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
  1226. +stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
  1227. {
  1228. struct device_node *np = pdev->dev.of_node;
  1229. struct plat_stmmacenet_data *plat;
  1230. @@ -406,12 +406,12 @@ stmmac_probe_config_dt(struct platform_d
  1231. if (!plat)
  1232. return ERR_PTR(-ENOMEM);
  1233. - *mac = of_get_mac_address(np);
  1234. - if (IS_ERR(*mac)) {
  1235. - if (PTR_ERR(*mac) == -EPROBE_DEFER)
  1236. - return ERR_CAST(*mac);
  1237. + rc = of_get_mac_address(np, mac);
  1238. + if (rc) {
  1239. + if (rc == -EPROBE_DEFER)
  1240. + return ERR_PTR(rc);
  1241. - *mac = NULL;
  1242. + eth_zero_addr(mac);
  1243. }
  1244. phy_mode = device_get_phy_mode(&pdev->dev);
  1245. @@ -643,7 +643,7 @@ void stmmac_remove_config_dt(struct plat
  1246. }
  1247. #else
  1248. struct plat_stmmacenet_data *
  1249. -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
  1250. +stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
  1251. {
  1252. return ERR_PTR(-EINVAL);
  1253. }
  1254. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
  1255. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
  1256. @@ -12,7 +12,7 @@
  1257. #include "stmmac.h"
  1258. struct plat_stmmacenet_data *
  1259. -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac);
  1260. +stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac);
  1261. void stmmac_remove_config_dt(struct platform_device *pdev,
  1262. struct plat_stmmacenet_data *plat);
  1263. --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
  1264. +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
  1265. @@ -1741,7 +1741,6 @@ static int am65_cpsw_nuss_init_slave_por
  1266. for_each_child_of_node(node, port_np) {
  1267. struct am65_cpsw_port *port;
  1268. - const void *mac_addr;
  1269. u32 port_id;
  1270. /* it is not a slave port node, continue */
  1271. @@ -1820,15 +1819,15 @@ static int am65_cpsw_nuss_init_slave_por
  1272. return ret;
  1273. }
  1274. - mac_addr = of_get_mac_address(port_np);
  1275. - if (!IS_ERR(mac_addr)) {
  1276. - ether_addr_copy(port->slave.mac_addr, mac_addr);
  1277. - } else if (am65_cpsw_am654_get_efuse_macid(port_np,
  1278. - port->port_id,
  1279. - port->slave.mac_addr) ||
  1280. - !is_valid_ether_addr(port->slave.mac_addr)) {
  1281. - random_ether_addr(port->slave.mac_addr);
  1282. - dev_err(dev, "Use random MAC address\n");
  1283. + ret = of_get_mac_address(port_np, port->slave.mac_addr);
  1284. + if (ret) {
  1285. + am65_cpsw_am654_get_efuse_macid(port_np,
  1286. + port->port_id,
  1287. + port->slave.mac_addr);
  1288. + if (!is_valid_ether_addr(port->slave.mac_addr)) {
  1289. + random_ether_addr(port->slave.mac_addr);
  1290. + dev_err(dev, "Use random MAC address\n");
  1291. + }
  1292. }
  1293. }
  1294. of_node_put(node);
  1295. --- a/drivers/net/ethernet/ti/cpsw.c
  1296. +++ b/drivers/net/ethernet/ti/cpsw.c
  1297. @@ -1306,7 +1306,6 @@ static int cpsw_probe_dt(struct cpsw_pla
  1298. for_each_available_child_of_node(node, slave_node) {
  1299. struct cpsw_slave_data *slave_data = data->slave_data + i;
  1300. - const void *mac_addr = NULL;
  1301. int lenp;
  1302. const __be32 *parp;
  1303. @@ -1378,10 +1377,8 @@ static int cpsw_probe_dt(struct cpsw_pla
  1304. }
  1305. no_phy_slave:
  1306. - mac_addr = of_get_mac_address(slave_node);
  1307. - if (!IS_ERR(mac_addr)) {
  1308. - ether_addr_copy(slave_data->mac_addr, mac_addr);
  1309. - } else {
  1310. + ret = of_get_mac_address(slave_node, slave_data->mac_addr);
  1311. + if (ret) {
  1312. ret = ti_cm_get_macid(&pdev->dev, i,
  1313. slave_data->mac_addr);
  1314. if (ret)
  1315. --- a/drivers/net/ethernet/ti/cpsw_new.c
  1316. +++ b/drivers/net/ethernet/ti/cpsw_new.c
  1317. @@ -1267,7 +1267,6 @@ static int cpsw_probe_dt(struct cpsw_com
  1318. for_each_child_of_node(tmp_node, port_np) {
  1319. struct cpsw_slave_data *slave_data;
  1320. - const void *mac_addr;
  1321. u32 port_id;
  1322. ret = of_property_read_u32(port_np, "reg", &port_id);
  1323. @@ -1326,10 +1325,8 @@ static int cpsw_probe_dt(struct cpsw_com
  1324. goto err_node_put;
  1325. }
  1326. - mac_addr = of_get_mac_address(port_np);
  1327. - if (!IS_ERR(mac_addr)) {
  1328. - ether_addr_copy(slave_data->mac_addr, mac_addr);
  1329. - } else {
  1330. + ret = of_get_mac_address(port_np, slave_data->mac_addr);
  1331. + if (ret) {
  1332. ret = ti_cm_get_macid(dev, port_id - 1,
  1333. slave_data->mac_addr);
  1334. if (ret)
  1335. --- a/drivers/net/ethernet/ti/davinci_emac.c
  1336. +++ b/drivers/net/ethernet/ti/davinci_emac.c
  1337. @@ -1687,7 +1687,6 @@ davinci_emac_of_get_pdata(struct platfor
  1338. const struct of_device_id *match;
  1339. const struct emac_platform_data *auxdata;
  1340. struct emac_platform_data *pdata = NULL;
  1341. - const u8 *mac_addr;
  1342. if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
  1343. return dev_get_platdata(&pdev->dev);
  1344. @@ -1699,11 +1698,8 @@ davinci_emac_of_get_pdata(struct platfor
  1345. np = pdev->dev.of_node;
  1346. pdata->version = EMAC_VERSION_2;
  1347. - if (!is_valid_ether_addr(pdata->mac_addr)) {
  1348. - mac_addr = of_get_mac_address(np);
  1349. - if (!IS_ERR(mac_addr))
  1350. - ether_addr_copy(pdata->mac_addr, mac_addr);
  1351. - }
  1352. + if (!is_valid_ether_addr(pdata->mac_addr))
  1353. + of_get_mac_address(np, pdata->mac_addr);
  1354. of_property_read_u32(np, "ti,davinci-ctrl-reg-offset",
  1355. &pdata->ctrl_reg_offset);
  1356. --- a/drivers/net/ethernet/ti/netcp_core.c
  1357. +++ b/drivers/net/ethernet/ti/netcp_core.c
  1358. @@ -1966,7 +1966,6 @@ static int netcp_create_interface(struct
  1359. struct resource res;
  1360. void __iomem *efuse = NULL;
  1361. u32 efuse_mac = 0;
  1362. - const void *mac_addr;
  1363. u8 efuse_mac_addr[6];
  1364. u32 temp[2];
  1365. int ret = 0;
  1366. @@ -2036,10 +2035,8 @@ static int netcp_create_interface(struct
  1367. devm_iounmap(dev, efuse);
  1368. devm_release_mem_region(dev, res.start, size);
  1369. } else {
  1370. - mac_addr = of_get_mac_address(node_interface);
  1371. - if (!IS_ERR(mac_addr))
  1372. - ether_addr_copy(ndev->dev_addr, mac_addr);
  1373. - else
  1374. + ret = of_get_mac_address(node_interface, ndev->dev_addr);
  1375. + if (ret)
  1376. eth_random_addr(ndev->dev_addr);
  1377. }
  1378. --- a/drivers/net/ethernet/wiznet/w5100-spi.c
  1379. +++ b/drivers/net/ethernet/wiznet/w5100-spi.c
  1380. @@ -423,8 +423,14 @@ static int w5100_spi_probe(struct spi_de
  1381. const struct of_device_id *of_id;
  1382. const struct w5100_ops *ops;
  1383. kernel_ulong_t driver_data;
  1384. + const void *mac = NULL;
  1385. + u8 tmpmac[ETH_ALEN];
  1386. int priv_size;
  1387. - const void *mac = of_get_mac_address(spi->dev.of_node);
  1388. + int ret;
  1389. +
  1390. + ret = of_get_mac_address(spi->dev.of_node, tmpmac);
  1391. + if (!ret)
  1392. + mac = tmpmac;
  1393. if (spi->dev.of_node) {
  1394. of_id = of_match_device(w5100_of_match, &spi->dev);
  1395. --- a/drivers/net/ethernet/wiznet/w5100.c
  1396. +++ b/drivers/net/ethernet/wiznet/w5100.c
  1397. @@ -1159,7 +1159,7 @@ int w5100_probe(struct device *dev, cons
  1398. INIT_WORK(&priv->setrx_work, w5100_setrx_work);
  1399. INIT_WORK(&priv->restart_work, w5100_restart_work);
  1400. - if (!IS_ERR_OR_NULL(mac_addr))
  1401. + if (mac_addr)
  1402. memcpy(ndev->dev_addr, mac_addr, ETH_ALEN);
  1403. else
  1404. eth_hw_addr_random(ndev);
  1405. --- a/drivers/net/ethernet/xilinx/ll_temac_main.c
  1406. +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
  1407. @@ -438,7 +438,7 @@ static void temac_do_set_mac_address(str
  1408. static int temac_init_mac_address(struct net_device *ndev, const void *address)
  1409. {
  1410. - ether_addr_copy(ndev->dev_addr, address);
  1411. + memcpy(ndev->dev_addr, address, ETH_ALEN);
  1412. if (!is_valid_ether_addr(ndev->dev_addr))
  1413. eth_hw_addr_random(ndev);
  1414. temac_do_set_mac_address(ndev);
  1415. @@ -1370,7 +1370,7 @@ static int temac_probe(struct platform_d
  1416. struct device_node *temac_np = dev_of_node(&pdev->dev), *dma_np;
  1417. struct temac_local *lp;
  1418. struct net_device *ndev;
  1419. - const void *addr;
  1420. + u8 addr[ETH_ALEN];
  1421. __be32 *p;
  1422. bool little_endian;
  1423. int rc = 0;
  1424. @@ -1561,8 +1561,8 @@ static int temac_probe(struct platform_d
  1425. if (temac_np) {
  1426. /* Retrieve the MAC address */
  1427. - addr = of_get_mac_address(temac_np);
  1428. - if (IS_ERR(addr)) {
  1429. + rc = of_get_mac_address(temac_np, addr);
  1430. + if (rc) {
  1431. dev_err(&pdev->dev, "could not find MAC address\n");
  1432. return -ENODEV;
  1433. }
  1434. --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
  1435. +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
  1436. @@ -1803,8 +1803,8 @@ static int axienet_probe(struct platform
  1437. struct device_node *np;
  1438. struct axienet_local *lp;
  1439. struct net_device *ndev;
  1440. - const void *mac_addr;
  1441. struct resource *ethres;
  1442. + u8 mac_addr[ETH_ALEN];
  1443. int addr_width = 32;
  1444. u32 value;
  1445. @@ -2004,13 +2004,14 @@ static int axienet_probe(struct platform
  1446. dev_info(&pdev->dev, "Ethernet core IRQ not defined\n");
  1447. /* Retrieve the MAC address */
  1448. - mac_addr = of_get_mac_address(pdev->dev.of_node);
  1449. - if (IS_ERR(mac_addr)) {
  1450. - dev_warn(&pdev->dev, "could not find MAC address property: %ld\n",
  1451. - PTR_ERR(mac_addr));
  1452. - mac_addr = NULL;
  1453. + ret = of_get_mac_address(pdev->dev.of_node, mac_addr);
  1454. + if (!ret) {
  1455. + axienet_set_mac_address(ndev, mac_addr);
  1456. + } else {
  1457. + dev_warn(&pdev->dev, "could not find MAC address property: %d\n",
  1458. + ret);
  1459. + axienet_set_mac_address(ndev, NULL);
  1460. }
  1461. - axienet_set_mac_address(ndev, mac_addr);
  1462. lp->coalesce_count_rx = XAXIDMA_DFT_RX_THRESHOLD;
  1463. lp->coalesce_count_tx = XAXIDMA_DFT_TX_THRESHOLD;
  1464. --- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
  1465. +++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
  1466. @@ -1113,7 +1113,6 @@ static int xemaclite_of_probe(struct pla
  1467. struct net_device *ndev = NULL;
  1468. struct net_local *lp = NULL;
  1469. struct device *dev = &ofdev->dev;
  1470. - const void *mac_address;
  1471. int rc = 0;
  1472. @@ -1155,12 +1154,9 @@ static int xemaclite_of_probe(struct pla
  1473. lp->next_rx_buf_to_use = 0x0;
  1474. lp->tx_ping_pong = get_bool(ofdev, "xlnx,tx-ping-pong");
  1475. lp->rx_ping_pong = get_bool(ofdev, "xlnx,rx-ping-pong");
  1476. - mac_address = of_get_mac_address(ofdev->dev.of_node);
  1477. - if (!IS_ERR(mac_address)) {
  1478. - /* Set the MAC address. */
  1479. - ether_addr_copy(ndev->dev_addr, mac_address);
  1480. - } else {
  1481. + rc = of_get_mac_address(ofdev->dev.of_node, ndev->dev_addr);
  1482. + if (rc) {
  1483. dev_warn(dev, "No MAC address found, using random\n");
  1484. eth_hw_addr_random(ndev);
  1485. }
  1486. --- a/drivers/net/wireless/ath/ath9k/init.c
  1487. +++ b/drivers/net/wireless/ath/ath9k/init.c
  1488. @@ -618,7 +618,6 @@ static int ath9k_of_init(struct ath_soft
  1489. struct ath_hw *ah = sc->sc_ah;
  1490. struct ath_common *common = ath9k_hw_common(ah);
  1491. enum ath_bus_type bus_type = common->bus_ops->ath_bus_type;
  1492. - const char *mac;
  1493. char eeprom_name[100];
  1494. int ret;
  1495. @@ -641,9 +640,7 @@ static int ath9k_of_init(struct ath_soft
  1496. ah->ah_flags |= AH_NO_EEP_SWAP;
  1497. }
  1498. - mac = of_get_mac_address(np);
  1499. - if (!IS_ERR(mac))
  1500. - ether_addr_copy(common->macaddr, mac);
  1501. + of_get_mac_address(np, common->macaddr);
  1502. return 0;
  1503. }
  1504. --- a/drivers/net/wireless/mediatek/mt76/eeprom.c
  1505. +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
  1506. @@ -90,15 +90,9 @@ out_put_node:
  1507. void
  1508. mt76_eeprom_override(struct mt76_dev *dev)
  1509. {
  1510. -#ifdef CONFIG_OF
  1511. struct device_node *np = dev->dev->of_node;
  1512. - const u8 *mac = NULL;
  1513. - if (np)
  1514. - mac = of_get_mac_address(np);
  1515. - if (!IS_ERR_OR_NULL(mac))
  1516. - ether_addr_copy(dev->macaddr, mac);
  1517. -#endif
  1518. + of_get_mac_address(np, dev->macaddr);
  1519. if (!is_valid_ether_addr(dev->macaddr)) {
  1520. eth_random_addr(dev->macaddr);
  1521. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
  1522. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
  1523. @@ -990,11 +990,7 @@ static void rt2x00lib_rate(struct ieee80
  1524. void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr)
  1525. {
  1526. - const char *mac_addr;
  1527. -
  1528. - mac_addr = of_get_mac_address(rt2x00dev->dev->of_node);
  1529. - if (!IS_ERR(mac_addr))
  1530. - ether_addr_copy(eeprom_mac_addr, mac_addr);
  1531. + of_get_mac_address(rt2x00dev->dev->of_node, eeprom_mac_addr);
  1532. if (!is_valid_ether_addr(eeprom_mac_addr)) {
  1533. eth_random_addr(eeprom_mac_addr);
  1534. --- a/drivers/of/of_net.c
  1535. +++ b/drivers/of/of_net.c
  1536. @@ -45,37 +45,29 @@ int of_get_phy_mode(struct device_node *
  1537. }
  1538. EXPORT_SYMBOL_GPL(of_get_phy_mode);
  1539. -static const void *of_get_mac_addr(struct device_node *np, const char *name)
  1540. +static int of_get_mac_addr(struct device_node *np, const char *name, u8 *addr)
  1541. {
  1542. struct property *pp = of_find_property(np, name, NULL);
  1543. - if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value))
  1544. - return pp->value;
  1545. - return NULL;
  1546. + if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value)) {
  1547. + memcpy(addr, pp->value, ETH_ALEN);
  1548. + return 0;
  1549. + }
  1550. + return -ENODEV;
  1551. }
  1552. -static const void *of_get_mac_addr_nvmem(struct device_node *np)
  1553. +static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
  1554. {
  1555. - int ret;
  1556. - const void *mac;
  1557. - u8 nvmem_mac[ETH_ALEN];
  1558. struct platform_device *pdev = of_find_device_by_node(np);
  1559. + int ret;
  1560. if (!pdev)
  1561. - return ERR_PTR(-ENODEV);
  1562. + return -ENODEV;
  1563. - ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac);
  1564. - if (ret) {
  1565. - put_device(&pdev->dev);
  1566. - return ERR_PTR(ret);
  1567. - }
  1568. -
  1569. - mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL);
  1570. + ret = nvmem_get_mac_address(&pdev->dev, addr);
  1571. put_device(&pdev->dev);
  1572. - if (!mac)
  1573. - return ERR_PTR(-ENOMEM);
  1574. - return mac;
  1575. + return ret;
  1576. }
  1577. /**
  1578. @@ -98,24 +90,27 @@ static const void *of_get_mac_addr_nvmem
  1579. * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
  1580. * but is all zeros.
  1581. *
  1582. - * Return: Will be a valid pointer on success and ERR_PTR in case of error.
  1583. + * Return: 0 on success and errno in case of error.
  1584. */
  1585. -const void *of_get_mac_address(struct device_node *np)
  1586. +int of_get_mac_address(struct device_node *np, u8 *addr)
  1587. {
  1588. - const void *addr;
  1589. -
  1590. - addr = of_get_mac_addr(np, "mac-address");
  1591. - if (addr)
  1592. - return addr;
  1593. + int ret;
  1594. - addr = of_get_mac_addr(np, "local-mac-address");
  1595. - if (addr)
  1596. - return addr;
  1597. + if (!np)
  1598. + return -ENODEV;
  1599. - addr = of_get_mac_addr(np, "address");
  1600. - if (addr)
  1601. - return addr;
  1602. + ret = of_get_mac_addr(np, "mac-address", addr);
  1603. + if (!ret)
  1604. + return 0;
  1605. +
  1606. + ret = of_get_mac_addr(np, "local-mac-address", addr);
  1607. + if (!ret)
  1608. + return 0;
  1609. +
  1610. + ret = of_get_mac_addr(np, "address", addr);
  1611. + if (!ret)
  1612. + return 0;
  1613. - return of_get_mac_addr_nvmem(np);
  1614. + return of_get_mac_addr_nvmem(np, addr);
  1615. }
  1616. EXPORT_SYMBOL(of_get_mac_address);
  1617. --- a/drivers/staging/octeon/ethernet.c
  1618. +++ b/drivers/staging/octeon/ethernet.c
  1619. @@ -407,14 +407,10 @@ static int cvm_oct_common_set_mac_addres
  1620. int cvm_oct_common_init(struct net_device *dev)
  1621. {
  1622. struct octeon_ethernet *priv = netdev_priv(dev);
  1623. - const u8 *mac = NULL;
  1624. + int ret;
  1625. - if (priv->of_node)
  1626. - mac = of_get_mac_address(priv->of_node);
  1627. -
  1628. - if (!IS_ERR_OR_NULL(mac))
  1629. - ether_addr_copy(dev->dev_addr, mac);
  1630. - else
  1631. + ret = of_get_mac_address(priv->of_node, dev->dev_addr);
  1632. + if (ret)
  1633. eth_hw_addr_random(dev);
  1634. /*
  1635. --- a/drivers/staging/wfx/main.c
  1636. +++ b/drivers/staging/wfx/main.c
  1637. @@ -334,7 +334,6 @@ int wfx_probe(struct wfx_dev *wdev)
  1638. {
  1639. int i;
  1640. int err;
  1641. - const void *macaddr;
  1642. struct gpio_desc *gpio_saved;
  1643. // During first part of boot, gpio_wakeup cannot yet been used. So
  1644. @@ -423,9 +422,9 @@ int wfx_probe(struct wfx_dev *wdev)
  1645. for (i = 0; i < ARRAY_SIZE(wdev->addresses); i++) {
  1646. eth_zero_addr(wdev->addresses[i].addr);
  1647. - macaddr = of_get_mac_address(wdev->dev->of_node);
  1648. - if (!IS_ERR_OR_NULL(macaddr)) {
  1649. - ether_addr_copy(wdev->addresses[i].addr, macaddr);
  1650. + err = of_get_mac_address(wdev->dev->of_node,
  1651. + wdev->addresses[i].addr);
  1652. + if (!err) {
  1653. wdev->addresses[i].addr[ETH_ALEN - 1] += i;
  1654. } else {
  1655. ether_addr_copy(wdev->addresses[i].addr,
  1656. --- a/include/linux/of_net.h
  1657. +++ b/include/linux/of_net.h
  1658. @@ -13,7 +13,7 @@
  1659. struct net_device;
  1660. extern int of_get_phy_mode(struct device_node *np, phy_interface_t *interface);
  1661. -extern const void *of_get_mac_address(struct device_node *np);
  1662. +extern int of_get_mac_address(struct device_node *np, u8 *mac);
  1663. extern struct net_device *of_find_net_device_by_node(struct device_node *np);
  1664. #else
  1665. static inline int of_get_phy_mode(struct device_node *np,
  1666. @@ -22,9 +22,9 @@ static inline int of_get_phy_mode(struct
  1667. return -ENODEV;
  1668. }
  1669. -static inline const void *of_get_mac_address(struct device_node *np)
  1670. +static inline int of_get_mac_address(struct device_node *np, u8 *mac)
  1671. {
  1672. - return ERR_PTR(-ENODEV);
  1673. + return -ENODEV;
  1674. }
  1675. static inline struct net_device *of_find_net_device_by_node(struct device_node *np)
  1676. --- a/include/net/dsa.h
  1677. +++ b/include/net/dsa.h
  1678. @@ -208,7 +208,7 @@ struct dsa_port {
  1679. unsigned int index;
  1680. const char *name;
  1681. struct dsa_port *cpu_dp;
  1682. - const char *mac;
  1683. + u8 mac[ETH_ALEN];
  1684. struct device_node *dn;
  1685. unsigned int ageing_time;
  1686. bool vlan_filtering;
  1687. --- a/net/dsa/dsa2.c
  1688. +++ b/net/dsa/dsa2.c
  1689. @@ -288,7 +288,7 @@ static int dsa_port_setup(struct dsa_por
  1690. break;
  1691. case DSA_PORT_TYPE_USER:
  1692. - dp->mac = of_get_mac_address(dp->dn);
  1693. + of_get_mac_address(dp->dn, dp->mac);
  1694. err = dsa_slave_create(dp);
  1695. if (err)
  1696. break;
  1697. --- a/net/dsa/slave.c
  1698. +++ b/net/dsa/slave.c
  1699. @@ -1855,7 +1855,7 @@ int dsa_slave_create(struct dsa_port *po
  1700. slave_dev->hw_features |= NETIF_F_HW_TC;
  1701. slave_dev->features |= NETIF_F_LLTX;
  1702. slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
  1703. - if (!IS_ERR_OR_NULL(port->mac))
  1704. + if (!is_zero_ether_addr(port->mac))
  1705. ether_addr_copy(slave_dev->dev_addr, port->mac);
  1706. else
  1707. eth_hw_addr_inherit(slave_dev, master);
  1708. --- a/net/ethernet/eth.c
  1709. +++ b/net/ethernet/eth.c
  1710. @@ -506,13 +506,14 @@ unsigned char * __weak arch_get_platform
  1711. int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
  1712. {
  1713. - const unsigned char *addr = NULL;
  1714. + unsigned char *addr;
  1715. + int ret;
  1716. - if (dev->of_node)
  1717. - addr = of_get_mac_address(dev->of_node);
  1718. - if (IS_ERR_OR_NULL(addr))
  1719. - addr = arch_get_platform_mac_address();
  1720. + ret = of_get_mac_address(dev->of_node, mac_addr);
  1721. + if (!ret)
  1722. + return 0;
  1723. + addr = arch_get_platform_mac_address();
  1724. if (!addr)
  1725. return -ENODEV;