linux/drivers/net/ethernet/ti
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
..
am65-cpsw-ethtool.c net: ethernet: ti: ale: add cpsw_ale_get_num_entries api 2020-09-11 17:34:39 -07:00
am65-cpsw-nuss.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
am65-cpsw-nuss.h net: ti: am65-cpsw-nuss: Add netdevice notifiers 2021-02-11 17:52:13 -08:00
am65-cpsw-qos.c net: ethernet: ti: am65-cpsw-qos: Demote non-conformant function header 2021-01-16 18:13:10 -08:00
am65-cpsw-qos.h ethernet: ti: am65-cpsw-qos: add TAPRIO offload support 2020-05-14 17:33:30 -07:00
am65-cpsw-switchdev.c net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes 2021-02-12 17:08:04 -08:00
am65-cpsw-switchdev.h net: ti: am65-cpsw-nuss: Add switchdev support 2021-02-11 17:52:13 -08:00
am65-cpts.c net: ethernet: ti: am65-cpts: Document am65_cpts_rx_enable()'s 'en' parameter 2021-01-16 18:13:14 -08:00
am65-cpts.h ethernet: ti: am65-cpts: Add missing inline qualifier to stub functions 2020-05-15 16:32:27 -07:00
cpmac.c net: cpmac: Fix use correct return type for ndo_start_xmit() 2020-05-06 14:24:06 -07:00
cpsw_ale.c net: ti: cpsw_ale: add driver data for AM64 CPSW3g 2021-01-19 17:32:34 -08:00
cpsw_ale.h net: ethernet: ti: cpsw_ale: add cpsw_ale_vlan_del_modify() 2020-11-02 16:41:07 -08:00
cpsw_ethtool.c net: ethernet: ti: cpsw: disable PTPv1 hw timestamping advertisement 2020-11-02 14:17:51 -08:00
cpsw_new.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
cpsw_priv.c bpf, devmap: Move drop error path to devmap for XDP_REDIRECT 2021-03-18 16:38:51 +01:00
cpsw_priv.h net: ethernet: ti: fix netdevice stats for XDP 2021-02-06 10:48:27 -08:00
cpsw_sl.c
cpsw_sl.h
cpsw_switchdev.c net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes 2021-02-12 17:08:04 -08:00
cpsw_switchdev.h net: ethernet: ti: introduce cpsw switchdev based driver part 2 - switch 2019-11-20 11:25:24 -08:00
cpsw-common.c
cpsw-phy-sel.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
cpsw.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
cpsw.h
cpts.c net: ethernet: ti: cpts: fix ethtool output when no ptp_clock registered 2020-12-28 13:32:34 -08:00
cpts.h net: ethernet: ti: cpts: add support for HW_TS_PUSH events 2020-04-23 12:50:21 -07:00
davinci_cpdma.c drivers/net/ethernet: clean up mis-targeted comments 2020-09-25 16:29:00 -07:00
davinci_cpdma.h
davinci_emac.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
davinci_mdio.c drivers: net: davinci_mdio: Use of_device_get_match_data() 2021-01-26 12:17:31 -06:00
k3-cppi-desc-pool.c net: ethernet: ti: fix return value check in k3_cppi_desc_pool_create_name() 2020-04-27 13:27:59 -07:00
k3-cppi-desc-pool.h net: ethernet: ti: introduce am65x/j721e gigabit eth subsystem driver 2020-03-26 20:01:14 -07:00
Kconfig net: ti: am65-cpsw-nuss: Add devlink support 2021-02-11 17:52:13 -08:00
Makefile net: ti: am65-cpsw-nuss: Add switchdev support 2021-02-11 17:52:13 -08:00
netcp_core.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
netcp_ethss.c net: netcp: ethss: use dev_id for ale configuration 2020-09-11 17:34:39 -07:00
netcp_sgmii.c
netcp_xgbepcsr.c
netcp.h
tlan.c net: tlan: Replace in_irq() usage 2020-10-31 09:55:38 -07:00
tlan.h