kernel/kthread.c:861:13: warning: variable 'ret' set but not used
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 72deda0abee6e705ae71a93f69f55e33be5bca5c commit: 4d13f4304fa43471bfea101658a11feec7b28ac0 kthread: Implement preferred affinity date: 3 weeks ago config: csky-randconfig-r022-20220420 (https://download.01.org/0day-ci/archive/20250130/[email protected]/config) compiler: csky-linux-gcc (GCC) 12.4.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250130/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
kernel/kthread.c: In function 'kthread_affine_preferred':
>> kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
861 | int ret;
| ^~~vim +/ret +861 kernel/kthread.c
855
856 int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)
857 {
858 struct kthread *kthread = to_kthread(p);
859 cpumask_var_t affinity;
860 unsigned long flags;
> 861 int ret;
862
863 if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE) || kthread->started) {
864 WARN_ON(1);
865 return -EINVAL;
866 }
867
868 WARN_ON_ONCE(kthread->preferred_affinity);
869
870 if (!zalloc_cpumask_var(&affinity, GFP_KERNEL))
871 return -ENOMEM;
872
873 kthread->preferred_affinity = kzalloc(sizeof(struct cpumask), GFP_KERNEL);
874 if (!kthread->preferred_affinity) {
875 ret = -ENOMEM;
876 goto out;
877 }
878
879 mutex_lock(&kthreads_hotplug_lock);
880 cpumask_copy(kthread->preferred_affinity, mask);
881 WARN_ON_ONCE(!list_empty(&kthread->hotplug_node));
882 list_add_tail(&kthread->hotplug_node, &kthreads_hotplug);
883 kthread_fetch_affinity(kthread, affinity);
884
885 /* It's safe because the task is inactive. */
886 raw_spin_lock_irqsave(&p->pi_lock, flags);
887 do_set_cpus_allowed(p, affinity);
888 raw_spin_unlock_irqrestore(&p->pi_lock, flags);
889
890 mutex_unlock(&kthreads_hotplug_lock);
891 out:
892 free_cpumask_var(affinity);
893
894 return 0;
895 }
896
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 1/1 kthread: Fix build warning variable 'ret' set but not used
Fix the following build time warning in kthread:
kernel/kthread.c: In function 'kthread_affine_preferred':
Quoted 1 line
Quoted 1 line
kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
861 | int ret;
| ^~~--- kernel/kthread.c | 2 -- 1 file changed, 2 deletions(-)
kernel/kthread.c +0 -2
@@ -859,7 +859,6 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)struct kthread *kthread =to_kthread (p);cpumask_var_t affinity;unsigned long flags; -int ret;if (!wait_task_inactive (p,TASK_UNINTERRUPTIBLE ) || kthread->started) {WARN_ON (1 );
@@ -873,7 +872,6 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask) kthread->preferred_affinity =kzalloc (sizeof (struct cpumask ),GFP_KERNEL );if (!kthread->preferred_affinity) { - ret = -ENOMEM ; goto out; }
Signature · 1 line
2.34.1
Re: [PATCH] kthread: Fix build warning variable 'ret' set but not used
Quoted 27 lines · Dhruva Gole
Fix the following build time warning in kthread:
kernel/kthread.c: In function 'kthread_affine_preferred':Quoted 1 line
Quoted 1 line
kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]861 | int ret; | ^~~Reported-by kernel test robot <[email protected]>Signed-off-by Dhruva Gole <[email protected]>--- kernel/kthread.c | 2 -- 1 file changed, 2 deletions(-)kernel/kthread.c +0
-1@@ -859,7 +859,6 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)struct kthread *kthread =to_kthread (p);cpumask_var_t affinity;unsigned long flags; -int ret;if (!wait_task_inactive (p,TASK_UNINTERRUPTIBLE ) || kthread->started) {WARN_ON (1 );
kernel/kthread.c int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask) · line 876
Quoted 6 lines
kernel/kthread.c +0
-1@@ -873,7 +872,6 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask) kthread->preferred_affinity =kzalloc (sizeof (struct cpumask ),GFP_KERNEL );if (!kthread->preferred_affinity) { - ret = -ENOMEM ; goto out; }
This seems wrong? This is an error path, so removing this causes "return 0" to happen. I would take a look at the commit history to figure out when this mistake was introduced and adjust it correctly. I would have expected "int ret = 0;", and "return ret;" at "out:" to be the fix.
Signature · 1 line
Kees Cook
Re: [PATCH] kthread: Fix build warning variable 'ret' set but not used
Quoted 29 lines · Kees Cook
Quoted 28 lines · Dhruva Gole
Fix the following build time warning in kthread:
kernel/kthread.c: In function 'kthread_affine_preferred':Quoted 1 line
Quoted 1 line
kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]861 | int ret; | ^~~Reported-by kernel test robot <[email protected]>Signed-off-by Dhruva Gole <[email protected]>--- kernel/kthread.c | 2 -- 1 file changed, 2 deletions(-)kernel/kthread.c +0
-1@@ -859,7 +859,6 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)struct kthread *kthread =to_kthread (p);cpumask_var_t affinity;unsigned long flags; -int ret;if (!wait_task_inactive (p,TASK_UNINTERRUPTIBLE ) || kthread->started) {WARN_ON (1 );@@ -873,7 +872,6 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)
Quoted 10 lines
kernel/kthread.c int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask) · line 876
Quoted 5 lines
kernel/kthread.c +0
-1kthread->preferred_affinity =kzalloc (sizeof (struct cpumask ),GFP_KERNEL );if (!kthread->preferred_affinity) { - ret = -ENOMEM ; goto out; }This seems wrong? This is an error path, so removing this causes "return 0" to happen. I would take a look at the commit history to figure out when this mistake was introduced and adjust it correctly. I would have expected "int ret = 0;", and "return ret;" at "out:" to be the fix.
Seems like it was introduced in commit 4d13f4304fa43 ("kthread: Implement preferred affinity")
This was a bit wrong to begin with. But you're right I will follow your suggestion and send out a v2.
Signature · 3 lines
Best regards, Dhruva Gole Texas Instruments Incorporated
PATCH v2 1/1 kthread: Fix build warning variable 'ret' set but not used
In reply to Dhruva GoleFix the following build time warning in kthread:
kernel/kthread.c: In function 'kthread_affine_preferred':
Quoted 1 line
Quoted 1 line
kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
861 | int ret;
| ^~~---
Link to v1:
https://lore.kernel.org/lkml/[email protected]/
Changelog:
- Use ret value toward the end return as per Kees' suggestion
---
kernel/kthread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kthread.c +2 -2
@@ -859,7 +859,7 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)struct kthread *kthread =to_kthread (p);cpumask_var_t affinity;unsigned long flags; -int ret; +int ret =0 ;if (!wait_task_inactive (p,TASK_UNINTERRUPTIBLE ) || kthread->started) {WARN_ON (1 );
@@ -892,7 +892,7 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask) out:free_cpumask_var (affinity); -return 0 ; +return ret; }/*
base-commit: 40b8e93e17bff4a4e0cc129e04f9fdf5daa5397e
Signature · 1 line
2.34.1
Re: [PATCH V2] kthread: Fix build warning variable 'ret' set but not used
Hi Dhruva,
Quoted 10 lines · Dhruva Gole
Fix the following build time warning in kthread:
kernel/kthread.c: In function 'kthread_affine_preferred':Quoted 1 line
Quoted 1 line
kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]861 | int ret; | ^~~Reported-by kernel test robot <[email protected]>Signed-off-by Dhruva Gole <[email protected]>
Thanks for your patch but another similar fix was already pending. I have sent the pull request there:
Re: [PATCH V2] kthread: Fix build warning variable 'ret' set but not used
Quoted 10 lines · Frederic Weisbecker
Hi Dhruva,
Quoted 7 lines · Dhruva Gole
Fix the following build time warning in kthread:
kernel/kthread.c: In function 'kthread_affine_preferred':Quoted 1 line
Quoted 1 line
kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]861 | int ret; | ^~~
Quoted 8 lines
Quoted 3 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Dhruva Gole <[email protected]>Thanks for your patch but another similar fix was already pending. I have sent the pull request there:
OK, btw another qn I had was does this file not need a MAINTAINERS file update?
I don't see a real MAINTAINER against it, everyone just shows as contributors / committers...
Or is it to be sent to Linus directly?
Signature · 3 lines
Best regards, Dhruva Gole Texas Instruments Incorporated
Re: [PATCH V2] kthread: Fix build warning variable 'ret' set but not used
Quoted 18 lines · Dhruva Gole
Quoted 17 lines · Frederic Weisbecker
Hi Dhruva,
Quoted 10 lines · Dhruva Gole
Fix the following build time warning in kthread:
kernel/kthread.c: In function 'kthread_affine_preferred':Quoted 1 line
Quoted 1 line
kernel/kthread.c:861:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]861 | int ret; | ^~~Reported-by kernel test robot <[email protected]>Signed-off-by Dhruva Gole <[email protected]>Thanks for your patch but another similar fix was already pending. I have sent the pull request there:
Quoted 7 lines
Quoted 1 line
OK, btw another qn I had was does this file not need a
MAINTAINERSfile update?
I don't see a real MAINTAINER against it, everyone just shows as contributors / committers...
Or is it to be sent to Linus directly?
There is no official maintainer for kthreads. But I volunteer to handle the patches targeted to it at least for a while given my recent invasive changes there.
Thanks.
Quoted 5 lines
Signature · 4 lines
-- Best regards, Dhruva Gole Texas Instruments Incorporated