All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver core: cleanup kstrto*() usage
@ 2020-11-22 12:10 Alexey Dobriyan
  2020-11-23  0:31   ` kernel test robot
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2020-11-22 12:10 UTC (permalink / raw
  To: gregkh, rafael; +Cc: linux-kernel

kstrto*() functions can write result directly to target memory
if no additional checks needs to be done.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 drivers/base/core.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1701,12 +1701,10 @@ ssize_t device_store_ulong(struct device *dev,
 {
 	struct dev_ext_attribute *ea = to_ext_attr(attr);
 	int ret;
-	unsigned long new;
 
-	ret = kstrtoul(buf, 0, &new);
+	ret = kstrtoul(buf, 0, (unsigned long *)ea->var);
 	if (ret)
 		return ret;
-	*(unsigned long *)(ea->var) = new;
 	/* Always return full write size even if we didn't consume all */
 	return size;
 }
@@ -1726,16 +1724,12 @@ ssize_t device_store_int(struct device *dev,
 			 const char *buf, size_t size)
 {
 	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	int val;
 	int ret;
-	long new;
 
-	ret = kstrtol(buf, 0, &new);
+	ret = kstrtoint(buf, 0, (int *)ea->var);
 	if (ret)
 		return ret;
-
-	if (new > INT_MAX || new < INT_MIN)
-		return -EINVAL;
-	*(int *)(ea->var) = new;
 	/* Always return full write size even if we didn't consume all */
 	return size;
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] driver core: cleanup kstrto*() usage
@ 2020-11-22 15:32 kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-11-22 15:32 UTC (permalink / raw
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 3362 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20201122121018.GA48617@localhost.localdomain>
References: <20201122121018.GA48617@localhost.localdomain>
TO: Alexey Dobriyan <adobriyan@gmail.com>
TO: gregkh(a)linuxfoundation.org
TO: rafael(a)kernel.org
CC: linux-kernel(a)vger.kernel.org

Hi Alexey,

I love your patch! Perhaps something to improve:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on v5.10-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Alexey-Dobriyan/driver-core-cleanup-kstrto-usage/20201122-201458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 33c0c9bdf7a59051a654cd98b7d2b48ce0080967
:::::: branch date: 3 hours ago
:::::: commit date: 3 hours ago
compiler: riscv64-linux-gcc (GCC) 9.3.0

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


cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

   drivers/base/core.c:3196:10: warning: Identical inner 'return' condition is always true. [identicalInnerCondition]
     return *tmp;
            ^
   drivers/base/core.c:3195:6: note: outer condition: *tmp
    if (*tmp)
        ^
   drivers/base/core.c:3196:10: note: identical inner condition: *tmp
     return *tmp;
            ^
   drivers/base/core.c:3202:10: warning: Identical inner 'return' condition is always true. [identicalInnerCondition]
     return *tmp;
            ^
   drivers/base/core.c:3201:6: note: outer condition: *tmp
    if (*tmp)
        ^
   drivers/base/core.c:3202:10: note: identical inner condition: *tmp
     return *tmp;
            ^
>> drivers/base/core.c:1725:6: warning: Unused variable: val [unusedVariable]
    int val;
        ^

vim +1725 drivers/base/core.c

ca22e56debc57b Kay Sievers     2011-12-14  1719  
ca22e56debc57b Kay Sievers     2011-12-14  1720  ssize_t device_store_int(struct device *dev,
ca22e56debc57b Kay Sievers     2011-12-14  1721  			 struct device_attribute *attr,
ca22e56debc57b Kay Sievers     2011-12-14  1722  			 const char *buf, size_t size)
ca22e56debc57b Kay Sievers     2011-12-14  1723  {
ca22e56debc57b Kay Sievers     2011-12-14  1724  	struct dev_ext_attribute *ea = to_ext_attr(attr);
e7443ff26978ad Alexey Dobriyan 2020-11-22 @1725  	int val;
f88184bfee48d4 Kaitao cheng    2018-11-06  1726  	int ret;
f88184bfee48d4 Kaitao cheng    2018-11-06  1727  
e7443ff26978ad Alexey Dobriyan 2020-11-22  1728  	ret = kstrtoint(buf, 0, (int *)ea->var);
f88184bfee48d4 Kaitao cheng    2018-11-06  1729  	if (ret)
f88184bfee48d4 Kaitao cheng    2018-11-06  1730  		return ret;
ca22e56debc57b Kay Sievers     2011-12-14  1731  	/* Always return full write size even if we didn't consume all */
ca22e56debc57b Kay Sievers     2011-12-14  1732  	return size;
ca22e56debc57b Kay Sievers     2011-12-14  1733  }
ca22e56debc57b Kay Sievers     2011-12-14  1734  EXPORT_SYMBOL_GPL(device_store_int);
ca22e56debc57b Kay Sievers     2011-12-14  1735  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] driver core: cleanup kstrto*() usage
  2020-11-22 12:10 Alexey Dobriyan
@ 2020-11-23  0:31   ` kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-11-23  0:31 UTC (permalink / raw
  To: Alexey Dobriyan, gregkh, rafael; +Cc: kbuild-all, linux-kernel

Hi Alexey,

I love your patch! Perhaps something to improve:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on v5.10-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Alexey-Dobriyan/driver-core-cleanup-kstrto-usage/20201122-201458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 33c0c9bdf7a59051a654cd98b7d2b48ce0080967
compiler: riscv64-linux-gcc (GCC) 9.3.0

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


cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

   drivers/base/core.c:3196:10: warning: Identical inner 'return' condition is always true. [identicalInnerCondition]
     return *tmp;
            ^
   drivers/base/core.c:3195:6: note: outer condition: *tmp
    if (*tmp)
        ^
   drivers/base/core.c:3196:10: note: identical inner condition: *tmp
     return *tmp;
            ^
   drivers/base/core.c:3202:10: warning: Identical inner 'return' condition is always true. [identicalInnerCondition]
     return *tmp;
            ^
   drivers/base/core.c:3201:6: note: outer condition: *tmp
    if (*tmp)
        ^
   drivers/base/core.c:3202:10: note: identical inner condition: *tmp
     return *tmp;
            ^
>> drivers/base/core.c:1725:6: warning: Unused variable: val [unusedVariable]
    int val;
        ^

vim +1725 drivers/base/core.c

ca22e56debc57b Kay Sievers     2011-12-14  1719  
ca22e56debc57b Kay Sievers     2011-12-14  1720  ssize_t device_store_int(struct device *dev,
ca22e56debc57b Kay Sievers     2011-12-14  1721  			 struct device_attribute *attr,
ca22e56debc57b Kay Sievers     2011-12-14  1722  			 const char *buf, size_t size)
ca22e56debc57b Kay Sievers     2011-12-14  1723  {
ca22e56debc57b Kay Sievers     2011-12-14  1724  	struct dev_ext_attribute *ea = to_ext_attr(attr);
e7443ff26978ad Alexey Dobriyan 2020-11-22 @1725  	int val;
f88184bfee48d4 Kaitao cheng    2018-11-06  1726  	int ret;
f88184bfee48d4 Kaitao cheng    2018-11-06  1727  
e7443ff26978ad Alexey Dobriyan 2020-11-22  1728  	ret = kstrtoint(buf, 0, (int *)ea->var);
f88184bfee48d4 Kaitao cheng    2018-11-06  1729  	if (ret)
f88184bfee48d4 Kaitao cheng    2018-11-06  1730  		return ret;
ca22e56debc57b Kay Sievers     2011-12-14  1731  	/* Always return full write size even if we didn't consume all */
ca22e56debc57b Kay Sievers     2011-12-14  1732  	return size;
ca22e56debc57b Kay Sievers     2011-12-14  1733  }
ca22e56debc57b Kay Sievers     2011-12-14  1734  EXPORT_SYMBOL_GPL(device_store_int);
ca22e56debc57b Kay Sievers     2011-12-14  1735  

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] driver core: cleanup kstrto*() usage
@ 2020-11-23  0:31   ` kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-11-23  0:31 UTC (permalink / raw
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3012 bytes --]

Hi Alexey,

I love your patch! Perhaps something to improve:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on v5.10-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Alexey-Dobriyan/driver-core-cleanup-kstrto-usage/20201122-201458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 33c0c9bdf7a59051a654cd98b7d2b48ce0080967
compiler: riscv64-linux-gcc (GCC) 9.3.0

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


cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

   drivers/base/core.c:3196:10: warning: Identical inner 'return' condition is always true. [identicalInnerCondition]
     return *tmp;
            ^
   drivers/base/core.c:3195:6: note: outer condition: *tmp
    if (*tmp)
        ^
   drivers/base/core.c:3196:10: note: identical inner condition: *tmp
     return *tmp;
            ^
   drivers/base/core.c:3202:10: warning: Identical inner 'return' condition is always true. [identicalInnerCondition]
     return *tmp;
            ^
   drivers/base/core.c:3201:6: note: outer condition: *tmp
    if (*tmp)
        ^
   drivers/base/core.c:3202:10: note: identical inner condition: *tmp
     return *tmp;
            ^
>> drivers/base/core.c:1725:6: warning: Unused variable: val [unusedVariable]
    int val;
        ^

vim +1725 drivers/base/core.c

ca22e56debc57b Kay Sievers     2011-12-14  1719  
ca22e56debc57b Kay Sievers     2011-12-14  1720  ssize_t device_store_int(struct device *dev,
ca22e56debc57b Kay Sievers     2011-12-14  1721  			 struct device_attribute *attr,
ca22e56debc57b Kay Sievers     2011-12-14  1722  			 const char *buf, size_t size)
ca22e56debc57b Kay Sievers     2011-12-14  1723  {
ca22e56debc57b Kay Sievers     2011-12-14  1724  	struct dev_ext_attribute *ea = to_ext_attr(attr);
e7443ff26978ad Alexey Dobriyan 2020-11-22 @1725  	int val;
f88184bfee48d4 Kaitao cheng    2018-11-06  1726  	int ret;
f88184bfee48d4 Kaitao cheng    2018-11-06  1727  
e7443ff26978ad Alexey Dobriyan 2020-11-22  1728  	ret = kstrtoint(buf, 0, (int *)ea->var);
f88184bfee48d4 Kaitao cheng    2018-11-06  1729  	if (ret)
f88184bfee48d4 Kaitao cheng    2018-11-06  1730  		return ret;
ca22e56debc57b Kay Sievers     2011-12-14  1731  	/* Always return full write size even if we didn't consume all */
ca22e56debc57b Kay Sievers     2011-12-14  1732  	return size;
ca22e56debc57b Kay Sievers     2011-12-14  1733  }
ca22e56debc57b Kay Sievers     2011-12-14  1734  EXPORT_SYMBOL_GPL(device_store_int);
ca22e56debc57b Kay Sievers     2011-12-14  1735  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-23  0:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-22 15:32 [PATCH] driver core: cleanup kstrto*() usage kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2020-11-22 12:10 Alexey Dobriyan
2020-11-23  0:31 ` kernel test robot
2020-11-23  0:31   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.