linux/drivers/staging
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
..
android driver: staging: count ashmem_range into SLAB_RECLAIMBLE 2020-12-28 15:06:06 +01:00
axis-fifo
board Revert "staging: board: Remove macro board_staging" 2021-01-04 15:55:40 +01:00
clocking-wizard staging: Replace lkml.org links with lore 2021-02-11 12:13:53 +01:00
comedi Staging/IIO driver fixes for 5.12-rc4 2021-03-21 11:54:04 -07:00
emxx_udc staging: emxx_udc: Make incorrectly defined global static 2021-02-07 10:15:05 +01:00
fbtft staging: fbtft: add tearing signal detect 2021-02-12 09:48:29 +01:00
fieldbus staging: fieldbus: arcx-anybus: constify static structs 2021-02-08 15:22:34 +01:00
fwserial staging: fwserial: Fix error handling in fwserial_create 2020-12-28 15:11:52 +01:00
gasket staging: gasket: fix indentation and lines ending with open parenthesis 2021-02-08 15:24:40 +01:00
gdm724x staging: gdm724x: Fix DMA from stack 2021-02-11 11:08:17 +01:00
greybus staging: greybus: Fixed a misspelling in hid.c 2021-02-13 22:37:51 +01:00
gs_fpgaboot
hikey9xx staging: hikey9xx: Fix alignment of function parameters 2021-02-13 22:37:51 +01:00
iio staging: iio: adis16240: add blank line before struct definition 2020-10-26 06:53:09 +01:00
kpc2000 staging: kpc2000: kpc_dma: rename show function per convention 2020-10-27 12:23:59 +01:00
ks7010 staging: ks7010: prevent buffer overflow in ks_wlan_set_scan() 2021-03-10 09:23:28 +01:00
media Simple Firmware Interface (SFI) support removal for v5.12-rc1 2021-02-24 10:35:29 -08:00
most staging: most: Switch from strlcpy to strscpy 2021-02-04 17:16:06 +01:00
mt7621-dma staging/mt7621-dma: mtk-hsdma.c->hsdma-mt7621.c 2021-01-31 13:39:53 +01:00
mt7621-dts staging: mt7621-dts: remove obsolete switch node 2021-01-26 18:46:35 +01:00
mt7621-pci staging: mt7621-pci: remove 'RALINK_PCI_IMBASEBAR0_ADDR' register 2020-11-26 09:12:18 +01:00
netlogic
nvec staging: nvec: minor coding style fix 2021-02-12 09:49:43 +01:00
octeon of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
octeon-usb drivers: staging: octeon-usb: fixed codestyle check warning 2020-09-13 09:21:15 +02:00
olpc_dcon staging: olpc_dcon: Switch from strlcpy to strscpy 2021-02-04 17:16:06 +01:00
pi433 staging: pi433: break long lines 2020-09-04 15:39:07 +02:00
qlge staging: qlge: Remove duplicate word in comment 2021-02-11 21:32:35 +01:00
ralink-gdma staging: ralink-gdma: fix kconfig dependency bug for DMA_RALINK 2020-11-06 11:12:49 +01:00
rtl8188eu staging: rtl8188eu: prevent ->ssid overflow in rtw_wx_set_scan() 2021-03-10 09:23:30 +01:00
rtl8192e staging: rtl8192e: Change state information from u16 to u8 2021-03-23 13:32:40 +01:00
rtl8192u staging: rtl8192u: fix ->ssid overflow in r8192_wx_set_scan() 2021-03-10 09:23:30 +01:00
rtl8712 staging: rtl8712: Fix possible buffer overflow in r8712_sitesurvey_cmd 2021-03-10 09:23:28 +01:00
rtl8723bs Staging/IIO driver patches for 5.12-rc1 2021-02-20 21:36:51 -08:00
rts5208 staging: rts5208: rtsx_transport.c: Fix lines ending with parentheses 2020-09-13 09:20:31 +02:00
sm750fb staging: sm750fb: Switch from strlcpy to strscpy 2021-02-04 17:16:07 +01:00
unisys staging: unisys: visorhba: enhance visorhba to use channel_interrupt 2021-01-07 16:57:50 +01:00
vc04_services staging: Replace lkml.org links with lore 2021-02-11 12:13:53 +01:00
vme Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2021-02-27 08:07:12 -08:00
vt6655 staging: vt665x: fix alignment constraints 2021-03-18 10:21:46 +01:00
vt6656 staging: vt6656: Fixed issue with alignment in rf.c 2021-02-12 09:47:13 +01:00
wfx of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
wimax staging: wimax/i2400m: fix some byte order issues found by sparse 2021-02-13 22:37:50 +01:00
wlan-ng staging:wlan-ng: use memdup_user instead of kmalloc/copy_from_user 2021-02-13 22:37:50 +01:00
Kconfig staging: dpaa2-switch: move the driver out of staging 2021-03-10 13:30:36 -08:00
Makefile staging: dpaa2-switch: move the driver out of staging 2021-03-10 13:30:36 -08:00