powerpc: tsi108: fix similar warning reported by kbuild test robot
authorPetr Štetiar <ynezz@true.cz>
Fri, 10 May 2019 09:35:16 +0000 (11:35 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 10 May 2019 22:14:29 +0000 (15:14 -0700)
This patch fixes following (similar) warning reported by kbuild test robot:

 In function ‘memcpy’,
  inlined from ‘smsc75xx_init_mac_address’ at drivers/net/usb/smsc75xx.c:778:3,
  inlined from ‘smsc75xx_bind’ at drivers/net/usb/smsc75xx.c:1501:2:
  ./include/linux/string.h:355:9: warning: argument 2 null where non-null expected [-Wnonnull]
  return __builtin_memcpy(p, q, size);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/net/usb/smsc75xx.c: In function ‘smsc75xx_bind’:
  ./include/linux/string.h:355:9: note: in a call to built-in function ‘__builtin_memcpy’

I've replaced the offending memcpy with ether_addr_copy, because I'm
100% sure, that of_get_mac_address can't return NULL as it returns valid
pointer or ERR_PTR encoded value, nothing else.

I'm hesitant to just change IS_ERR into IS_ERR_OR_NULL check, as this
would make the warning disappear also, but it would be confusing to
check for impossible return value just to make a compiler happy.

I'm now changing all occurencies of memcpy to ether_addr_copy after the
of_get_mac_address call, as it's very likely, that we're going to get
similar reports from kbuild test robot in the future.

Fixes: ea168cdf1299 ("powerpc: tsi108: support of_get_mac_address new ERR_PTR error")
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/powerpc/sysdev/tsi108_dev.c

index c92dcac85231c6381884199cfec717a08d3e36eb..026619c9a8cbc9f8cfecfd2ba298444792a47c21 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/irq.h>
 #include <linux/export.h>
 #include <linux/device.h>
+#include <linux/etherdevice.h>
 #include <linux/platform_device.h>
 #include <linux/of_net.h>
 #include <asm/tsi108.h>
@@ -106,7 +107,7 @@ static int __init tsi108_eth_of_init(void)
 
                mac_addr = of_get_mac_address(np);
                if (!IS_ERR(mac_addr))
-                       memcpy(tsi_eth_data.mac_addr, mac_addr, 6);
+                       ether_addr_copy(tsi_eth_data.mac_addr, mac_addr);
 
                ph = of_get_property(np, "mdio-handle", NULL);
                mdio = of_find_node_by_phandle(*ph);