diff mbox

[v1] power: supply: Convert to use match_string() helper

Message ID 20180503174204.21266-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Andy Shevchenko May 3, 2018, 5:42 p.m. UTC
The new helper returns index of the matching string in an array.
We are going to use it here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/power/supply/power_supply_core.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Andy Shevchenko May 3, 2018, 8:24 p.m. UTC | #1
On Thu, 2018-05-03 at 20:42 +0300, Andy Shevchenko wrote:
> The new helper returns index of the matching string in an array.
> We are going to use it here.
> 

This one is wrong, please ignore.

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/power/supply/power_supply_core.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/power/supply/power_supply_core.c
> b/drivers/power/supply/power_supply_core.c
> index ecd68c2053c5..c695d151695e 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -36,8 +36,6 @@ static struct device_type power_supply_dev_type;
>  static bool __power_supply_is_supplied_by(struct power_supply
> *supplier,
>  					 struct power_supply *supply)
>  {
> -	int i;
> -
>  	if (!supply->supplied_from && !supplier->supplied_to)
>  		return false;
>  
> @@ -45,15 +43,15 @@ static bool __power_supply_is_supplied_by(struct
> power_supply *supplier,
>  	if (supply->supplied_from) {
>  		if (!supplier->desc->name)
>  			return false;
> -		for (i = 0; i < supply->num_supplies; i++)
> -			if (!strcmp(supplier->desc->name, supply-
> >supplied_from[i]))
> -				return true;
> +		if (match_string(supply->supplied_from, supply-
> >num_supplies,
> +				 supplier->desc->name) >= 0)
> +			return true;
>  	} else {
>  		if (!supply->desc->name)
>  			return false;
> -		for (i = 0; i < supplier->num_supplicants; i++)
> -			if (!strcmp(supplier->supplied_to[i], supply-
> >desc->name))
> -				return true;
> +		if (match_string(supplier->supplied_to, supplier-
> >num_supplicants,
> +				 supply->desc->name) >= 0)
> +			return true;
>  	}
>  
>  	return false;
kernel test robot May 4, 2018, 12:27 p.m. UTC | #2
Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on battery/master]
[also build test WARNING on v4.17-rc3 next-20180503]
[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/Andy-Shevchenko/power-supply-Convert-to-use-match_string-helper/20180504-173513
base:   git://git.infradead.org/battery-2.6.git master
config: i386-randconfig-x077-201817 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/power/supply/power_supply_core.c:13:
   drivers/power/supply/power_supply_core.c: In function '__power_supply_is_supplied_by':
   drivers/power/supply/power_supply_core.c:45:20: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
      if (match_string(supply->supplied_from, supply->num_supplies,
                       ^
   include/linux/compiler.h:149:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
>> drivers/power/supply/power_supply_core.c:45:3: note: in expansion of macro 'if'
      if (match_string(supply->supplied_from, supply->num_supplies,
      ^~
   In file included from arch/x86/include/asm/page_32.h:34:0,
                    from arch/x86/include/asm/page.h:13,
                    from arch/x86/include/asm/thread_info.h:11,
                    from include/linux/thread_info.h:54,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:18,
                    from include/linux/module.h:10,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/string.h:137: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);
        ^~~~~~~~~~~~
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/power/supply/power_supply_core.c:13:
   drivers/power/supply/power_supply_core.c:45:20: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
      if (match_string(supply->supplied_from, supply->num_supplies,
                       ^
   include/linux/compiler.h:149:42: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                             ^~~~
>> drivers/power/supply/power_supply_core.c:45:3: note: in expansion of macro 'if'
      if (match_string(supply->supplied_from, supply->num_supplies,
      ^~
   In file included from arch/x86/include/asm/page_32.h:34:0,
                    from arch/x86/include/asm/page.h:13,
                    from arch/x86/include/asm/thread_info.h:11,
                    from include/linux/thread_info.h:54,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:18,
                    from include/linux/module.h:10,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/string.h:137: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);
        ^~~~~~~~~~~~
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/power/supply/power_supply_core.c:13:
   drivers/power/supply/power_supply_core.c:45:20: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
      if (match_string(supply->supplied_from, supply->num_supplies,
                       ^
   include/linux/compiler.h:160:16: note: in definition of macro '__trace_if'
      ______r = !!(cond);     \
                   ^~~~
>> drivers/power/supply/power_supply_core.c:45:3: note: in expansion of macro 'if'
      if (match_string(supply->supplied_from, supply->num_supplies,
      ^~
   In file included from arch/x86/include/asm/page_32.h:34:0,
                    from arch/x86/include/asm/page.h:13,
                    from arch/x86/include/asm/thread_info.h:11,
                    from include/linux/thread_info.h:54,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:18,
                    from include/linux/module.h:10,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/string.h:137: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);
        ^~~~~~~~~~~~
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/power/supply/power_supply_core.c:13:
   drivers/power/supply/power_supply_core.c:51:20: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
      if (match_string(supplier->supplied_to, supplier->num_supplicants,
                       ^
   include/linux/compiler.h:149:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
   drivers/power/supply/power_supply_core.c:51:3: note: in expansion of macro 'if'
      if (match_string(supplier->supplied_to, supplier->num_supplicants,
      ^~
   In file included from arch/x86/include/asm/page_32.h:34:0,
                    from arch/x86/include/asm/page.h:13,
                    from arch/x86/include/asm/thread_info.h:11,
                    from include/linux/thread_info.h:54,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:18,
                    from include/linux/module.h:10,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/string.h:137: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);
        ^~~~~~~~~~~~
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/power/supply/power_supply_core.c:13:
   drivers/power/supply/power_supply_core.c:51:20: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
      if (match_string(supplier->supplied_to, supplier->num_supplicants,
                       ^
   include/linux/compiler.h:149:42: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                             ^~~~
   drivers/power/supply/power_supply_core.c:51:3: note: in expansion of macro 'if'
      if (match_string(supplier->supplied_to, supplier->num_supplicants,
      ^~
   In file included from arch/x86/include/asm/page_32.h:34:0,
                    from arch/x86/include/asm/page.h:13,
                    from arch/x86/include/asm/thread_info.h:11,
                    from include/linux/thread_info.h:54,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:18,
                    from include/linux/module.h:10,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/string.h:137: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);
        ^~~~~~~~~~~~
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/power/supply/power_supply_core.c:13:
   drivers/power/supply/power_supply_core.c:51:20: error: passing argument 1 of 'match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
      if (match_string(supplier->supplied_to, supplier->num_supplicants,
                       ^
   include/linux/compiler.h:160:16: note: in definition of macro '__trace_if'
      ______r = !!(cond);     \
                   ^~~~
   drivers/power/supply/power_supply_core.c:51:3: note: in expansion of macro 'if'
      if (match_string(supplier->supplied_to, supplier->num_supplicants,
      ^~
   In file included from arch/x86/include/asm/page_32.h:34:0,
                    from arch/x86/include/asm/page.h:13,

vim +/if +45 drivers/power/supply/power_supply_core.c

  > 13	#include <linux/module.h>
    14	#include <linux/types.h>
    15	#include <linux/init.h>
    16	#include <linux/slab.h>
    17	#include <linux/device.h>
    18	#include <linux/notifier.h>
    19	#include <linux/err.h>
    20	#include <linux/power_supply.h>
    21	#include <linux/thermal.h>
    22	#include "power_supply.h"
    23	
    24	/* exported for the APM Power driver, APM emulation */
    25	struct class *power_supply_class;
    26	EXPORT_SYMBOL_GPL(power_supply_class);
    27	
    28	ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
    29	EXPORT_SYMBOL_GPL(power_supply_notifier);
    30	
    31	static struct device_type power_supply_dev_type;
    32	
    33	#define POWER_SUPPLY_DEFERRED_REGISTER_TIME	msecs_to_jiffies(10)
    34	
    35	static bool __power_supply_is_supplied_by(struct power_supply *supplier,
    36						 struct power_supply *supply)
    37	{
    38		if (!supply->supplied_from && !supplier->supplied_to)
    39			return false;
    40	
    41		/* Support both supplied_to and supplied_from modes */
    42		if (supply->supplied_from) {
    43			if (!supplier->desc->name)
    44				return false;
  > 45			if (match_string(supply->supplied_from, supply->num_supplies,
    46					 supplier->desc->name) >= 0)
    47				return true;
    48		} else {
    49			if (!supply->desc->name)
    50				return false;
    51			if (match_string(supplier->supplied_to, supplier->num_supplicants,
    52					 supply->desc->name) >= 0)
    53				return true;
    54		}
    55	
    56		return false;
    57	}
    58	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot May 4, 2018, 12:33 p.m. UTC | #3
Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on battery/master]
[also build test WARNING on v4.17-rc3 next-20180503]
[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/Andy-Shevchenko/power-supply-Convert-to-use-match_string-helper/20180504-173513
base:   git://git.infradead.org/battery-2.6.git master
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> drivers/power/supply/power_supply_core.c:45:40: sparse: incorrect type in argument 1 (different modifiers) @@    expected char const *const *array @@    got const *array @@
   drivers/power/supply/power_supply_core.c:45:40:    expected char const *const *array
   drivers/power/supply/power_supply_core.c:45:40:    got char **supplied_from
   drivers/power/supply/power_supply_core.c:51:42: sparse: incorrect type in argument 1 (different modifiers) @@    expected char const *const *array @@    got const *array @@
   drivers/power/supply/power_supply_core.c:51:42:    expected char const *const *array
   drivers/power/supply/power_supply_core.c:51:42:    got char **supplied_to
   In file included from include/linux/kobject.h:21:0,
                    from include/linux/module.h:17,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/sysfs.h: In function 'sysfs_get_dirent':
   include/linux/sysfs.h:517:37: warning: pointer targets in passing argument 2 of 'kernfs_find_and_get' differ in signedness [-Wpointer-sign]
     return kernfs_find_and_get(parent, name);
                                        ^~~~
   In file included from include/linux/sysfs.h:15:0,
                    from include/linux/kobject.h:21,
                    from include/linux/module.h:17,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/kernfs.h:440:1: note: expected 'const char *' but argument is of type 'const unsigned char *'
    kernfs_find_and_get(struct kernfs_node *kn, const char *name)
    ^~~~~~~~~~~~~~~~~~~
   drivers/power/supply/power_supply_core.c: In function '__power_supply_is_supplied_by':
   drivers/power/supply/power_supply_core.c:45:20: warning: passing argument 1 of 'match_string' from incompatible pointer type [-Wincompatible-pointer-types]
      if (match_string(supply->supplied_from, supply->num_supplies,
                       ^~~~~~
   In file included from include/linux/bitmap.h:8:0,
                    from include/linux/cpumask.h:11,
                    from arch/x86/include/asm/cpumask.h:4,
                    from arch/x86/include/asm/msr.h:10,
                    from arch/x86/include/asm/processor.h:20,
                    from arch/x86/include/asm/cpufeature.h:4,
                    from arch/x86/include/asm/thread_info.h:52,
                    from include/linux/thread_info.h:54,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:18,
                    from include/linux/module.h:10,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/string.h:137: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);
        ^~~~~~~~~~~~
   drivers/power/supply/power_supply_core.c:51:20: warning: passing argument 1 of 'match_string' from incompatible pointer type [-Wincompatible-pointer-types]
      if (match_string(supplier->supplied_to, supplier->num_supplicants,
                       ^~~~~~~~
   In file included from include/linux/bitmap.h:8:0,
                    from include/linux/cpumask.h:11,
                    from arch/x86/include/asm/cpumask.h:4,
                    from arch/x86/include/asm/msr.h:10,
                    from arch/x86/include/asm/processor.h:20,
                    from arch/x86/include/asm/cpufeature.h:4,
                    from arch/x86/include/asm/thread_info.h:52,
                    from include/linux/thread_info.h:54,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/seqlock.h:35,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:18,
                    from include/linux/module.h:10,
                    from drivers/power/supply/power_supply_core.c:13:
   include/linux/string.h:137: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);
        ^~~~~~~~~~~~

vim +45 drivers/power/supply/power_supply_core.c

    34	
    35	static bool __power_supply_is_supplied_by(struct power_supply *supplier,
    36						 struct power_supply *supply)
    37	{
    38		if (!supply->supplied_from && !supplier->supplied_to)
    39			return false;
    40	
    41		/* Support both supplied_to and supplied_from modes */
    42		if (supply->supplied_from) {
    43			if (!supplier->desc->name)
    44				return false;
  > 45			if (match_string(supply->supplied_from, supply->num_supplies,
    46					 supplier->desc->name) >= 0)
    47				return true;
    48		} else {
    49			if (!supply->desc->name)
    50				return false;
    51			if (match_string(supplier->supplied_to, supplier->num_supplicants,
    52					 supply->desc->name) >= 0)
    53				return true;
    54		}
    55	
    56		return false;
    57	}
    58	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index ecd68c2053c5..c695d151695e 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -36,8 +36,6 @@  static struct device_type power_supply_dev_type;
 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
 					 struct power_supply *supply)
 {
-	int i;
-
 	if (!supply->supplied_from && !supplier->supplied_to)
 		return false;
 
@@ -45,15 +43,15 @@  static bool __power_supply_is_supplied_by(struct power_supply *supplier,
 	if (supply->supplied_from) {
 		if (!supplier->desc->name)
 			return false;
-		for (i = 0; i < supply->num_supplies; i++)
-			if (!strcmp(supplier->desc->name, supply->supplied_from[i]))
-				return true;
+		if (match_string(supply->supplied_from, supply->num_supplies,
+				 supplier->desc->name) >= 0)
+			return true;
 	} else {
 		if (!supply->desc->name)
 			return false;
-		for (i = 0; i < supplier->num_supplicants; i++)
-			if (!strcmp(supplier->supplied_to[i], supply->desc->name))
-				return true;
+		if (match_string(supplier->supplied_to, supplier->num_supplicants,
+				 supply->desc->name) >= 0)
+			return true;
 	}
 
 	return false;