OSDN Git Service

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