linux/drivers/net
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
..
appletalk
arcnet net: arcnet: com20020 fix error handling 2021-03-14 14:17:48 -07:00
bonding net: bonding: remove repeated word 2021-03-30 16:56:39 -07:00
caif
can Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
dsa net: dsa: mt7530: Add support for EEE features 2021-04-13 14:28:08 -07:00
ethernet of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
fddi
fjes
hamradio module: remove never implemented MODULE_SUPPORTED_DEVICE 2021-03-17 13:16:18 -07:00
hippi
hyperv net: remove the new_ifindex argument from dev_change_net_namespace 2021-04-07 14:43:28 -07:00
ieee802154 Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
ipa net: ipa: add IPA v4.11 configuration data 2021-04-11 16:49:08 -07:00
ipvlan
mdio net: mdio: Remove redundant dev_err call in mdio_mux_iproc_probe() 2021-03-29 13:16:44 -07:00
mhi net: mhi: remove pointless conditional before kfree_skb() 2021-03-30 13:47:28 -07:00
netdevsim netdevsim: remove unneeded semicolon 2021-04-06 16:27:33 -07:00
pcs net: pcs: add C37 SGMII AN support for intel mGbE controller 2021-03-15 12:53:12 -07:00
phy phy: sfp: add netlink SFP support to generic SFP code 2021-04-11 16:34:56 -07:00
plip
ppp ppp: deflate: Remove useless call "zlib_inflateEnd" 2021-03-30 16:59:30 -07:00
slip
team
usb Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
vmxnet3 vmxnet3: Update driver to use ethtool_sprintf 2021-03-17 11:42:31 -07:00
wan Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
wireguard
wireless of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
xen-netback
bareudp.c bareudp: allow UDP L4 GRO passthrou 2021-03-30 17:06:50 -07:00
dummy.c
eql.c
geneve.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
gtp.c
ifb.c
Kconfig netdevsim: Add dummy psample implementation 2021-03-14 15:00:43 -07:00
LICENSE.SRC
loopback.c
macsec.c
macvlan.c
macvtap.c
Makefile dsa: simplify Kconfig symbols and dependencies 2021-03-22 12:15:37 -07:00
mdio.c net: mdio: Correct function name mdio45_links_ok() in comment 2021-03-29 13:42:44 -07:00
mii.c
net_failover.c
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
Space.c
sungem_phy.c
tap.c
thunderbolt.c
tun.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
veth.c veth: refine napi usage 2021-04-11 16:39:28 -07:00
virtio_net.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
vrf.c
vsockmon.c
vxlan.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-04-09 20:48:35 -07:00
xen-netfront.c bpf, devmap: Move drop error path to devmap for XDP_REDIRECT 2021-03-18 16:38:51 +01:00