diff mbox series

[net-next,1/2] of: net: move nvmem_get_mac_address() into of_get_mac_addr_nvmem()

Message ID 20211013082550.624-1-yajun.deng@linux.dev (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/2] of: net: move nvmem_get_mac_address() into of_get_mac_addr_nvmem() | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 3 maintainers not CCed: michael@walle.cc lee.jones@linaro.org andrew@lunn.ch
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 1 this patch: 2
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 38 lines checked
netdev/build_allmodconfig_warn fail Errors and warnings before: 1 this patch: 2
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Yajun Deng Oct. 13, 2021, 8:25 a.m. UTC
nvmem_get_mac_address() is only called by of_get_mac_addr_nvmem(), and
they use almost the same code. so move nvmem_get_mac_address() into
of_get_mac_addr_nvmem().
In addition, prefer ether_addr_copy() over memcpy() if the ethernet
addresses are __aligned(2).

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 net/core/of_net.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

kernel test robot Oct. 13, 2021, 7:16 p.m. UTC | #1
Hi Yajun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Yajun-Deng/of-net-move-nvmem_get_mac_address-into-of_get_mac_addr_nvmem/20211013-162802
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git d1f24712a86abd04d82cf4b00fb4ab8ff2d23c8a
config: i386-buildonly-randconfig-r002-20211013 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a8c695542b2987eb9a203d5663a0740cb4725f)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/10748c5429eced2d22c6cf10e8dcdef8a1a5c38d
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yajun-Deng/of-net-move-nvmem_get_mac_address-into-of_get_mac_addr_nvmem/20211013-162802
        git checkout 10748c5429eced2d22c6cf10e8dcdef8a1a5c38d
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> net/core/of_net.c:66:6: error: unused variable 'ret' [-Werror,-Wunused-variable]
           int ret;
               ^
   1 error generated.


vim +/ret +66 net/core/of_net.c

