OpenCloudOS-Kernel/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 ARM: 9049/1: locomo: make locomo bus's remove callback return void 2021-02-01 19:44:30 +00:00
configs Modules updates for v5.12 2021-02-23 10:15:33 -08:00
crypto crypto: arm/blake2b - add NEON-accelerated BLAKE2b 2021-01-03 08:41:39 +11:00
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 ARM: bcm: Select BRCMSTB_L2_IRQ for bcm2835 2021-01-25 21:59:06 +01:00
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL 2020-12-15 12:13:42 -08:00
mach-digicolor
mach-dove
mach-ep93xx
mach-exynos soc: samsung: exynos-chipid: convert to driver and merge exynos-asv 2021-01-03 17:08:45 +01:00
mach-footbridge ARM: footbridge: fix dc21285 PCI configuration accessors 2021-01-29 11:29:53 +00:00
mach-gemini
mach-highbank arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL 2020-12-15 12:13:42 -08:00
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 clocksource/drivers/ixp4xx: Select TIMER_OF when needed 2021-01-18 16:20:15 +01:00
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 ARM: mstar: SMP support 2020-12-09 17:45:40 +01:00
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 ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs 2020-11-30 17:31:29 +08:00
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 arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL 2020-12-15 12:13:42 -08:00
mach-sa1100 ARM: 9049/1: locomo: make locomo bus's remove callback return void 2021-02-01 19:44:30 +00:00
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 irqchip/sun6i-r: Use a stacked irqchip driver 2021-01-21 20:21:49 +00:00
mach-tegra ARM: tegra: Don't enable unused PLLs on resume from suspend 2021-01-19 18:20:42 +01:00
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 bpf: Rename BPF_XADD and prepare to encode other atomics in .imm 2021-01-14 18:34:29 -08:00
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 ARM: 9051/1: vdso: remove unneded extra-y addition 2021-02-01 19:48:06 +00:00
vfp ARM: 9044/1: vfp: use undef hook for VFP support detection 2020-12-21 11:19:19 +00:00
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