linux/drivers/net/ethernet/broadcom
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
..
bnx2x ethernet/broadcom:remove unneeded variable: "ret" 2021-03-17 14:38:45 -07:00
bnxt bnxt_en: Free and allocate VF-Reps during error recovery. 2021-04-12 13:20:38 -07:00
genet net: bcmgenet: remove unused including <linux/version.h> 2021-03-25 16:58:55 -07:00
b44.c net: b44: fix error return code in b44_init_one() 2020-11-17 10:50:28 -08:00
b44.h
bcm63xx_enet.c bcm63xx_enet: fix sporadic kernel panic 2021-02-23 12:15:04 -08:00
bcm63xx_enet.h bcm63xx_enet: convert to build_skb 2021-01-07 12:39:53 -08:00
bcm4908_enet.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
bcm4908_enet.h net: broadcom: rename BCM4908 driver & update DT binding 2021-02-11 15:04:17 -08:00
bcmsysport.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
bcmsysport.h net: broadcom: share header defining UniMAC registers 2021-01-08 19:17:28 -08:00
bgmac-bcma-mdio.c
bgmac-bcma.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
bgmac-platform.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
bgmac.c net: broadcom: share header defining UniMAC registers 2021-01-08 19:17:28 -08:00
bgmac.h net: broadcom: share header defining UniMAC registers 2021-01-08 19:17:28 -08:00
bnx2_fw.h
bnx2.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
bnx2.h
cnic_defs.h net: cnic: fix spelling mistake "reserverd" -> "reserved" 2020-02-17 21:59:16 -08:00
cnic_if.h
cnic.c cnic: convert tasklets to use new tasklet_setup() API 2020-09-14 13:02:37 -07:00
cnic.h
Kconfig net: broadcom: BCM4908_ENET should not default to y, unconditionally 2021-03-16 15:26:31 -07:00
Makefile net: broadcom: rename BCM4908 driver & update DT binding 2021-02-11 15:04:17 -08:00
sb1250-mac.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-01-28 16:02:33 -08:00
tg3.c tg3: Remove unused PHY_BRCM flags 2021-02-16 14:11:57 -08:00
tg3.h tg3: improve PCI VPD access 2021-01-25 15:24:19 -08:00
unimac.h net: broadcom: share header defining UniMAC registers 2021-01-08 19:17:28 -08:00