3eb46a1da78dff drivers/of/of_net.c Sergei Shtylyov 2015-03-18  59  
83216e3988cd19 drivers/of/of_net.c Michael Walle   2021-04-12  60  static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
d01f449c008a3f drivers/of/of_net.c Petr Štetiar    2019-05-03  61  {
d01f449c008a3f drivers/of/of_net.c Petr Štetiar    2019-05-03  62  	struct platform_device *pdev = of_find_device_by_node(np);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  63  	struct nvmem_cell *cell;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  64  	const void *mac;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  65  	size_t len;
83216e3988cd19 drivers/of/of_net.c Michael Walle   2021-04-12 @66  	int ret;
d01f449c008a3f drivers/of/of_net.c Petr Štetiar    2019-05-03  67  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  68  	/* Try lookup by device first, there might be a nvmem_cell_lookup
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  69  	 * associated with a given device.
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  70  	 */
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  71  	if (pdev)
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  72  		cell = nvmem_cell_get(&pdev->dev, "mac-address");
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  73  	else
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  74  		cell = of_nvmem_cell_get(np, "mac-address");
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  75  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  76  	if (IS_ERR(cell))
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  77  		return PTR_ERR(cell);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  78  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  79  	mac = nvmem_cell_read(cell, &len);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  80  	nvmem_cell_put(cell);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  81  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  82  	if (IS_ERR(mac))
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  83  		return PTR_ERR(mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  84  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  85  	if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  86  		kfree(mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  87  		return -EINVAL;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  88  	}
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  89  
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  90  	ether_addr_copy(addr, mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  91  	kfree(mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  92  
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  93  	if (pdev)
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  94  		put_device(&pdev->dev);
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  95  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  96  	return 0;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  97  }
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  98  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Oct. 15, 2021, 10 a.m. UTC | #2
Hi Yajun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Yajun-Deng/of-net-move-nvmem_get_mac_address-into-of_get_mac_addr_nvmem/20211013-162802
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git d1f24712a86abd04d82cf4b00fb4ab8ff2d23c8a
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/10748c5429eced2d22c6cf10e8dcdef8a1a5c38d
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yajun-Deng/of-net-move-nvmem_get_mac_address-into-of_get_mac_addr_nvmem/20211013-162802
        git checkout 10748c5429eced2d22c6cf10e8dcdef8a1a5c38d
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=arc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   net/core/of_net.c: In function 'of_get_mac_addr_nvmem':
>> net/core/of_net.c:66:13: error: unused variable 'ret' [-Werror=unused-variable]
      66 |         int ret;
         |             ^~~
   cc1: all warnings being treated as errors


vim +/ret +66 net/core/of_net.c

3eb46a1da78dff drivers/of/of_net.c Sergei Shtylyov 2015-03-18  59  
83216e3988cd19 drivers/of/of_net.c Michael Walle   2021-04-12  60  static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
d01f449c008a3f drivers/of/of_net.c Petr Štetiar    2019-05-03  61  {
d01f449c008a3f drivers/of/of_net.c Petr Štetiar    2019-05-03  62  	struct platform_device *pdev = of_find_device_by_node(np);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  63  	struct nvmem_cell *cell;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  64  	const void *mac;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  65  	size_t len;
83216e3988cd19 drivers/of/of_net.c Michael Walle   2021-04-12 @66  	int ret;
d01f449c008a3f drivers/of/of_net.c Petr Štetiar    2019-05-03  67  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  68  	/* Try lookup by device first, there might be a nvmem_cell_lookup
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  69  	 * associated with a given device.
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  70  	 */
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  71  	if (pdev)
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  72  		cell = nvmem_cell_get(&pdev->dev, "mac-address");
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  73  	else
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  74  		cell = of_nvmem_cell_get(np, "mac-address");
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  75  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  76  	if (IS_ERR(cell))
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  77  		return PTR_ERR(cell);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  78  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  79  	mac = nvmem_cell_read(cell, &len);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  80  	nvmem_cell_put(cell);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  81  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  82  	if (IS_ERR(mac))
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  83  		return PTR_ERR(mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  84  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  85  	if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  86  		kfree(mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  87  		return -EINVAL;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  88  	}
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  89  
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  90  	ether_addr_copy(addr, mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  91  	kfree(mac);
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  92  
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  93  	if (pdev)
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  94  		put_device(&pdev->dev);
10748c5429eced net/core/of_net.c   Yajun Deng      2021-10-13  95  
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  96  	return 0;
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  97  }
f10843e04a0752 drivers/of/of_net.c Michael Walle   2021-04-12  98  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/net/core/of_net.c b/net/core/of_net.c
index f1a9bf7578e7..cd170ffda5f9 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -51,7 +51,7 @@  static int of_get_mac_addr(struct device_node *np, const char *name, u8 *addr)
 	struct property *pp = of_find_property(np, name, NULL);
 
 	if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value)) {
-		memcpy(addr, pp->value, ETH_ALEN);
+		ether_addr_copy(addr, pp->value);
 		return 0;
 	}
 	return -ENODEV;
@@ -68,13 +68,11 @@  static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
 	/* Try lookup by device first, there might be a nvmem_cell_lookup
 	 * associated with a given device.
 	 */
-	if (pdev) {
-		ret = nvmem_get_mac_address(&pdev->dev, addr);
-		put_device(&pdev->dev);
-		return ret;
-	}
+	if (pdev)
+		cell = nvmem_cell_get(&pdev->dev, "mac-address");
+	else
+		cell = of_nvmem_cell_get(np, "mac-address");
 
-	cell = of_nvmem_cell_get(np, "mac-address");
 	if (IS_ERR(cell))
 		return PTR_ERR(cell);
 
@@ -89,9 +87,12 @@  static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
 		return -EINVAL;
 	}
 
-	memcpy(addr, mac, ETH_ALEN);
+	ether_addr_copy(addr, mac);
 	kfree(mac);
 
+	if (pdev)
+		put_device(&pdev->dev);
+
 	return 0;
 }