Skip to contentSkip to conversation

misc: apds990x: Use sysfs_match_string() helper

PATCH Superseded Andy Shevchenko 4 participants 5 messages Jun 9, 2017 – Jun 11, 2017 Char and misc drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: apds990x: Use sysfs_match_string() helper

Use sysfs_match_string() helper instead of open coded variant.

Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/misc/apds990x.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/misc/apds990x.c +6 -6
index c341164edaad..e9298f9d1588 100644
@@ -856,13 +856,13 @@ static ssize_t apds990x_prox_reporting_mode_store(struct device *dev,
 				  const char *buf, size_t len)
 {
 	struct apds990x_chip *chip =  dev_get_drvdata(dev);
+	int ret;
 
-	if (sysfs_streq(buf, reporting_modes[0]))
-		chip->prox_continuous_mode = 0;
-	else if (sysfs_streq(buf, reporting_modes[1]))
-		chip->prox_continuous_mode = 1;
-	else
-		return -EINVAL;
+	ret = sysfs_match_string(reporting_modes, buf);
+	if (ret < 0)
+		return ret;
+
+	chip->prox_continuous_mode = ret;
 	return len;
 }
 
Signature · 1 line
2.11.0
#1 lore raw
url: https://github.com/0day-ci/linux/commits/Andy-Shevchenko/misc-apds990x-Use-sysfs_match_string-helper/20170610-131929 config: m68k-allyesconfig (attached as .config) compiler: m68k-linux-gcc…

Hi Andy,

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on v4.12-rc4 next-20170609]
[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/misc-apds990x-Use-sysfs_match_string-helper/20170610-131929
config: m68k-allyesconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 4.9.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=m68k

All warnings (new ones prefixed by >>):

In file included from include/linux/bitmap.h:8:0,

                    from include/linux/nodemask.h:94,
                    from include/linux/mmzone.h:16,
                    from include/linux/gfp.h:5,
                    from include/linux/kmod.h:22,
                    from include/linux/module.h:13,
                    from drivers//misc/apds990x.c:26:
   drivers//misc/apds990x.c: In function 'apds990x_prox_reporting_mode_store':
>> include/linux/string.h:155:36: warning: passing argument 1 of '__sysfs_match_string' from incompatible pointer type
    #define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)
                                       ^
>> drivers//misc/apds990x.c:861:8: note: in expansion of macro 'sysfs_match_string'
     ret = sysfs_match_string(reporting_modes, buf);
           ^
   include/linux/string.h:146:5: note: expected 'const char * const*' but argument is of type 'const char (*)[9]'
    int __sysfs_match_string(const char * const *array, size_t n, const char *s);
        ^
--
   In file included from include/linux/bitmap.h:8:0,
                    from include/linux/nodemask.h:94,
                    from include/linux/mmzone.h:16,
                    from include/linux/gfp.h:5,
                    from include/linux/kmod.h:22,
                    from include/linux/module.h:13,
                    from drivers/misc/apds990x.c:26:
   drivers/misc/apds990x.c: In function 'apds990x_prox_reporting_mode_store':
>> include/linux/string.h:155:36: warning: passing argument 1 of '__sysfs_match_string' from incompatible pointer type
    #define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)
                                       ^
   drivers/misc/apds990x.c:861:8: note: in expansion of macro 'sysfs_match_string'
     ret = sysfs_match_string(reporting_modes, buf);
           ^
   include/linux/string.h:146:5: note: expected 'const char * const*' but argument is of type 'const char (*)[9]'
    int __sysfs_match_string(const char * const *array, size_t n, const char *s);
        ^

vim +/sysfs_match_string +861 drivers//misc/apds990x.c

845
846 static ssize_t apds990x_prox_reporting_mode_show(struct device *dev,
847 struct device_attribute *attr, char *buf)
848 {
849 struct apds990x_chip *chip = dev_get_drvdata(dev);
850 return sprintf(buf, "%s\n",
851 reporting_modes[!!chip->prox_continuous_mode]);
852 }
853
854 static ssize_t apds990x_prox_reporting_mode_store(struct device *dev,
855 struct device_attribute *attr,
856 const char *buf, size_t len)
857 {
858 struct apds990x_chip *chip = dev_get_drvdata(dev);
859 int ret;
860

 > 861		ret = sysfs_match_string(reporting_modes, buf);

862 if (ret < 0)
863 return ret;
864
865 chip->prox_continuous_mode = ret;
866 return len;
867 }
868
869 static DEVICE_ATTR(prox0_reporting_mode, S_IRUGO | S_IWUSR,

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

#2 lore raw
In reply to Andy Shevchenko
url: https://github.com/0day-ci/linux/commits/Andy-Shevchenko/misc-apds990x-Use-sysfs_match_string-helper/20170610-131929 config: x86_64-rhel (attached as .config) compiler: gcc-6 (Debian 6.2.0-3)…

Hi Andy,

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v4.12-rc4 next-20170609]
[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/misc-apds990x-Use-sysfs_match_string-helper/20170610-131929
config: x86_64-rhel (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

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:37,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:80,
                    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/misc/apds990x.c:26:
   drivers/misc/apds990x.c: In function 'apds990x_prox_reporting_mode_store':
>> drivers/misc/apds990x.c:861:27: error: passing argument 1 of '__sysfs_match_string' from incompatible pointer type [-Werror=incompatible-pointer-types]
     ret = sysfs_match_string(reporting_modes, buf);
                              ^
   include/linux/string.h:155:57: note: in definition of macro 'sysfs_match_string'
    #define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)
                                                            ^~
   include/linux/string.h:146:5: note: expected 'const char * const*' but argument is of type 'const char (*)[9]'
    int __sysfs_match_string(const char * const *array, size_t n, const char *s);
        ^~~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/__sysfs_match_string +861 drivers/misc/apds990x.c

855 struct device_attribute *attr,
856 const char *buf, size_t len)
857 {
858 struct apds990x_chip *chip = dev_get_drvdata(dev);
859 int ret;
860

 > 861		ret = sysfs_match_string(reporting_modes, buf);

862 if (ret < 0)
863 return ret;
864

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

#4 lore raw
Quoted 11 lines · Greg Kroah-Hartman
Quoted 8 lines · Andy Shevchenko

Use sysfs_match_string() helper instead of open coded variant.

Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/misc/apds990x.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

kbuild is failing :(

reporting_modes[] is not an array of string pointers, but an array of 9-byte arrays. Converting it to an array of pointers should fix this.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds