diff mbox series

watchdog_dev: Remove unnecessary ‘0’ values from err

Message ID 20231021110538.441-1-fenghui@nfschina.com (mailing list archive)
State New
Headers show
Series watchdog_dev: Remove unnecessary ‘0’ values from err | expand

Commit Message

fenghui Oct. 21, 2023, 11:05 a.m. UTC
err is assigned first, so it does not need to initialize the assignment.

Signed-off-by: fenghui <fenghui@nfschina.com>
---
 drivers/watchdog/watchdog_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guenter Roeck Oct. 23, 2023, 12:03 a.m. UTC | #1
On 10/21/23 04:05, fenghui wrote:
> err is assigned first, so it does not need to initialize the assignment.
> 
> Signed-off-by: fenghui <fenghui@nfschina.com>
> ---
>   drivers/watchdog/watchdog_dev.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index 15df74e11a59..0868ccbcf92b 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -291,7 +291,7 @@ static int watchdog_start(struct watchdog_device *wdd)
>    */
>   static int watchdog_stop(struct watchdog_device *wdd)
>   {
> -	int err = 0;
> +	int err;
>   
>   	if (!watchdog_active(wdd))
>   		return 0;

NACK

...

        if (wdd->ops->stop) {
                 clear_bit(WDOG_HW_RUNNING, &wdd->status);
                 err = wdd->ops->stop(wdd);
                 trace_watchdog_stop(wdd, err);
         } else {
                 set_bit(WDOG_HW_RUNNING, &wdd->status);		<-- err is not set in this path
         }
kernel test robot Oct. 24, 2023, 3:55 p.m. UTC | #2
Hi fenghui,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.6-rc7 next-20231024]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/fenghui/watchdog_dev-Remove-unnecessary-0-values-from-err/20231021-190730
base:   linus/master
patch link:    https://lore.kernel.org/r/20231021110538.441-1-fenghui%40nfschina.com
patch subject: [PATCH] watchdog_dev: Remove unnecessary ‘0’ values from err
config: arm-omap1_defconfig (https://download.01.org/0day-ci/archive/20231024/202310242358.POvbqd5T-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231024/202310242358.POvbqd5T-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/202310242358.POvbqd5T-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/watchdog/watchdog_dev.c:305:6: warning: variable 'err' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
     305 |         if (wdd->ops->stop) {
         |             ^~~~~~~~~~~~~~
   drivers/watchdog/watchdog_dev.c:313:6: note: uninitialized use occurs here
     313 |         if (err == 0) {
         |             ^~~
   drivers/watchdog/watchdog_dev.c:305:2: note: remove the 'if' if its condition is always true
     305 |         if (wdd->ops->stop) {
         |         ^~~~~~~~~~~~~~~~~~~~
     306 |                 clear_bit(WDOG_HW_RUNNING, &wdd->status);
     307 |                 err = wdd->ops->stop(wdd);
     308 |                 trace_watchdog_stop(wdd, err);
     309 |         } else {
         |          ~~~~~~~
     310 |                 set_bit(WDOG_HW_RUNNING, &wdd->status);
         | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     311 |         }
         | ~~~~~~~~~
   drivers/watchdog/watchdog_dev.c:294:9: note: initialize the variable 'err' to silence this warning
     294 |         int err;
         |                ^
         |                 = 0
   1 warning generated.


vim +305 drivers/watchdog/watchdog_dev.c

234445b4e4542f Wim Van Sebroeck           2011-07-22  281  
234445b4e4542f Wim Van Sebroeck           2011-07-22  282  /*
ba6c89ab3b5878 Daniel Bristot de Oliveira 2022-02-11  283   * watchdog_stop - wrapper to stop the watchdog
ba6c89ab3b5878 Daniel Bristot de Oliveira 2022-02-11  284   * @wdd: The watchdog device to stop
b4ffb1909843b2 Guenter Roeck              2015-12-25  285   *
234445b4e4542f Wim Van Sebroeck           2011-07-22  286   * Stop the watchdog if it is still active and unmark it active.
7e192b9c4234d2 Wim Van Sebroeck           2011-07-22  287   * If the 'nowayout' feature was set, the watchdog cannot be stopped.
ba6c89ab3b5878 Daniel Bristot de Oliveira 2022-02-11  288   * The caller must hold wd_data->lock.
ba6c89ab3b5878 Daniel Bristot de Oliveira 2022-02-11  289   *
ba6c89ab3b5878 Daniel Bristot de Oliveira 2022-02-11  290   * Return: 0 on success or a negative errno code for failure.
234445b4e4542f Wim Van Sebroeck           2011-07-22  291   */
bc794ac3b5836e Guenter Roeck              2015-09-29  292  static int watchdog_stop(struct watchdog_device *wdd)
234445b4e4542f Wim Van Sebroeck           2011-07-22  293  {
585c761ac0ef85 fenghui                    2023-10-21  294  	int err;
e907df32725204 Hans de Goede              2012-05-22  295  
bc794ac3b5836e Guenter Roeck              2015-09-29  296  	if (!watchdog_active(wdd))
b4ffb1909843b2 Guenter Roeck              2015-12-25  297  		return 0;
7e192b9c4234d2 Wim Van Sebroeck           2011-07-22  298  
bc794ac3b5836e Guenter Roeck              2015-09-29  299  	if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) {
0254e953537c92 Guenter Roeck              2016-01-03  300  		pr_info("watchdog%d: nowayout prevents watchdog being stopped!\n",
0254e953537c92 Guenter Roeck              2016-01-03  301  			wdd->id);
b4ffb1909843b2 Guenter Roeck              2015-12-25  302  		return -EBUSY;
7e192b9c4234d2 Wim Van Sebroeck           2011-07-22  303  	}
234445b4e4542f Wim Van Sebroeck           2011-07-22  304  
3c10bbde10fe4d Guenter Roeck              2016-07-21 @305  	if (wdd->ops->stop) {
3c10bbde10fe4d Guenter Roeck              2016-07-21  306  		clear_bit(WDOG_HW_RUNNING, &wdd->status);
bc794ac3b5836e Guenter Roeck              2015-09-29  307  		err = wdd->ops->stop(wdd);
e25b091bed4946 Uwe Kleine-König           2022-10-08  308  		trace_watchdog_stop(wdd, err);
3c10bbde10fe4d Guenter Roeck              2016-07-21  309  	} else {
d0684c8a935495 Guenter Roeck              2016-02-28  310  		set_bit(WDOG_HW_RUNNING, &wdd->status);
3c10bbde10fe4d Guenter Roeck              2016-07-21  311  	}
d0684c8a935495 Guenter Roeck              2016-02-28  312  
664a39236e718f Guenter Roeck              2016-02-28  313  	if (err == 0) {
bc794ac3b5836e Guenter Roeck              2015-09-29  314  		clear_bit(WDOG_ACTIVE, &wdd->status);
ee142889e32f56 Guenter Roeck              2016-02-28  315  		watchdog_update_worker(wdd);
7b7d2fdc8c3e3f Curtis Klein               2021-02-03  316  		watchdog_hrtimer_pretimeout_stop(wdd);
664a39236e718f Guenter Roeck              2016-02-28  317  	}
7a87982420e5e1 Hans de Goede              2012-05-22  318  
234445b4e4542f Wim Van Sebroeck           2011-07-22  319  	return err;
7a87982420e5e1 Hans de Goede              2012-05-22  320  }
234445b4e4542f Wim Van Sebroeck           2011-07-22  321
diff mbox series

Patch

diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 15df74e11a59..0868ccbcf92b 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -291,7 +291,7 @@  static int watchdog_start(struct watchdog_device *wdd)
  */
 static int watchdog_stop(struct watchdog_device *wdd)
 {
-	int err = 0;
+	int err;
 
 	if (!watchdog_active(wdd))
 		return 0;