Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [groeck-staging:hwmon-next 13/13] drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false
@ 2025-04-09  2:11 kernel test robot
  2025-04-09  2:51 ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: kernel test robot @ 2025-04-09  2:11 UTC (permalink / raw)
  To: Alexander Stein; +Cc: llvm, oe-kbuild-all, linux-hwmon, Guenter Roeck

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
head:   d6b1492c9c2e7f2659b63a165ea45ab556c0df0c
commit: d6b1492c9c2e7f2659b63a165ea45ab556c0df0c [13/13] hwmon: (gpio-fan) Add regulator support
config: riscv-randconfig-001-20250409 (https://download.01.org/0day-ci/archive/20250409/202504091047.biuX8Kl2-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250409/202504091047.biuX8Kl2-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504091047.biuX8Kl2-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
     250 |         if (val == 0)
         |             ^~~~~~~~
   drivers/hwmon/gpio-fan.c:255:9: note: uninitialized use occurs here
     255 |         return ret ? ret : count;
         |                ^~~
   drivers/hwmon/gpio-fan.c:250:2: note: remove the 'if' if its condition is always true
     250 |         if (val == 0)
         |         ^~~~~~~~~~~~~
     251 |                 ret = set_fan_speed(fan_data, fan_data->num_speed - 1);
   drivers/hwmon/gpio-fan.c:237:9: note: initialize the variable 'ret' to silence this warning
     237 |         int ret;
         |                ^
         |                 = 0
   1 warning generated.


vim +250 drivers/hwmon/gpio-fan.c

d6fe1360f42e86 Simon Guinot       2010-10-22  230  
c490c63e9505a3 Julia Lawall       2016-12-22  231  static ssize_t pwm1_enable_store(struct device *dev,
c490c63e9505a3 Julia Lawall       2016-12-22  232  				 struct device_attribute *attr,
d6fe1360f42e86 Simon Guinot       2010-10-22  233  				 const char *buf, size_t count)
d6fe1360f42e86 Simon Guinot       2010-10-22  234  {
d6fe1360f42e86 Simon Guinot       2010-10-22  235  	struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
d6fe1360f42e86 Simon Guinot       2010-10-22  236  	unsigned long val;
d6b1492c9c2e7f Alexander Stein    2025-04-08  237  	int ret;
d6fe1360f42e86 Simon Guinot       2010-10-22  238  
179c4fdb565dd2 Frans Meulenbroeks 2012-01-04  239  	if (kstrtoul(buf, 10, &val) || val > 1)
d6fe1360f42e86 Simon Guinot       2010-10-22  240  		return -EINVAL;
d6fe1360f42e86 Simon Guinot       2010-10-22  241  
d6fe1360f42e86 Simon Guinot       2010-10-22  242  	if (fan_data->pwm_enable == val)
d6fe1360f42e86 Simon Guinot       2010-10-22  243  		return count;
d6fe1360f42e86 Simon Guinot       2010-10-22  244  
d6fe1360f42e86 Simon Guinot       2010-10-22  245  	mutex_lock(&fan_data->lock);
d6fe1360f42e86 Simon Guinot       2010-10-22  246  
d6fe1360f42e86 Simon Guinot       2010-10-22  247  	fan_data->pwm_enable = val;
d6fe1360f42e86 Simon Guinot       2010-10-22  248  
d6fe1360f42e86 Simon Guinot       2010-10-22  249  	/* Disable manual control mode: set fan at full speed. */
d6fe1360f42e86 Simon Guinot       2010-10-22 @250  	if (val == 0)
d6b1492c9c2e7f Alexander Stein    2025-04-08  251  		ret = set_fan_speed(fan_data, fan_data->num_speed - 1);
d6fe1360f42e86 Simon Guinot       2010-10-22  252  
d6fe1360f42e86 Simon Guinot       2010-10-22  253  	mutex_unlock(&fan_data->lock);
d6fe1360f42e86 Simon Guinot       2010-10-22  254  
d6b1492c9c2e7f Alexander Stein    2025-04-08  255  	return ret ? ret : count;
d6fe1360f42e86 Simon Guinot       2010-10-22  256  }
d6fe1360f42e86 Simon Guinot       2010-10-22  257  

:::::: The code at line 250 was first introduced by commit
:::::: d6fe1360f42e86262153927986dea6502daff703 hwmon: add generic GPIO fan driver

:::::: TO: Simon Guinot <sguinot@lacie.com>
:::::: CC: Guenter Roeck <guenter.roeck@ericsson.com>

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [groeck-staging:hwmon-next 13/13] drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false
  2025-04-09  2:11 [groeck-staging:hwmon-next 13/13] drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false kernel test robot
@ 2025-04-09  2:51 ` Guenter Roeck
  2025-04-09  6:50   ` Alexander Stein
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2025-04-09  2:51 UTC (permalink / raw)
  To: kernel test robot, Alexander Stein; +Cc: llvm, oe-kbuild-all, linux-hwmon

Alexander,

On 4/8/25 19:11, kernel test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
> head:   d6b1492c9c2e7f2659b63a165ea45ab556c0df0c
> commit: d6b1492c9c2e7f2659b63a165ea45ab556c0df0c [13/13] hwmon: (gpio-fan) Add regulator support
> config: riscv-randconfig-001-20250409 (https://download.01.org/0day-ci/archive/20250409/202504091047.biuX8Kl2-lkp@intel.com/config)
> compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250409/202504091047.biuX8Kl2-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202504091047.biuX8Kl2-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>>> drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
>       250 |         if (val == 0)
>           |             ^~~~~~~~
>     drivers/hwmon/gpio-fan.c:255:9: note: uninitialized use occurs here
>       255 |         return ret ? ret : count;
>           |                ^~~
>     drivers/hwmon/gpio-fan.c:250:2: note: remove the 'if' if its condition is always true
>       250 |         if (val == 0)
>           |         ^~~~~~~~~~~~~
>       251 |                 ret = set_fan_speed(fan_data, fan_data->num_speed - 1);
>     drivers/hwmon/gpio-fan.c:237:9: note: initialize the variable 'ret' to silence this warning
>       237 |         int ret;
>           |                ^
>           |                 = 0
>     1 warning generated.
> 

I dropped the patch from linux-next. Please fix and make sure there are no
such problems before resubmitting.

Thanks,
Guenter
> 
> vim +250 drivers/hwmon/gpio-fan.c
> 
> d6fe1360f42e86 Simon Guinot       2010-10-22  230
> c490c63e9505a3 Julia Lawall       2016-12-22  231  static ssize_t pwm1_enable_store(struct device *dev,
> c490c63e9505a3 Julia Lawall       2016-12-22  232  				 struct device_attribute *attr,
> d6fe1360f42e86 Simon Guinot       2010-10-22  233  				 const char *buf, size_t count)
> d6fe1360f42e86 Simon Guinot       2010-10-22  234  {
> d6fe1360f42e86 Simon Guinot       2010-10-22  235  	struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
> d6fe1360f42e86 Simon Guinot       2010-10-22  236  	unsigned long val;
> d6b1492c9c2e7f Alexander Stein    2025-04-08  237  	int ret;
> d6fe1360f42e86 Simon Guinot       2010-10-22  238
> 179c4fdb565dd2 Frans Meulenbroeks 2012-01-04  239  	if (kstrtoul(buf, 10, &val) || val > 1)
> d6fe1360f42e86 Simon Guinot       2010-10-22  240  		return -EINVAL;
> d6fe1360f42e86 Simon Guinot       2010-10-22  241
> d6fe1360f42e86 Simon Guinot       2010-10-22  242  	if (fan_data->pwm_enable == val)
> d6fe1360f42e86 Simon Guinot       2010-10-22  243  		return count;
> d6fe1360f42e86 Simon Guinot       2010-10-22  244
> d6fe1360f42e86 Simon Guinot       2010-10-22  245  	mutex_lock(&fan_data->lock);
> d6fe1360f42e86 Simon Guinot       2010-10-22  246
> d6fe1360f42e86 Simon Guinot       2010-10-22  247  	fan_data->pwm_enable = val;
> d6fe1360f42e86 Simon Guinot       2010-10-22  248
> d6fe1360f42e86 Simon Guinot       2010-10-22  249  	/* Disable manual control mode: set fan at full speed. */
> d6fe1360f42e86 Simon Guinot       2010-10-22 @250  	if (val == 0)
> d6b1492c9c2e7f Alexander Stein    2025-04-08  251  		ret = set_fan_speed(fan_data, fan_data->num_speed - 1);
> d6fe1360f42e86 Simon Guinot       2010-10-22  252
> d6fe1360f42e86 Simon Guinot       2010-10-22  253  	mutex_unlock(&fan_data->lock);
> d6fe1360f42e86 Simon Guinot       2010-10-22  254
> d6b1492c9c2e7f Alexander Stein    2025-04-08  255  	return ret ? ret : count;
> d6fe1360f42e86 Simon Guinot       2010-10-22  256  }
> d6fe1360f42e86 Simon Guinot       2010-10-22  257
> 
> :::::: The code at line 250 was first introduced by commit
> :::::: d6fe1360f42e86262153927986dea6502daff703 hwmon: add generic GPIO fan driver
> 
> :::::: TO: Simon Guinot <sguinot@lacie.com>
> :::::: CC: Guenter Roeck <guenter.roeck@ericsson.com>
> 


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

* Re: [groeck-staging:hwmon-next 13/13] drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false
  2025-04-09  2:51 ` Guenter Roeck
@ 2025-04-09  6:50   ` Alexander Stein
  2025-04-09 16:02     ` Nathan Chancellor
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Stein @ 2025-04-09  6:50 UTC (permalink / raw)
  To: kernel test robot, Guenter Roeck; +Cc: llvm, oe-kbuild-all, linux-hwmon

Hi Guenter,

Am Mittwoch, 9. April 2025, 04:51:35 CEST schrieb Guenter Roeck:
> Alexander,
> 
> On 4/8/25 19:11, kernel test robot wrote:
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
> > head:   d6b1492c9c2e7f2659b63a165ea45ab556c0df0c
> > commit: d6b1492c9c2e7f2659b63a165ea45ab556c0df0c [13/13] hwmon: (gpio-fan) Add regulator support
> > config: riscv-randconfig-001-20250409 (https://download.01.org/0day-ci/archive/20250409/202504091047.biuX8Kl2-lkp@intel.com/config)
> > compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
> > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250409/202504091047.biuX8Kl2-lkp@intel.com/reproduce)
> > 
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202504091047.biuX8Kl2-lkp@intel.com/
> > 
> > All warnings (new ones prefixed by >>):
> > 
> >>> drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
> >       250 |         if (val == 0)
> >           |             ^~~~~~~~
> >     drivers/hwmon/gpio-fan.c:255:9: note: uninitialized use occurs here
> >       255 |         return ret ? ret : count;
> >           |                ^~~
> >     drivers/hwmon/gpio-fan.c:250:2: note: remove the 'if' if its condition is always true
> >       250 |         if (val == 0)
> >           |         ^~~~~~~~~~~~~
> >       251 |                 ret = set_fan_speed(fan_data, fan_data->num_speed - 1);
> >     drivers/hwmon/gpio-fan.c:237:9: note: initialize the variable 'ret' to silence this warning
> >       237 |         int ret;
> >           |                ^
> >           |                 = 0
> >     1 warning generated.
> > 
> 
> I dropped the patch from linux-next. Please fix and make sure there are no
> such problems before resubmitting.

Oh, surprising. A W=1 build on my machine doesn't raise this warning. I'm not
sure if this is specific to riscv or clang. Nevertheless this is correct and
I'll send a fixed one.

Thanks and best regards
Alexander

> Thanks,
> Guenter
> > 
> > vim +250 drivers/hwmon/gpio-fan.c
> > 
> > d6fe1360f42e86 Simon Guinot       2010-10-22  230
> > c490c63e9505a3 Julia Lawall       2016-12-22  231  static ssize_t pwm1_enable_store(struct device *dev,
> > c490c63e9505a3 Julia Lawall       2016-12-22  232  				 struct device_attribute *attr,
> > d6fe1360f42e86 Simon Guinot       2010-10-22  233  				 const char *buf, size_t count)
> > d6fe1360f42e86 Simon Guinot       2010-10-22  234  {
> > d6fe1360f42e86 Simon Guinot       2010-10-22  235  	struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
> > d6fe1360f42e86 Simon Guinot       2010-10-22  236  	unsigned long val;
> > d6b1492c9c2e7f Alexander Stein    2025-04-08  237  	int ret;
> > d6fe1360f42e86 Simon Guinot       2010-10-22  238
> > 179c4fdb565dd2 Frans Meulenbroeks 2012-01-04  239  	if (kstrtoul(buf, 10, &val) || val > 1)
> > d6fe1360f42e86 Simon Guinot       2010-10-22  240  		return -EINVAL;
> > d6fe1360f42e86 Simon Guinot       2010-10-22  241
> > d6fe1360f42e86 Simon Guinot       2010-10-22  242  	if (fan_data->pwm_enable == val)
> > d6fe1360f42e86 Simon Guinot       2010-10-22  243  		return count;
> > d6fe1360f42e86 Simon Guinot       2010-10-22  244
> > d6fe1360f42e86 Simon Guinot       2010-10-22  245  	mutex_lock(&fan_data->lock);
> > d6fe1360f42e86 Simon Guinot       2010-10-22  246
> > d6fe1360f42e86 Simon Guinot       2010-10-22  247  	fan_data->pwm_enable = val;
> > d6fe1360f42e86 Simon Guinot       2010-10-22  248
> > d6fe1360f42e86 Simon Guinot       2010-10-22  249  	/* Disable manual control mode: set fan at full speed. */
> > d6fe1360f42e86 Simon Guinot       2010-10-22 @250  	if (val == 0)
> > d6b1492c9c2e7f Alexander Stein    2025-04-08  251  		ret = set_fan_speed(fan_data, fan_data->num_speed - 1);
> > d6fe1360f42e86 Simon Guinot       2010-10-22  252
> > d6fe1360f42e86 Simon Guinot       2010-10-22  253  	mutex_unlock(&fan_data->lock);
> > d6fe1360f42e86 Simon Guinot       2010-10-22  254
> > d6b1492c9c2e7f Alexander Stein    2025-04-08  255  	return ret ? ret : count;
> > d6fe1360f42e86 Simon Guinot       2010-10-22  256  }
> > d6fe1360f42e86 Simon Guinot       2010-10-22  257
> > 
> > :::::: The code at line 250 was first introduced by commit
> > :::::: d6fe1360f42e86262153927986dea6502daff703 hwmon: add generic GPIO fan driver
> > 
> > :::::: TO: Simon Guinot <sguinot@lacie.com>
> > :::::: CC: Guenter Roeck <guenter.roeck@ericsson.com>
> > 
> 
> 


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/



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

* Re: [groeck-staging:hwmon-next 13/13] drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false
  2025-04-09  6:50   ` Alexander Stein
@ 2025-04-09 16:02     ` Nathan Chancellor
  2025-04-10  8:35       ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2025-04-09 16:02 UTC (permalink / raw)
  To: Alexander Stein
  Cc: kernel test robot, Guenter Roeck, llvm, oe-kbuild-all,
	linux-hwmon

On Wed, Apr 09, 2025 at 08:50:14AM +0200, Alexander Stein wrote:
> Am Mittwoch, 9. April 2025, 04:51:35 CEST schrieb Guenter Roeck:
> > On 4/8/25 19:11, kernel test robot wrote:
> > > All warnings (new ones prefixed by >>):
> > > 
> > >>> drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
> > >       250 |         if (val == 0)
> > >           |             ^~~~~~~~
> > >     drivers/hwmon/gpio-fan.c:255:9: note: uninitialized use occurs here
> > >       255 |         return ret ? ret : count;
> > >           |                ^~~
> > >     drivers/hwmon/gpio-fan.c:250:2: note: remove the 'if' if its condition is always true
> > >       250 |         if (val == 0)
> > >           |         ^~~~~~~~~~~~~
> > >       251 |                 ret = set_fan_speed(fan_data, fan_data->num_speed - 1);
> > >     drivers/hwmon/gpio-fan.c:237:9: note: initialize the variable 'ret' to silence this warning
> > >       237 |         int ret;
> > >           |                ^
> > >           |                 = 0
> > >     1 warning generated.
> > > 
> > 
> > I dropped the patch from linux-next. Please fix and make sure there are no
> > such problems before resubmitting.
> 
> Oh, surprising. A W=1 build on my machine doesn't raise this warning. I'm not
> sure if this is specific to riscv or clang. Nevertheless this is correct and
> I'll send a fixed one.

Unfortunately, the kernel disabled GCC's version, -Wmaybe-uninitialized,
several years ago in commit 78a5255ffb6a ("Stop the ad-hoc games with
-Wno-maybe-initialized"), so you either need to add it yourself via
KCFLAGS or just do a quick pass with Clang's slightly weaker but more
reliable -Wsometimes-uninitialized. I have fast versions of clang
available on kernel.org to make doing this testing a little easier:
https://mirrors.edge.kernel.org/pub/tools/llvm/

Cheers,
Nathan

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

* Re: [groeck-staging:hwmon-next 13/13] drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false
  2025-04-09 16:02     ` Nathan Chancellor
@ 2025-04-10  8:35       ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2025-04-10  8:35 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Alexander Stein, kernel test robot, Guenter Roeck, llvm,
	oe-kbuild-all, linux-hwmon

Another option is Smatch.

https://github.com/error27/smatch

:! ~/progs/smatch/release/smatch_scripts/kchecker drivers/hwmon/gpio-fan.c
  CHECK   scripts/mod/empty.c
  CALL    scripts/checksyscalls.sh
  DESCEND objtool
  INSTALL libsubcmd_headers
  CC      drivers/hwmon/gpio-fan.o
  CHECK   drivers/hwmon/gpio-fan.c
drivers/hwmon/gpio-fan.c:145 set_fan_speed() warn: potential spectre issue 'fan_data->speed' [w] (local cap)
drivers/hwmon/gpio-fan.c:255 pwm1_enable_store() error: uninitialized symbol 'ret'.

I don't think the spectre v1 issue is real but I don't know very much
about spectre.

regards,
dan carpenter


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

end of thread, other threads:[~2025-04-10  8:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09  2:11 [groeck-staging:hwmon-next 13/13] drivers/hwmon/gpio-fan.c:250:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false kernel test robot
2025-04-09  2:51 ` Guenter Roeck
2025-04-09  6:50   ` Alexander Stein
2025-04-09 16:02     ` Nathan Chancellor
2025-04-10  8:35       ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox