arm: common: use match_string() helper to simplify the code
diff mbox series

Message ID 1536937519-31611-1-git-send-email-zhongjiang@huawei.com
State New
Headers show
Series
  • arm: common: use match_string() helper to simplify the code
Related show

Commit Message

zhong jiang Sept. 14, 2018, 3:05 p.m. UTC
match_string() returns the index of an array for a matching string,
which can be used instead of open coded implementation.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 arch/arm/plat-orion/common.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

kbuild test robot Sept. 14, 2018, 11:52 p.m. UTC | #1
Hi zhong,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on arm-soc/for-next]
[also build test ERROR on v4.19-rc3 next-20180913]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/zhong-jiang/arm-common-use-match_string-helper-to-simplify-the-code/20180915-035510
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc.git for-next
config: arm-multi_v5_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=arm 

All errors (new ones prefixed by >>):

   arch/arm/plat-orion/common.c: In function 'orion_ge00_switch_init':
>> arch/arm/plat-orion/common.c:487:23: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
     index = match_string(d->port_names, ARRAY_SIZE(d->port_names), "cpu");
                          ^
   In file included from include/linux/bitmap.h:9:0,
                    from include/linux/cpumask.h:12,
                    from include/linux/rcupdate.h:44,
                    from include/linux/radix-tree.h:28,
                    from include/linux/idr.h:15,
                    from include/linux/kernfs.h:14,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/device.h:16,
                    from include/linux/platform_device.h:14,
                    from arch/arm/plat-orion/common.c:13:
   include/linux/string.h:184:5: note: expected 'const char * const*' but argument is of type 'char **'
    int match_string(const char * const *array, size_t n, const char *string);
        ^~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/match_string +487 arch/arm/plat-orion/common.c

   479	
   480	void __init orion_ge00_switch_init(struct dsa_chip_data *d)
   481	{
   482		int index;
   483	
   484		if (!IS_BUILTIN(CONFIG_PHYLIB))
   485			return;
   486	
 > 487		index = match_string(d->port_names, ARRAY_SIZE(d->port_names), "cpu");
   488		if (index >= 0)
   489			d->netdev[index] = &orion_ge00.dev;
   490	
   491		orion_ge00_switch_board_info.mdio_addr = d->sw_addr;
   492		orion_ge00_switch_board_info.platform_data = d;
   493	
   494		mdiobus_register_board_info(&orion_ge00_switch_board_info, 1);
   495	}
   496	#endif
   497	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
zhong jiang Sept. 15, 2018, 6:46 a.m. UTC | #2
On 2018/9/15 7:52, kbuild test robot wrote:
> Hi zhong,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on arm-soc/for-next]
> [also build test ERROR on v4.19-rc3 next-20180913]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>
> url:    https://github.com/0day-ci/linux/commits/zhong-jiang/arm-common-use-match_string-helper-to-simplify-the-code/20180915-035510
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc.git for-next
> config: arm-multi_v5_defconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
> reproduce:
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # save the attached .config to linux build tree
>         GCC_VERSION=7.2.0 make.cross ARCH=arm 
>
> All errors (new ones prefixed by >>):
>
>    arch/arm/plat-orion/common.c: In function 'orion_ge00_switch_init':
>>> arch/arm/plat-orion/common.c:487:23: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
>      index = match_string(d->port_names, ARRAY_SIZE(d->port_names), "cpu");
>                           ^
>    In file included from include/linux/bitmap.h:9:0,
>                     from include/linux/cpumask.h:12,
>                     from include/linux/rcupdate.h:44,
>                     from include/linux/radix-tree.h:28,
>                     from include/linux/idr.h:15,
>                     from include/linux/kernfs.h:14,
>                     from include/linux/sysfs.h:16,
>                     from include/linux/kobject.h:20,
>                     from include/linux/device.h:16,
>                     from include/linux/platform_device.h:14,
>                     from arch/arm/plat-orion/common.c:13:
>    include/linux/string.h:184:5: note: expected 'const char * const*' but argument is of type 'char **'
>     int match_string(const char * const *array, size_t n, const char *string);
>         ^~~~~~~~~~~~
>    cc1: some warnings being treated as errors
I am sorry for that. :-[    Will repost in v2.

Thanks,
zhong jiang
> vim +/match_string +487 arch/arm/plat-orion/common.c
>
>    479	
>    480	void __init orion_ge00_switch_init(struct dsa_chip_data *d)
>    481	{
>    482		int index;
>    483	
>    484		if (!IS_BUILTIN(CONFIG_PHYLIB))
>    485			return;
>    486	
>  > 487		index = match_string(d->port_names, ARRAY_SIZE(d->port_names), "cpu");
>    488		if (index >= 0)
>    489			d->netdev[index] = &orion_ge00.dev;
>    490	
>    491		orion_ge00_switch_board_info.mdio_addr = d->sw_addr;
>    492		orion_ge00_switch_board_info.platform_data = d;
>    493	
>    494		mdiobus_register_board_info(&orion_ge00_switch_board_info, 1);
>    495	}
>    496	#endif
>    497	
>
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

Patch
diff mbox series

diff --git a/arch/arm/plat-orion/common.c b/arch/arm/plat-orion/common.c
index a2399fd..d705ffa 100644
--- a/arch/arm/plat-orion/common.c
+++ b/arch/arm/plat-orion/common.c
@@ -479,17 +479,14 @@  void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
 
 void __init orion_ge00_switch_init(struct dsa_chip_data *d)
 {
-	unsigned int i;
+	int index;
 
 	if (!IS_BUILTIN(CONFIG_PHYLIB))
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(d->port_names); i++) {
-		if (!strcmp(d->port_names[i], "cpu")) {
-			d->netdev[i] = &orion_ge00.dev;
-			break;
-		}
-	}
+	index = match_string(d->port_names, ARRAY_SIZE(d->port_names), "cpu");
+	if (index >= 0)
+		d->netdev[index] = &orion_ge00.dev;
 
 	orion_ge00_switch_board_info.mdio_addr = d->sw_addr;
 	orion_ge00_switch_board_info.platform_data = d;