kernel: bump 5.4 to 5.4.161
[openwrt/staging/wigyori.git] / target / linux / generic / backport-5.4 / 782-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 @@ -1451,10 +1451,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 @@ -807,7 +807,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 @@ -870,12 +869,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 @@ -1525,10 +1524,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 @@ -870,7 +870,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 @@ -955,11 +954,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 @@ -1634,7 +1634,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 @@ -1735,10 +1734,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 @@ -2420,7 +2420,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 @@ -2502,12 +2501,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 @@ -4206,7 +4206,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 @@ -4319,15 +4318,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);
452 if (err < 0)
453 --- a/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c
454 +++ b/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c
455 @@ -1391,7 +1391,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 @@ -1508,11 +1507,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 @@ -1390,7 +1390,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 @@ -1404,11 +1404,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 @@ -1147,11 +1147,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 @@ -1695,6 +1695,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 @@ -1710,9 +1711,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 @@ -823,7 +823,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 @@ -901,10 +900,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 @@ -605,7 +605,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 int phy_if;
618 @@ -723,13 +722,12 @@ 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_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
627 err = -EINVAL;
628 goto _return_of_get_parent;
629 }
630 - ether_addr_copy(mac_dev->addr, mac_addr);
631
632 /* Get the port handles */
633 nph = of_count_phandle_with_args(mac_node, "fsl,fman-ports", NULL);
634 --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
635 +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
636 @@ -925,7 +925,6 @@ static int fs_enet_probe(struct platform
637 const u32 *data;
638 struct clk *clk;
639 int err;
640 - const u8 *mac_addr;
641 const char *phy_connection_type;
642 int privsize, len, ret = -ENODEV;
643
644 @@ -1013,9 +1012,7 @@ static int fs_enet_probe(struct platform
645 spin_lock_init(&fep->lock);
646 spin_lock_init(&fep->tx_lock);
647
648 - mac_addr = of_get_mac_address(ofdev->dev.of_node);
649 - if (!IS_ERR(mac_addr))
650 - ether_addr_copy(ndev->dev_addr, mac_addr);
651 + of_get_mac_address(ofdev->dev.of_node, ndev->dev_addr);
652
653 ret = fep->ops->allocate_bd(ndev);
654 if (ret)
655 --- a/drivers/net/ethernet/freescale/gianfar.c
656 +++ b/drivers/net/ethernet/freescale/gianfar.c
657 @@ -643,7 +643,6 @@ static phy_interface_t gfar_get_interfac
658 static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
659 {
660 const char *model;
661 - const void *mac_addr;
662 int err = 0, i;
663 struct net_device *dev = NULL;
664 struct gfar_private *priv = NULL;
665 @@ -784,10 +783,7 @@ static int gfar_of_init(struct platform_
666 if (stash_len || stash_idx)
667 priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
668
669 - mac_addr = of_get_mac_address(np);
670 -
671 - if (!IS_ERR(mac_addr))
672 - ether_addr_copy(dev->dev_addr, mac_addr);
673 + err = of_get_mac_address(np, dev->dev_addr);
674
675 if (model && !strcasecmp(model, "TSEC"))
676 priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
677 --- a/drivers/net/ethernet/freescale/ucc_geth.c
678 +++ b/drivers/net/ethernet/freescale/ucc_geth.c
679 @@ -3697,7 +3697,6 @@ static int ucc_geth_probe(struct platfor
680 int err, ucc_num, max_speed = 0;
681 const unsigned int *prop;
682 const char *sprop;
683 - const void *mac_addr;
684 phy_interface_t phy_interface;
685 static const int enet_to_speed[] = {
686 SPEED_10, SPEED_10, SPEED_10,
687 @@ -3907,9 +3906,7 @@ static int ucc_geth_probe(struct platfor
688 goto err_free_netdev;
689 }
690
691 - mac_addr = of_get_mac_address(np);
692 - if (!IS_ERR(mac_addr))
693 - ether_addr_copy(dev->dev_addr, mac_addr);
694 + of_get_mac_address(np, dev->dev_addr);
695
696 ugeth->ug_info = ug_info;
697 ugeth->dev = device;
698 --- a/drivers/net/ethernet/hisilicon/hisi_femac.c
699 +++ b/drivers/net/ethernet/hisilicon/hisi_femac.c
700 @@ -784,7 +784,6 @@ static int hisi_femac_drv_probe(struct p
701 struct net_device *ndev;
702 struct hisi_femac_priv *priv;
703 struct phy_device *phy;
704 - const char *mac_addr;
705 int ret;
706
707 ndev = alloc_etherdev(sizeof(*priv));
708 @@ -854,10 +853,8 @@ static int hisi_femac_drv_probe(struct p
709 (unsigned long)phy->phy_id,
710 phy_modes(phy->interface));
711
712 - mac_addr = of_get_mac_address(node);
713 - if (!IS_ERR(mac_addr))
714 - ether_addr_copy(ndev->dev_addr, mac_addr);
715 - if (!is_valid_ether_addr(ndev->dev_addr)) {
716 + ret = of_get_mac_address(node, ndev->dev_addr);
717 + if (ret) {
718 eth_hw_addr_random(ndev);
719 dev_warn(dev, "using random MAC address %pM\n",
720 ndev->dev_addr);
721 --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
722 +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
723 @@ -1098,7 +1098,6 @@ static int hix5hd2_dev_probe(struct plat
724 struct net_device *ndev;
725 struct hix5hd2_priv *priv;
726 struct mii_bus *bus;
727 - const char *mac_addr;
728 int ret;
729
730 ndev = alloc_etherdev(sizeof(struct hix5hd2_priv));
731 @@ -1221,10 +1220,8 @@ static int hix5hd2_dev_probe(struct plat
732 goto out_phy_node;
733 }
734
735 - mac_addr = of_get_mac_address(node);
736 - if (!IS_ERR(mac_addr))
737 - ether_addr_copy(ndev->dev_addr, mac_addr);
738 - if (!is_valid_ether_addr(ndev->dev_addr)) {
739 + ret = of_get_mac_address(node, ndev->dev_addr);
740 + if (ret) {
741 eth_hw_addr_random(ndev);
742 netdev_warn(ndev, "using random MAC address %pM\n",
743 ndev->dev_addr);
744 --- a/drivers/net/ethernet/lantiq_xrx200.c
745 +++ b/drivers/net/ethernet/lantiq_xrx200.c
746 @@ -439,7 +439,6 @@ static int xrx200_probe(struct platform_
747 struct resource *res;
748 struct xrx200_priv *priv;
749 struct net_device *net_dev;
750 - const u8 *mac;
751 int err;
752
753 /* alloc the network device */
754 @@ -483,10 +482,8 @@ static int xrx200_probe(struct platform_
755 return PTR_ERR(priv->clk);
756 }
757
758 - mac = of_get_mac_address(np);
759 - if (!IS_ERR(mac))
760 - ether_addr_copy(net_dev->dev_addr, mac);
761 - else
762 + err = of_get_mac_address(np, net_dev->dev_addr);
763 + if (err)
764 eth_hw_addr_random(net_dev);
765
766 /* bring up the dma engine and IP core */
767 --- a/drivers/net/ethernet/marvell/mv643xx_eth.c
768 +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
769 @@ -2705,7 +2705,6 @@ static int mv643xx_eth_shared_of_add_por
770 struct platform_device *ppdev;
771 struct mv643xx_eth_platform_data ppd;
772 struct resource res;
773 - const char *mac_addr;
774 int ret;
775 int dev_num = 0;
776
777 @@ -2736,9 +2735,7 @@ static int mv643xx_eth_shared_of_add_por
778 return -EINVAL;
779 }
780
781 - mac_addr = of_get_mac_address(pnp);
782 - if (!IS_ERR(mac_addr))
783 - ether_addr_copy(ppd.mac_addr, mac_addr);
784 + of_get_mac_address(pnp, ppd.mac_addr);
785
786 mv643xx_eth_property(pnp, "tx-queue-size", ppd.tx_queue_size);
787 mv643xx_eth_property(pnp, "tx-sram-addr", ppd.tx_sram_addr);
788 --- a/drivers/net/ethernet/marvell/mvneta.c
789 +++ b/drivers/net/ethernet/marvell/mvneta.c
790 @@ -4526,7 +4526,6 @@ static int mvneta_probe(struct platform_
791 struct net_device *dev;
792 struct phylink *phylink;
793 struct phy *comphy;
794 - const char *dt_mac_addr;
795 char hw_mac_addr[ETH_ALEN];
796 const char *mac_from;
797 int tx_csum_limit;
798 @@ -4623,10 +4622,9 @@ static int mvneta_probe(struct platform_
799 goto err_free_ports;
800 }
801
802 - dt_mac_addr = of_get_mac_address(dn);
803 - if (!IS_ERR(dt_mac_addr)) {
804 + err = of_get_mac_address(dn, dev->dev_addr);
805 + if (!err) {
806 mac_from = "device tree";
807 - ether_addr_copy(dev->dev_addr, dt_mac_addr);
808 } else {
809 mvneta_get_mac_addr(pp, hw_mac_addr);
810 if (is_valid_ether_addr(hw_mac_addr)) {
811 --- a/drivers/net/ethernet/marvell/pxa168_eth.c
812 +++ b/drivers/net/ethernet/marvell/pxa168_eth.c
813 @@ -1402,7 +1402,6 @@ static int pxa168_eth_probe(struct platf
814 struct resource *res;
815 struct clk *clk;
816 struct device_node *np;
817 - const unsigned char *mac_addr = NULL;
818 int err;
819
820 printk(KERN_NOTICE "PXA168 10/100 Ethernet Driver\n");
821 @@ -1445,12 +1444,8 @@ static int pxa168_eth_probe(struct platf
822
823 INIT_WORK(&pep->tx_timeout_task, pxa168_eth_tx_timeout_task);
824
825 - if (pdev->dev.of_node)
826 - mac_addr = of_get_mac_address(pdev->dev.of_node);
827 -
828 - if (!IS_ERR_OR_NULL(mac_addr)) {
829 - ether_addr_copy(dev->dev_addr, mac_addr);
830 - } else {
831 + err = of_get_mac_address(pdev->dev.of_node, dev->dev_addr);
832 + if (err) {
833 /* try reading the mac address, if set by the bootloader */
834 pxa168_eth_get_mac_address(dev, dev->dev_addr);
835 if (!is_valid_ether_addr(dev->dev_addr)) {
836 --- a/drivers/net/ethernet/marvell/sky2.c
837 +++ b/drivers/net/ethernet/marvell/sky2.c
838 @@ -4721,7 +4721,7 @@ static struct net_device *sky2_init_netd
839 {
840 struct sky2_port *sky2;
841 struct net_device *dev = alloc_etherdev(sizeof(*sky2));
842 - const void *iap;
843 + int ret;
844
845 if (!dev)
846 return NULL;
847 @@ -4791,10 +4791,8 @@ static struct net_device *sky2_init_netd
848 * 1) from device tree data
849 * 2) from internal registers set by bootloader
850 */
851 - iap = of_get_mac_address(hw->pdev->dev.of_node);
852 - if (!IS_ERR(iap))
853 - ether_addr_copy(dev->dev_addr, iap);
854 - else
855 + ret = of_get_mac_address(hw->pdev->dev.of_node, dev->dev_addr);
856 + if (ret)
857 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8,
858 ETH_ALEN);
859
860 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
861 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
862 @@ -2490,14 +2490,11 @@ static int __init mtk_init(struct net_de
863 {
864 struct mtk_mac *mac = netdev_priv(dev);
865 struct mtk_eth *eth = mac->hw;
866 - const char *mac_addr;
867 + int ret;
868
869 - mac_addr = of_get_mac_address(mac->of_node);
870 - if (!IS_ERR(mac_addr))
871 - ether_addr_copy(dev->dev_addr, mac_addr);
872 -
873 - /* If the mac address is invalid, use random mac address */
874 - if (!is_valid_ether_addr(dev->dev_addr)) {
875 + ret = of_get_mac_address(mac->of_node, dev->dev_addr);
876 + if (ret) {
877 + /* If the mac address is invalid, use random mac address */
878 eth_hw_addr_random(dev);
879 dev_err(eth->dev, "generated random MAC address %pM\n",
880 dev->dev_addr);
881 --- a/drivers/net/ethernet/micrel/ks8851.c
882 +++ b/drivers/net/ethernet/micrel/ks8851.c
883 @@ -419,11 +419,10 @@ static void ks8851_read_mac_addr(struct
884 static void ks8851_init_mac(struct ks8851_net *ks)
885 {
886 struct net_device *dev = ks->netdev;
887 - const u8 *mac_addr;
888 + int ret;
889
890 - mac_addr = of_get_mac_address(ks->spidev->dev.of_node);
891 - if (!IS_ERR(mac_addr)) {
892 - ether_addr_copy(dev->dev_addr, mac_addr);
893 + ret = of_get_mac_address(ks->spidev->dev.of_node, dev->dev_addr);
894 + if (!ret) {
895 ks8851_write_mac_addr(dev);
896 return;
897 }
898 --- a/drivers/net/ethernet/micrel/ks8851_mll.c
899 +++ b/drivers/net/ethernet/micrel/ks8851_mll.c
900 @@ -1239,7 +1239,6 @@ static int ks8851_probe(struct platform_
901 struct net_device *netdev;
902 struct ks_net *ks;
903 u16 id, data;
904 - const char *mac;
905
906 netdev = alloc_etherdev(sizeof(struct ks_net));
907 if (!netdev)
908 @@ -1326,9 +1325,7 @@ static int ks8851_probe(struct platform_
909
910 /* overwriting the default MAC address */
911 if (pdev->dev.of_node) {
912 - mac = of_get_mac_address(pdev->dev.of_node);
913 - if (!IS_ERR(mac))
914 - ether_addr_copy(ks->mac_addr, mac);
915 + of_get_mac_address(pdev->dev.of_node, ks->mac_addr);
916 } else {
917 struct ks8851_mll_platform_data *pdata;
918
919 --- a/drivers/net/ethernet/nxp/lpc_eth.c
920 +++ b/drivers/net/ethernet/nxp/lpc_eth.c
921 @@ -1349,9 +1349,7 @@ static int lpc_eth_drv_probe(struct plat
922 __lpc_get_mac(pldat, ndev->dev_addr);
923
924 if (!is_valid_ether_addr(ndev->dev_addr)) {
925 - const char *macaddr = of_get_mac_address(np);
926 - if (!IS_ERR(macaddr))
927 - ether_addr_copy(ndev->dev_addr, macaddr);
928 + of_get_mac_address(np, ndev->dev_addr);
929 }
930 if (!is_valid_ether_addr(ndev->dev_addr))
931 eth_hw_addr_random(ndev);
932 --- a/drivers/net/ethernet/qualcomm/qca_spi.c
933 +++ b/drivers/net/ethernet/qualcomm/qca_spi.c
934 @@ -885,7 +885,7 @@ qca_spi_probe(struct spi_device *spi)
935 struct net_device *qcaspi_devs = NULL;
936 u8 legacy_mode = 0;
937 u16 signature;
938 - const char *mac;
939 + int ret;
940
941 if (!spi->dev.of_node) {
942 dev_err(&spi->dev, "Missing device tree\n");
943 @@ -962,12 +962,8 @@ qca_spi_probe(struct spi_device *spi)
944
945 spi_set_drvdata(spi, qcaspi_devs);
946
947 - mac = of_get_mac_address(spi->dev.of_node);
948 -
949 - if (!IS_ERR(mac))
950 - ether_addr_copy(qca->net_dev->dev_addr, mac);
951 -
952 - if (!is_valid_ether_addr(qca->net_dev->dev_addr)) {
953 + ret = of_get_mac_address(spi->dev.of_node, qca->net_dev->dev_addr);
954 + if (ret) {
955 eth_hw_addr_random(qca->net_dev);
956 dev_info(&spi->dev, "Using random MAC address: %pM\n",
957 qca->net_dev->dev_addr);
958 --- a/drivers/net/ethernet/qualcomm/qca_uart.c
959 +++ b/drivers/net/ethernet/qualcomm/qca_uart.c
960 @@ -323,7 +323,6 @@ static int qca_uart_probe(struct serdev_
961 {
962 struct net_device *qcauart_dev = alloc_etherdev(sizeof(struct qcauart));
963 struct qcauart *qca;
964 - const char *mac;
965 u32 speed = 115200;
966 int ret;
967
968 @@ -348,12 +347,8 @@ static int qca_uart_probe(struct serdev_
969
970 of_property_read_u32(serdev->dev.of_node, "current-speed", &speed);
971
972 - mac = of_get_mac_address(serdev->dev.of_node);
973 -
974 - if (!IS_ERR(mac))
975 - ether_addr_copy(qca->net_dev->dev_addr, mac);
976 -
977 - if (!is_valid_ether_addr(qca->net_dev->dev_addr)) {
978 + ret = of_get_mac_address(serdev->dev.of_node, qca->net_dev->dev_addr);
979 + if (ret) {
980 eth_hw_addr_random(qca->net_dev);
981 dev_info(&serdev->dev, "Using random MAC address: %pM\n",
982 qca->net_dev->dev_addr);
983 --- a/drivers/net/ethernet/renesas/ravb_main.c
984 +++ b/drivers/net/ethernet/renesas/ravb_main.c
985 @@ -109,11 +109,13 @@ static void ravb_set_buffer_align(struct
986 * Ethernet AVB device doesn't have ROM for MAC address.
987 * This function gets the MAC address that was used by a bootloader.
988 */
989 -static void ravb_read_mac_address(struct net_device *ndev, const u8 *mac)
990 +static void ravb_read_mac_address(struct device_node *np,
991 + struct net_device *ndev)
992 {
993 - if (!IS_ERR(mac)) {
994 - ether_addr_copy(ndev->dev_addr, mac);
995 - } else {
996 + int ret;
997 +
998 + ret = of_get_mac_address(np, ndev->dev_addr);
999 + if (ret) {
1000 u32 mahr = ravb_read(ndev, MAHR);
1001 u32 malr = ravb_read(ndev, MALR);
1002
1003 @@ -2152,7 +2154,7 @@ static int ravb_probe(struct platform_de
1004 priv->msg_enable = RAVB_DEF_MSG_ENABLE;
1005
1006 /* Read and set MAC address */
1007 - ravb_read_mac_address(ndev, of_get_mac_address(np));
1008 + ravb_read_mac_address(np, ndev);
1009 if (!is_valid_ether_addr(ndev->dev_addr)) {
1010 dev_warn(&pdev->dev,
1011 "no valid MAC address supplied, using a random one\n");
1012 --- a/drivers/net/ethernet/renesas/sh_eth.c
1013 +++ b/drivers/net/ethernet/renesas/sh_eth.c
1014 @@ -3195,7 +3195,6 @@ static struct sh_eth_plat_data *sh_eth_p
1015 {
1016 struct device_node *np = dev->of_node;
1017 struct sh_eth_plat_data *pdata;
1018 - const char *mac_addr;
1019 int ret;
1020
1021 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
1022 @@ -3207,9 +3206,7 @@ static struct sh_eth_plat_data *sh_eth_p
1023 return NULL;
1024 pdata->phy_interface = ret;
1025
1026 - mac_addr = of_get_mac_address(np);
1027 - if (!IS_ERR(mac_addr))
1028 - ether_addr_copy(pdata->mac_addr, mac_addr);
1029 + of_get_mac_address(np, pdata->mac_addr);
1030
1031 pdata->no_ether_link =
1032 of_property_read_bool(np, "renesas,no-ether-link");
1033 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
1034 +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
1035 @@ -25,8 +25,7 @@
1036
1037 #ifdef CONFIG_OF
1038 static int sxgbe_probe_config_dt(struct platform_device *pdev,
1039 - struct sxgbe_plat_data *plat,
1040 - const char **mac)
1041 + struct sxgbe_plat_data *plat)
1042 {
1043 struct device_node *np = pdev->dev.of_node;
1044 struct sxgbe_dma_cfg *dma_cfg;
1045 @@ -34,7 +33,6 @@ static int sxgbe_probe_config_dt(struct
1046 if (!np)
1047 return -ENODEV;
1048
1049 - *mac = of_get_mac_address(np);
1050 plat->interface = of_get_phy_mode(np);
1051
1052 plat->bus_id = of_alias_get_id(np, "ethernet");
1053 @@ -60,8 +58,7 @@ static int sxgbe_probe_config_dt(struct
1054 }
1055 #else
1056 static int sxgbe_probe_config_dt(struct platform_device *pdev,
1057 - struct sxgbe_plat_data *plat,
1058 - const char **mac)
1059 + struct sxgbe_plat_data *plat)
1060 {
1061 return -ENOSYS;
1062 }
1063 @@ -82,7 +79,6 @@ static int sxgbe_platform_probe(struct p
1064 void __iomem *addr;
1065 struct sxgbe_priv_data *priv = NULL;
1066 struct sxgbe_plat_data *plat_dat = NULL;
1067 - const char *mac = NULL;
1068 struct net_device *ndev = platform_get_drvdata(pdev);
1069 struct device_node *node = dev->of_node;
1070
1071 @@ -98,7 +94,7 @@ static int sxgbe_platform_probe(struct p
1072 if (!plat_dat)
1073 return -ENOMEM;
1074
1075 - ret = sxgbe_probe_config_dt(pdev, plat_dat, &mac);
1076 + ret = sxgbe_probe_config_dt(pdev, plat_dat);
1077 if (ret) {
1078 pr_err("%s: main dt probe failed\n", __func__);
1079 return ret;
1080 @@ -119,8 +115,7 @@ static int sxgbe_platform_probe(struct p
1081 }
1082
1083 /* Get MAC address if available (DT) */
1084 - if (!IS_ERR_OR_NULL(mac))
1085 - ether_addr_copy(priv->dev->dev_addr, mac);
1086 + of_get_mac_address(node, priv->dev->dev_addr);
1087
1088 /* Get the TX/RX IRQ numbers */
1089 for (i = 0, chan = 1; i < SXGBE_TX_QUEUES; i++) {
1090 --- a/drivers/net/ethernet/socionext/sni_ave.c
1091 +++ b/drivers/net/ethernet/socionext/sni_ave.c
1092 @@ -1559,7 +1559,6 @@ static int ave_probe(struct platform_dev
1093 struct ave_private *priv;
1094 struct net_device *ndev;
1095 struct device_node *np;
1096 - const void *mac_addr;
1097 void __iomem *base;
1098 const char *name;
1099 int i, irq, ret;
1100 @@ -1600,12 +1599,9 @@ static int ave_probe(struct platform_dev
1101
1102 ndev->max_mtu = AVE_MAX_ETHFRAME - (ETH_HLEN + ETH_FCS_LEN);
1103
1104 - mac_addr = of_get_mac_address(np);
1105 - if (!IS_ERR(mac_addr))
1106 - ether_addr_copy(ndev->dev_addr, mac_addr);
1107 -
1108 - /* if the mac address is invalid, use random mac address */
1109 - if (!is_valid_ether_addr(ndev->dev_addr)) {
1110 + ret = of_get_mac_address(np, ndev->dev_addr);
1111 + if (ret) {
1112 + /* if the mac address is invalid, use random mac address */
1113 eth_hw_addr_random(ndev);
1114 dev_warn(dev, "Using random MAC address: %pM\n",
1115 ndev->dev_addr);
1116 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c
1117 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c
1118 @@ -110,7 +110,7 @@ static int anarion_dwmac_probe(struct pl
1119 if (IS_ERR(gmac))
1120 return PTR_ERR(gmac);
1121
1122 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1123 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1124 if (IS_ERR(plat_dat))
1125 return PTR_ERR(plat_dat);
1126
1127 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
1128 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
1129 @@ -438,7 +438,7 @@ static int dwc_eth_dwmac_probe(struct pl
1130 if (IS_ERR(stmmac_res.addr))
1131 return PTR_ERR(stmmac_res.addr);
1132
1133 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1134 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1135 if (IS_ERR(plat_dat))
1136 return PTR_ERR(plat_dat);
1137
1138 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
1139 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
1140 @@ -27,7 +27,7 @@ static int dwmac_generic_probe(struct pl
1141 return ret;
1142
1143 if (pdev->dev.of_node) {
1144 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1145 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1146 if (IS_ERR(plat_dat)) {
1147 dev_err(&pdev->dev, "dt configuration failed\n");
1148 return PTR_ERR(plat_dat);
1149 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
1150 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
1151 @@ -254,7 +254,7 @@ static int ipq806x_gmac_probe(struct pla
1152 if (val)
1153 return val;
1154
1155 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1156 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1157 if (IS_ERR(plat_dat))
1158 return PTR_ERR(plat_dat);
1159
1160 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
1161 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
1162 @@ -37,7 +37,7 @@ static int lpc18xx_dwmac_probe(struct pl
1163 if (ret)
1164 return ret;
1165
1166 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1167 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1168 if (IS_ERR(plat_dat))
1169 return PTR_ERR(plat_dat);
1170
1171 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
1172 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
1173 @@ -348,7 +348,7 @@ static int mediatek_dwmac_probe(struct p
1174 if (ret)
1175 return ret;
1176
1177 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1178 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1179 if (IS_ERR(plat_dat))
1180 return PTR_ERR(plat_dat);
1181
1182 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
1183 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
1184 @@ -52,7 +52,7 @@ static int meson6_dwmac_probe(struct pla
1185 if (ret)
1186 return ret;
1187
1188 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1189 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1190 if (IS_ERR(plat_dat))
1191 return PTR_ERR(plat_dat);
1192
1193 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
1194 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
1195 @@ -324,7 +324,7 @@ static int meson8b_dwmac_probe(struct pl
1196 if (ret)
1197 return ret;
1198
1199 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1200 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1201 if (IS_ERR(plat_dat))
1202 return PTR_ERR(plat_dat);
1203
1204 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
1205 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
1206 @@ -118,7 +118,7 @@ static int oxnas_dwmac_probe(struct plat
1207 if (ret)
1208 return ret;
1209
1210 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1211 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1212 if (IS_ERR(plat_dat))
1213 return PTR_ERR(plat_dat);
1214
1215 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
1216 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
1217 @@ -461,7 +461,7 @@ static int qcom_ethqos_probe(struct plat
1218 if (ret)
1219 return ret;
1220
1221 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1222 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1223 if (IS_ERR(plat_dat)) {
1224 dev_err(&pdev->dev, "dt configuration failed\n");
1225 return PTR_ERR(plat_dat);
1226 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
1227 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
1228 @@ -1396,7 +1396,7 @@ static int rk_gmac_probe(struct platform
1229 if (ret)
1230 return ret;
1231
1232 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1233 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1234 if (IS_ERR(plat_dat))
1235 return PTR_ERR(plat_dat);
1236
1237 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
1238 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
1239 @@ -398,7 +398,7 @@ static int socfpga_dwmac_probe(struct pl
1240 if (ret)
1241 return ret;
1242
1243 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1244 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1245 if (IS_ERR(plat_dat))
1246 return PTR_ERR(plat_dat);
1247
1248 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
1249 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
1250 @@ -320,7 +320,7 @@ static int sti_dwmac_probe(struct platfo
1251 if (ret)
1252 return ret;
1253
1254 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1255 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1256 if (IS_ERR(plat_dat))
1257 return PTR_ERR(plat_dat);
1258
1259 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
1260 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
1261 @@ -364,7 +364,7 @@ static int stm32_dwmac_probe(struct plat
1262 if (ret)
1263 return ret;
1264
1265 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1266 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1267 if (IS_ERR(plat_dat))
1268 return PTR_ERR(plat_dat);
1269
1270 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
1271 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
1272 @@ -1127,7 +1127,7 @@ static int sun8i_dwmac_probe(struct plat
1273 if (ret)
1274 return ret;
1275
1276 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1277 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1278 if (IS_ERR(plat_dat))
1279 return PTR_ERR(plat_dat);
1280
1281 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
1282 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
1283 @@ -108,7 +108,7 @@ static int sun7i_gmac_probe(struct platf
1284 if (ret)
1285 return ret;
1286
1287 - plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
1288 + plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
1289 if (IS_ERR(plat_dat))
1290 return PTR_ERR(plat_dat);
1291
1292 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
1293 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
1294 @@ -25,7 +25,7 @@
1295
1296 struct stmmac_resources {
1297 void __iomem *addr;
1298 - const char *mac;
1299 + u8 mac[ETH_ALEN];
1300 int wol_irq;
1301 int lpi_irq;
1302 int irq;
1303 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
1304 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
1305 @@ -4471,7 +4471,7 @@ int stmmac_dvr_probe(struct device *devi
1306 priv->wol_irq = res->wol_irq;
1307 priv->lpi_irq = res->lpi_irq;
1308
1309 - if (!IS_ERR_OR_NULL(res->mac))
1310 + if (!is_zero_ether_addr(res->mac))
1311 memcpy(priv->dev->dev_addr, res->mac, ETH_ALEN);
1312
1313 dev_set_drvdata(device, priv->dev);
1314 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
1315 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
1316 @@ -393,7 +393,7 @@ static int stmmac_of_get_mac_mode(struct
1317 * set some private fields that will be used by the main at runtime.
1318 */
1319 struct plat_stmmacenet_data *
1320 -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
1321 +stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
1322 {
1323 struct device_node *np = pdev->dev.of_node;
1324 struct plat_stmmacenet_data *plat;
1325 @@ -404,12 +404,12 @@ stmmac_probe_config_dt(struct platform_d
1326 if (!plat)
1327 return ERR_PTR(-ENOMEM);
1328
1329 - *mac = of_get_mac_address(np);
1330 - if (IS_ERR(*mac)) {
1331 - if (PTR_ERR(*mac) == -EPROBE_DEFER)
1332 - return ERR_CAST(*mac);
1333 + rc = of_get_mac_address(np, mac);
1334 + if (rc) {
1335 + if (rc == -EPROBE_DEFER)
1336 + return ERR_PTR(rc);
1337
1338 - *mac = NULL;
1339 + eth_zero_addr(mac);
1340 }
1341
1342 plat->phy_interface = of_get_phy_mode(np);
1343 @@ -639,7 +639,7 @@ void stmmac_remove_config_dt(struct plat
1344 }
1345 #else
1346 struct plat_stmmacenet_data *
1347 -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
1348 +stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
1349 {
1350 return ERR_PTR(-EINVAL);
1351 }
1352 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
1353 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
1354 @@ -12,7 +12,7 @@
1355 #include "stmmac.h"
1356
1357 struct plat_stmmacenet_data *
1358 -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac);
1359 +stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac);
1360 void stmmac_remove_config_dt(struct platform_device *pdev,
1361 struct plat_stmmacenet_data *plat);
1362
1363 --- a/drivers/net/ethernet/ti/cpsw.c
1364 +++ b/drivers/net/ethernet/ti/cpsw.c
1365 @@ -2555,7 +2555,6 @@ static int cpsw_probe_dt(struct cpsw_pla
1366
1367 for_each_available_child_of_node(node, slave_node) {
1368 struct cpsw_slave_data *slave_data = data->slave_data + i;
1369 - const void *mac_addr = NULL;
1370 int lenp;
1371 const __be32 *parp;
1372
1373 @@ -2628,10 +2627,8 @@ static int cpsw_probe_dt(struct cpsw_pla
1374 }
1375
1376 no_phy_slave:
1377 - mac_addr = of_get_mac_address(slave_node);
1378 - if (!IS_ERR(mac_addr)) {
1379 - ether_addr_copy(slave_data->mac_addr, mac_addr);
1380 - } else {
1381 + ret = of_get_mac_address(slave_node, slave_data->mac_addr);
1382 + if (ret) {
1383 ret = ti_cm_get_macid(&pdev->dev, i,
1384 slave_data->mac_addr);
1385 if (ret)
1386 --- a/drivers/net/ethernet/ti/davinci_emac.c
1387 +++ b/drivers/net/ethernet/ti/davinci_emac.c
1388 @@ -1697,7 +1697,6 @@ davinci_emac_of_get_pdata(struct platfor
1389 const struct of_device_id *match;
1390 const struct emac_platform_data *auxdata;
1391 struct emac_platform_data *pdata = NULL;
1392 - const u8 *mac_addr;
1393
1394 if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
1395 return dev_get_platdata(&pdev->dev);
1396 @@ -1709,11 +1708,8 @@ davinci_emac_of_get_pdata(struct platfor
1397 np = pdev->dev.of_node;
1398 pdata->version = EMAC_VERSION_2;
1399
1400 - if (!is_valid_ether_addr(pdata->mac_addr)) {
1401 - mac_addr = of_get_mac_address(np);
1402 - if (!IS_ERR(mac_addr))
1403 - ether_addr_copy(pdata->mac_addr, mac_addr);
1404 - }
1405 + if (!is_valid_ether_addr(pdata->mac_addr))
1406 + of_get_mac_address(np, pdata->mac_addr);
1407
1408 of_property_read_u32(np, "ti,davinci-ctrl-reg-offset",
1409 &pdata->ctrl_reg_offset);
1410 --- a/drivers/net/ethernet/ti/netcp_core.c
1411 +++ b/drivers/net/ethernet/ti/netcp_core.c
1412 @@ -1966,7 +1966,6 @@ static int netcp_create_interface(struct
1413 struct resource res;
1414 void __iomem *efuse = NULL;
1415 u32 efuse_mac = 0;
1416 - const void *mac_addr;
1417 u8 efuse_mac_addr[6];
1418 u32 temp[2];
1419 int ret = 0;
1420 @@ -2036,10 +2035,8 @@ static int netcp_create_interface(struct
1421 devm_iounmap(dev, efuse);
1422 devm_release_mem_region(dev, res.start, size);
1423 } else {
1424 - mac_addr = of_get_mac_address(node_interface);
1425 - if (!IS_ERR(mac_addr))
1426 - ether_addr_copy(ndev->dev_addr, mac_addr);
1427 - else
1428 + ret = of_get_mac_address(node_interface, ndev->dev_addr);
1429 + if (ret)
1430 eth_random_addr(ndev->dev_addr);
1431 }
1432
1433 --- a/drivers/net/ethernet/wiznet/w5100-spi.c
1434 +++ b/drivers/net/ethernet/wiznet/w5100-spi.c
1435 @@ -423,8 +423,14 @@ static int w5100_spi_probe(struct spi_de
1436 const struct of_device_id *of_id;
1437 const struct w5100_ops *ops;
1438 kernel_ulong_t driver_data;
1439 + const void *mac = NULL;
1440 + u8 tmpmac[ETH_ALEN];
1441 int priv_size;
1442 - const void *mac = of_get_mac_address(spi->dev.of_node);
1443 + int ret;
1444 +
1445 + ret = of_get_mac_address(spi->dev.of_node, tmpmac);
1446 + if (!ret)
1447 + mac = tmpmac;
1448
1449 if (spi->dev.of_node) {
1450 of_id = of_match_device(w5100_of_match, &spi->dev);
1451 --- a/drivers/net/ethernet/wiznet/w5100.c
1452 +++ b/drivers/net/ethernet/wiznet/w5100.c
1453 @@ -1159,7 +1159,7 @@ int w5100_probe(struct device *dev, cons
1454 INIT_WORK(&priv->setrx_work, w5100_setrx_work);
1455 INIT_WORK(&priv->restart_work, w5100_restart_work);
1456
1457 - if (!IS_ERR_OR_NULL(mac_addr))
1458 + if (mac_addr)
1459 memcpy(ndev->dev_addr, mac_addr, ETH_ALEN);
1460 else
1461 eth_hw_addr_random(ndev);
1462 --- a/drivers/net/ethernet/xilinx/ll_temac_main.c
1463 +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
1464 @@ -434,7 +434,7 @@ static void temac_do_set_mac_address(str
1465
1466 static int temac_init_mac_address(struct net_device *ndev, const void *address)
1467 {
1468 - ether_addr_copy(ndev->dev_addr, address);
1469 + memcpy(ndev->dev_addr, address, ETH_ALEN);
1470 if (!is_valid_ether_addr(ndev->dev_addr))
1471 eth_hw_addr_random(ndev);
1472 temac_do_set_mac_address(ndev);
1473 @@ -1296,7 +1296,7 @@ static int temac_probe(struct platform_d
1474 struct temac_local *lp;
1475 struct net_device *ndev;
1476 struct resource *res;
1477 - const void *addr;
1478 + u8 addr[ETH_ALEN];
1479 __be32 *p;
1480 bool little_endian;
1481 int rc = 0;
1482 @@ -1492,8 +1492,8 @@ static int temac_probe(struct platform_d
1483
1484 if (temac_np) {
1485 /* Retrieve the MAC address */
1486 - addr = of_get_mac_address(temac_np);
1487 - if (IS_ERR(addr)) {
1488 + rc = of_get_mac_address(temac_np, addr);
1489 + if (rc) {
1490 dev_err(&pdev->dev, "could not find MAC address\n");
1491 return -ENODEV;
1492 }
1493 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
1494 +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
1495 @@ -1663,7 +1663,7 @@ static int axienet_probe(struct platform
1496 struct device_node *np;
1497 struct axienet_local *lp;
1498 struct net_device *ndev;
1499 - const void *mac_addr;
1500 + u8 mac_addr[ETH_ALEN];
1501 struct resource *ethres;
1502 u32 value;
1503
1504 @@ -1835,13 +1835,14 @@ static int axienet_probe(struct platform
1505 dev_info(&pdev->dev, "Ethernet core IRQ not defined\n");
1506
1507 /* Retrieve the MAC address */
1508 - mac_addr = of_get_mac_address(pdev->dev.of_node);
1509 - if (IS_ERR(mac_addr)) {
1510 - dev_warn(&pdev->dev, "could not find MAC address property: %ld\n",
1511 - PTR_ERR(mac_addr));
1512 - mac_addr = NULL;
1513 + ret = of_get_mac_address(pdev->dev.of_node, mac_addr);
1514 + if (!ret) {
1515 + axienet_set_mac_address(ndev, mac_addr);
1516 + } else {
1517 + dev_warn(&pdev->dev, "could not find MAC address property: %d\n",
1518 + ret);
1519 + axienet_set_mac_address(ndev, NULL);
1520 }
1521 - axienet_set_mac_address(ndev, mac_addr);
1522
1523 lp->coalesce_count_rx = XAXIDMA_DFT_RX_THRESHOLD;
1524 lp->coalesce_count_tx = XAXIDMA_DFT_TX_THRESHOLD;
1525 --- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
1526 +++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
1527 @@ -1113,7 +1113,6 @@ static int xemaclite_of_probe(struct pla
1528 struct net_device *ndev = NULL;
1529 struct net_local *lp = NULL;
1530 struct device *dev = &ofdev->dev;
1531 - const void *mac_address;
1532
1533 int rc = 0;
1534
1535 @@ -1155,12 +1154,9 @@ static int xemaclite_of_probe(struct pla
1536 lp->next_rx_buf_to_use = 0x0;
1537 lp->tx_ping_pong = get_bool(ofdev, "xlnx,tx-ping-pong");
1538 lp->rx_ping_pong = get_bool(ofdev, "xlnx,rx-ping-pong");
1539 - mac_address = of_get_mac_address(ofdev->dev.of_node);
1540
1541 - if (!IS_ERR(mac_address)) {
1542 - /* Set the MAC address. */
1543 - ether_addr_copy(ndev->dev_addr, mac_address);
1544 - } else {
1545 + rc = of_get_mac_address(ofdev->dev.of_node, ndev->dev_addr);
1546 + if (rc) {
1547 dev_warn(dev, "No MAC address found, using random\n");
1548 eth_hw_addr_random(ndev);
1549 }
1550 --- a/drivers/net/wireless/ath/ath9k/init.c
1551 +++ b/drivers/net/wireless/ath/ath9k/init.c
1552 @@ -618,7 +618,6 @@ static int ath9k_of_init(struct ath_soft
1553 struct ath_hw *ah = sc->sc_ah;
1554 struct ath_common *common = ath9k_hw_common(ah);
1555 enum ath_bus_type bus_type = common->bus_ops->ath_bus_type;
1556 - const char *mac;
1557 char eeprom_name[100];
1558 int ret;
1559
1560 @@ -641,9 +640,7 @@ static int ath9k_of_init(struct ath_soft
1561 ah->ah_flags |= AH_NO_EEP_SWAP;
1562 }
1563
1564 - mac = of_get_mac_address(np);
1565 - if (!IS_ERR(mac))
1566 - ether_addr_copy(common->macaddr, mac);
1567 + of_get_mac_address(np, common->macaddr);
1568
1569 return 0;
1570 }
1571 --- a/drivers/net/wireless/mediatek/mt76/eeprom.c
1572 +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
1573 @@ -75,17 +75,9 @@ out_put_node:
1574 void
1575 mt76_eeprom_override(struct mt76_dev *dev)
1576 {
1577 -#ifdef CONFIG_OF
1578 struct device_node *np = dev->dev->of_node;
1579 - const u8 *mac;
1580
1581 - if (!np)
1582 - return;
1583 -
1584 - mac = of_get_mac_address(np);
1585 - if (!IS_ERR(mac))
1586 - ether_addr_copy(dev->macaddr, mac);
1587 -#endif
1588 + of_get_mac_address(np, dev->macaddr);
1589
1590 if (!is_valid_ether_addr(dev->macaddr)) {
1591 eth_random_addr(dev->macaddr);
1592 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
1593 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
1594 @@ -990,11 +990,7 @@ static void rt2x00lib_rate(struct ieee80
1595
1596 void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr)
1597 {
1598 - const char *mac_addr;
1599 -
1600 - mac_addr = of_get_mac_address(rt2x00dev->dev->of_node);
1601 - if (!IS_ERR(mac_addr))
1602 - ether_addr_copy(eeprom_mac_addr, mac_addr);
1603 + of_get_mac_address(rt2x00dev->dev->of_node, eeprom_mac_addr);
1604
1605 if (!is_valid_ether_addr(eeprom_mac_addr)) {
1606 eth_random_addr(eeprom_mac_addr);
1607 --- a/drivers/of/of_net.c
1608 +++ b/drivers/of/of_net.c
1609 @@ -39,37 +39,29 @@ int of_get_phy_mode(struct device_node *
1610 }
1611 EXPORT_SYMBOL_GPL(of_get_phy_mode);
1612
1613 -static const void *of_get_mac_addr(struct device_node *np, const char *name)
1614 +static int of_get_mac_addr(struct device_node *np, const char *name, u8 *addr)
1615 {
1616 struct property *pp = of_find_property(np, name, NULL);
1617
1618 - if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value))
1619 - return pp->value;
1620 - return NULL;
1621 + if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value)) {
1622 + memcpy(addr, pp->value, ETH_ALEN);
1623 + return 0;
1624 + }
1625 + return -ENODEV;
1626 }
1627
1628 -static const void *of_get_mac_addr_nvmem(struct device_node *np)
1629 +static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
1630 {
1631 - int ret;
1632 - const void *mac;
1633 - u8 nvmem_mac[ETH_ALEN];
1634 struct platform_device *pdev = of_find_device_by_node(np);
1635 + int ret;
1636
1637 if (!pdev)
1638 - return ERR_PTR(-ENODEV);
1639 + return -ENODEV;
1640
1641 - ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac);
1642 - if (ret) {
1643 - put_device(&pdev->dev);
1644 - return ERR_PTR(ret);
1645 - }
1646 -
1647 - mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL);
1648 + ret = nvmem_get_mac_address(&pdev->dev, addr);
1649 put_device(&pdev->dev);
1650 - if (!mac)
1651 - return ERR_PTR(-ENOMEM);
1652
1653 - return mac;
1654 + return ret;
1655 }
1656
1657 /**
1658 @@ -92,24 +84,27 @@ static const void *of_get_mac_addr_nvmem
1659 * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
1660 * but is all zeros.
1661 *
1662 - * Return: Will be a valid pointer on success and ERR_PTR in case of error.
1663 + * Return: 0 on success and errno in case of error.
1664 */
1665 -const void *of_get_mac_address(struct device_node *np)
1666 +int of_get_mac_address(struct device_node *np, u8 *addr)
1667 {
1668 - const void *addr;
1669 -
1670 - addr = of_get_mac_addr(np, "mac-address");
1671 - if (addr)
1672 - return addr;
1673 + int ret;
1674
1675 - addr = of_get_mac_addr(np, "local-mac-address");
1676 - if (addr)
1677 - return addr;
1678 + if (!np)
1679 + return -ENODEV;
1680
1681 - addr = of_get_mac_addr(np, "address");
1682 - if (addr)
1683 - return addr;
1684 + ret = of_get_mac_addr(np, "mac-address", addr);
1685 + if (!ret)
1686 + return 0;
1687 +
1688 + ret = of_get_mac_addr(np, "local-mac-address", addr);
1689 + if (!ret)
1690 + return 0;
1691 +
1692 + ret = of_get_mac_addr(np, "address", addr);
1693 + if (!ret)
1694 + return 0;
1695
1696 - return of_get_mac_addr_nvmem(np);
1697 + return of_get_mac_addr_nvmem(np, addr);
1698 }
1699 EXPORT_SYMBOL(of_get_mac_address);
1700 --- a/drivers/staging/octeon/ethernet.c
1701 +++ b/drivers/staging/octeon/ethernet.c
1702 @@ -407,14 +407,10 @@ static int cvm_oct_common_set_mac_addres
1703 int cvm_oct_common_init(struct net_device *dev)
1704 {
1705 struct octeon_ethernet *priv = netdev_priv(dev);
1706 - const u8 *mac = NULL;
1707 + int ret;
1708
1709 - if (priv->of_node)
1710 - mac = of_get_mac_address(priv->of_node);
1711 -
1712 - if (!IS_ERR_OR_NULL(mac))
1713 - ether_addr_copy(dev->dev_addr, mac);
1714 - else
1715 + ret = of_get_mac_address(priv->of_node, dev->dev_addr);
1716 + if (ret)
1717 eth_hw_addr_random(dev);
1718
1719 /*
1720 --- a/include/linux/of_net.h
1721 +++ b/include/linux/of_net.h
1722 @@ -11,7 +11,7 @@
1723
1724 struct net_device;
1725 extern int of_get_phy_mode(struct device_node *np);
1726 -extern const void *of_get_mac_address(struct device_node *np);
1727 +extern int of_get_mac_address(struct device_node *np, u8 *mac);
1728 extern struct net_device *of_find_net_device_by_node(struct device_node *np);
1729 #else
1730 static inline int of_get_phy_mode(struct device_node *np)
1731 @@ -19,9 +19,9 @@ static inline int of_get_phy_mode(struct
1732 return -ENODEV;
1733 }
1734
1735 -static inline const void *of_get_mac_address(struct device_node *np)
1736 +static inline int of_get_mac_address(struct device_node *np, u8 *mac)
1737 {
1738 - return ERR_PTR(-ENODEV);
1739 + return -ENODEV;
1740 }
1741
1742 static inline struct net_device *of_find_net_device_by_node(struct device_node *np)
1743 --- a/include/net/dsa.h
1744 +++ b/include/net/dsa.h
1745 @@ -186,7 +186,7 @@ struct dsa_port {
1746 unsigned int index;
1747 const char *name;
1748 struct dsa_port *cpu_dp;
1749 - const char *mac;
1750 + u8 mac[ETH_ALEN];
1751 struct device_node *dn;
1752 unsigned int ageing_time;
1753 bool vlan_filtering;
1754 --- a/net/dsa/dsa2.c
1755 +++ b/net/dsa/dsa2.c
1756 @@ -318,7 +318,7 @@ static int dsa_port_setup(struct dsa_por
1757 break;
1758 devlink_port_registered = true;
1759
1760 - dp->mac = of_get_mac_address(dp->dn);
1761 + of_get_mac_address(dp->dn, dp->mac);
1762 err = dsa_slave_create(dp);
1763 if (err)
1764 break;
1765 --- a/net/dsa/slave.c
1766 +++ b/net/dsa/slave.c
1767 @@ -1414,7 +1414,7 @@ int dsa_slave_create(struct dsa_port *po
1768 slave_dev->hw_features |= NETIF_F_HW_TC;
1769 slave_dev->features |= NETIF_F_LLTX;
1770 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
1771 - if (!IS_ERR_OR_NULL(port->mac))
1772 + if (!is_zero_ether_addr(port->mac))
1773 ether_addr_copy(slave_dev->dev_addr, port->mac);
1774 else
1775 eth_hw_addr_inherit(slave_dev, master);
1776 --- a/net/ethernet/eth.c
1777 +++ b/net/ethernet/eth.c
1778 @@ -550,13 +550,14 @@ unsigned char * __weak arch_get_platform
1779
1780 int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
1781 {
1782 - const unsigned char *addr = NULL;
1783 + unsigned char *addr;
1784 + int ret;
1785
1786 - if (dev->of_node)
1787 - addr = of_get_mac_address(dev->of_node);
1788 - if (IS_ERR_OR_NULL(addr))
1789 - addr = arch_get_platform_mac_address();
1790 + ret = of_get_mac_address(dev->of_node, mac_addr);
1791 + if (!ret)
1792 + return 0;
1793
1794 + addr = arch_get_platform_mac_address();
1795 if (!addr)
1796 return -ENODEV;
1797
1798 --- a/drivers/net/usb/smsc75xx.c
1799 +++ b/drivers/net/usb/smsc75xx.c
1800 @@ -757,11 +757,12 @@ static int smsc75xx_ioctl(struct net_dev
1801
1802 static void smsc75xx_init_mac_address(struct usbnet *dev)
1803 {
1804 - const u8 *mac_addr;
1805 + u8 mac_addr[ETH_ALEN];
1806 + int ret;
1807
1808 /* maybe the boot loader passed the MAC address in devicetree */
1809 - mac_addr = of_get_mac_address(dev->udev->dev.of_node);
1810 - if (!IS_ERR(mac_addr)) {
1811 + ret = of_get_mac_address(dev->udev->dev.of_node, mac_addr);
1812 + if (!ret) {
1813 ether_addr_copy(dev->net->dev_addr, mac_addr);
1814 return;
1815 }
1816 --- a/drivers/net/usb/smsc95xx.c
1817 +++ b/drivers/net/usb/smsc95xx.c
1818 @@ -901,11 +901,12 @@ static int smsc95xx_ioctl(struct net_dev
1819
1820 static void smsc95xx_init_mac_address(struct usbnet *dev)
1821 {
1822 - const u8 *mac_addr;
1823 + u8 mac_addr[ETH_ALEN];
1824 + int ret;
1825
1826 /* maybe the boot loader passed the MAC address in devicetree */
1827 - mac_addr = of_get_mac_address(dev->udev->dev.of_node);
1828 - if (!IS_ERR(mac_addr)) {
1829 + ret = of_get_mac_address(dev->udev->dev.of_node, mac_addr);
1830 + if (!ret) {
1831 ether_addr_copy(dev->net->dev_addr, mac_addr);
1832 return;
1833 }
1834 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
1835 +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
1836 @@ -3444,10 +3444,11 @@ static int bcmgenet_probe(struct platfor
1837 const struct of_device_id *of_id = NULL;
1838 struct bcmgenet_priv *priv;
1839 struct net_device *dev;
1840 - const void *macaddr;
1841 + u8 macaddr[ETH_ALEN];
1842 unsigned int i;
1843 int err = -EIO;
1844 const char *phy_mode_str;
1845 + int ret;
1846
1847 /* Up to GENET_MAX_MQ_CNT + 1 TX queues and RX queues */
1848 dev = alloc_etherdev_mqs(sizeof(*priv), GENET_MAX_MQ_CNT + 1,
1849 @@ -3474,14 +3475,15 @@ static int bcmgenet_probe(struct platfor
1850 }
1851
1852 if (dn) {
1853 - macaddr = of_get_mac_address(dn);
1854 - if (IS_ERR(macaddr)) {
1855 + ret = of_get_mac_address(dn, macaddr);
1856 + if (ret) {
1857 dev_err(&pdev->dev, "can't find MAC address\n");
1858 err = -EINVAL;
1859 goto err;
1860 }
1861 + ether_addr_copy(dev->dev_addr, macaddr);
1862 } else {
1863 - macaddr = pd->mac_address;
1864 + ether_addr_copy(dev->dev_addr, pd->mac_address);
1865 }
1866
1867 priv->base = devm_platform_ioremap_resource(pdev, 0);
1868 @@ -3494,7 +3496,6 @@ static int bcmgenet_probe(struct platfor
1869
1870 SET_NETDEV_DEV(dev, &pdev->dev);
1871 dev_set_drvdata(&pdev->dev, dev);
1872 - ether_addr_copy(dev->dev_addr, macaddr);
1873 dev->watchdog_timeo = 2 * HZ;
1874 dev->ethtool_ops = &bcmgenet_ethtool_ops;
1875 dev->netdev_ops = &bcmgenet_netdev_ops;