linux-sg2042/arch/arm/mach-mvebu
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
..
Kconfig ARM: mvebu: Drop unneeded select of HAVE_SMP 2020-05-15 23:27:38 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
armada-370-xp.h ARM: use const and __initconst for smp_operations 2015-12-01 22:17:45 +01:00
board-v7.c ARM: mvebu: drop return from void function 2019-04-30 09:05:44 +02:00
coherency.c dma-mapping: split <linux/dma-mapping.h> 2020-10-06 07:07:03 +02:00
coherency.h mvebu: add definition for coherency_base 2016-06-16 11:24:47 +02:00
coherency_ll.S ARM: mvebu: drop pointless check for coherency_base 2020-09-24 10:19:06 +02:00
common.h ARM: mvebu: Add standby support 2015-07-25 17:17:05 +02:00
cpu-reset.c mvebu: fix missing include of common.h in cpu-reset.c 2016-06-16 11:24:19 +02:00
dove.c arm: Remove unnecessary of_platform_populate with default match table 2016-06-23 14:58:37 -05:00
headsmp-a9.S Remove __cpuinit macros and users. 2015-07-02 09:54:14 -07:00
headsmp.S ARM: mvebu: Split low level functions to manipulate HW coherency 2014-05-08 16:18:54 +00:00
kirkwood-pm.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 406 2019-06-05 17:37:13 +02:00
kirkwood-pm.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 406 2019-06-05 17:37:13 +02:00
kirkwood.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
kirkwood.h ARM: mvebu: Simplify headers and make local 2014-02-22 21:19:59 +00:00
mvebu-soc-id.c ARM: mvebu: Use system controller to get the soc id when possible 2014-06-30 17:40:59 +00:00
mvebu-soc-id.h ARM: mvebu: Update the SoC ID and revision definitions 2015-01-09 09:22:53 -06:00
platsmp-a9.c ARM: use const and __initconst for smp_operations 2015-12-01 22:17:45 +01:00
platsmp.c ARM: mvebu: convert secondary CPU clock sync to hotplug state 2018-06-27 08:40:29 +02:00
pm-board.c ARM: mvebu: fix a leaked reference by adding missing of_node_put 2019-04-30 09:05:39 +02:00
pm.c ARM: 8641/1: treewide: Replace uses of virt_to_phys with __pa_symbol 2017-02-28 11:06:10 +00:00
pmsu.c ARM: mvebu: declare asm symbols as character arrays in pmsu.c 2018-06-27 08:15:12 +02:00
pmsu.h mvebu SoC suspend changes for v3.19 2014-12-04 16:46:43 +01:00
pmsu_ll.S ARM: mvebu: prefix coprocessor operand with p 2019-04-30 09:05:44 +02:00
system-controller.c ARM: 8641/1: treewide: Replace uses of virt_to_phys with __pa_symbol 2017-02-28 11:06:10 +00:00