linux-stable/arch/arm
Michael Walle 83216e3988 of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.

There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.

Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().

Usually the code looks like:

  const char *addr;
  addr = of_get_mac_address(np);
  if (!IS_ERR(addr))
    ether_addr_copy(ndev->dev_addr, addr);

This can then be simply rewritten as:

  of_get_mac_address(np, ndev->dev_addr);

Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.

The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!

<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
  <...
- ether_addr_copy(z, x);
  ...>

@@
identifier a.x;
@@
- if (<+... x ...+>) {}

@@
identifier a.x;
@@
  if (<+... x ...+>) {
      ...
  }
- else {}

@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
-     {}
- else
+ if (!(e))
      {...}

@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
  ... when != x
</spml>

All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-13 14:35:02 -07:00
..
boot Merge tag 'mvebu-fixes-5.12-1' of git://git.kernel.org/pub/scm/linux/kernel/git/gclement/mvebu into arm/fixes 2021-04-06 23:21:08 +02:00
common
configs Modules updates for v5.12 2021-02-23 10:15:33 -08:00
crypto
include ARM updates for 5.12-rc1: 2021-02-22 14:27:07 -08:00
kernel io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
lib
mach-actions
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91 ARM: at91: use proper asm syntax in pm_suspend 2021-02-08 15:54:05 +01:00
mach-axxia
mach-bcm
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci
mach-digicolor
mach-dove
mach-ep93xx
mach-exynos
mach-footbridge
mach-gemini
mach-highbank
mach-hisi
mach-imx ARM: imx: avic: Convert to using IRQCHIP_DECLARE 2021-03-15 12:21:18 +08:00
mach-integrator
mach-iop32x
mach-ixp4xx
mach-keystone ARM: keystone: fix integer overflow warning 2021-04-01 16:32:37 +02:00
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-milbeaut
mach-mmp
mach-moxart
mach-mstar
mach-mv78xx0
mach-mvebu of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
mach-mxs
mach-nomadik
mach-npcm
mach-nspire
mach-omap1 ARM: omap1: fix building with clang IAS 2021-04-01 16:32:37 +02:00
mach-omap2 Fixes for omaps for v5.12-rc cycle 2021-03-18 23:52:27 +01:00
mach-orion5x
mach-oxnas
mach-pxa ARM: pxa: mainstone: avoid -Woverride-init warning 2021-04-01 16:32:37 +02:00
mach-qcom
mach-rda
mach-realtek
mach-realview
mach-rockchip
mach-rpc
mach-s3c ARM: s3c: irq-s3c24xx: staticize local functions 2021-02-08 18:10:21 +01:00
mach-s5pv210
mach-sa1100
mach-shmobile
mach-socfpga
mach-spear clk: spear: Move prototype to accessible header 2021-02-11 11:56:06 -08:00
mach-sti
mach-stm32
mach-sunxi
mach-tegra
mach-uniphier
mach-ux500
mach-versatile
mach-vexpress
mach-vt8500
mach-zynq
mm ARM updates for 5.12-rc1: 2021-02-22 14:27:07 -08:00
net
nwfpe
plat-omap
plat-orion
plat-pxa
plat-versatile
probes
tools Kbuild updates for v5.12 2021-02-25 10:17:31 -08:00
vdso
vfp
xen Xen/gnttab: introduce common INVALID_GRANT_{HANDLE,REF} 2021-03-10 16:39:29 -06:00
Kbuild
Kconfig ARM: ep93xx: Select GENERIC_IRQ_MULTI_HANDLER directly 2021-03-08 20:18:32 +00:00
Kconfig-nommu
Kconfig.assembler
Kconfig.debug ARM updates for 5.12-rc1: 2021-02-22 14:27:07 -08:00
Makefile Remove oprofile and dcookies support 2021-02-21 10:40:34 -08:00