linux-stable/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
..
armada-370-xp.h
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
coherency_ll.S ARM: mvebu: drop pointless check for coherency_base 2020-09-24 10:19:06 +02:00
common.h
cpu-reset.c
dove.c
headsmp-a9.S
headsmp.S
Kconfig ARM: mvebu: Drop unneeded select of HAVE_SMP 2020-05-15 23:27:38 +02: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
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mvebu-soc-id.c
mvebu-soc-id.h
platsmp-a9.c
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
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