kernel/kthread.c | 2 -- 1 file changed, 2 deletions(-)
Fix the following build time warning in kthread:
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;
| ^~~
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202501301528.t0cZVbnq-lkp@intel.com/
Signed-off-by: Dhruva Gole <d-gole@ti.com>
---
kernel/kthread.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 4005b13ebd7f..f730b1413d13 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -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;
}
--
2.34.1
On Tue, Feb 04, 2025 at 02:38:38PM +0530, Dhruva Gole wrote:
> Fix the following build time warning in kthread:
>
> 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;
> | ^~~
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202501301528.t0cZVbnq-lkp@intel.com/
> Signed-off-by: Dhruva Gole <d-gole@ti.com>
> ---
> kernel/kthread.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index 4005b13ebd7f..f730b1413d13 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -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;
> }
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.
--
Kees Cook
On Feb 04, 2025 at 07:15:41 -0800, Kees Cook wrote:
> On Tue, Feb 04, 2025 at 02:38:38PM +0530, Dhruva Gole wrote:
> > Fix the following build time warning in kthread:
> >
> > 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;
> > | ^~~
> >
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202501301528.t0cZVbnq-lkp@intel.com/
> > Signed-off-by: Dhruva Gole <d-gole@ti.com>
> > ---
> > kernel/kthread.c | 2 --
> > 1 file changed, 2 deletions(-)
> >
> > diff --git a/kernel/kthread.c b/kernel/kthread.c
> > index 4005b13ebd7f..f730b1413d13 100644
> > --- a/kernel/kthread.c
> > +++ b/kernel/kthread.c
> > @@ -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;
> > }
>
> 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.
--
Best regards,
Dhruva Gole
Texas Instruments Incorporated
Fix the following build time warning in kthread:
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;
| ^~~
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202501301528.t0cZVbnq-lkp@intel.com/
Signed-off-by: Dhruva Gole <d-gole@ti.com>
---
Link to v1:
https://lore.kernel.org/lkml/20250204090838.214647-1-d-gole@ti.com/
Changelog:
- Use ret value toward the end return as per Kees' suggestion
---
kernel/kthread.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 4005b13ebd7f..5dc5b0d7238e 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -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
--
2.34.1
Hi Dhruva, Le Tue, Feb 04, 2025 at 09:39:21PM +0530, Dhruva Gole a écrit : > Fix the following build time warning in kthread: > > 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; > | ^~~ > > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/oe-kbuild-all/202501301528.t0cZVbnq-lkp@intel.com/ > Signed-off-by: Dhruva Gole <d-gole@ti.com> Thanks for your patch but another similar fix was already pending. I have sent the pull request there: https://lore.kernel.org/lkml/Z6JjZMdbDoAX_AVW@pavilion.home/T/#u
On Feb 04, 2025 at 20:02:19 +0100, Frederic Weisbecker wrote: > Hi Dhruva, > > Le Tue, Feb 04, 2025 at 09:39:21PM +0530, Dhruva Gole a écrit : > > Fix the following build time warning in kthread: > > > > 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; > > | ^~~ > > > > Reported-by: kernel test robot <lkp@intel.com> > > Closes: https://lore.kernel.org/oe-kbuild-all/202501301528.t0cZVbnq-lkp@intel.com/ > > Signed-off-by: Dhruva Gole <d-gole@ti.com> > > Thanks for your patch but another similar fix was already pending. I have sent > the pull request there: > > https://lore.kernel.org/lkml/Z6JjZMdbDoAX_AVW@pavilion.home/T/#u 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? -- Best regards, Dhruva Gole Texas Instruments Incorporated
Le Wed, Feb 05, 2025 at 11:47:40AM +0530, Dhruva Gole a écrit : > On Feb 04, 2025 at 20:02:19 +0100, Frederic Weisbecker wrote: > > Hi Dhruva, > > > > Le Tue, Feb 04, 2025 at 09:39:21PM +0530, Dhruva Gole a écrit : > > > Fix the following build time warning in kthread: > > > > > > 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; > > > | ^~~ > > > > > > Reported-by: kernel test robot <lkp@intel.com> > > > Closes: https://lore.kernel.org/oe-kbuild-all/202501301528.t0cZVbnq-lkp@intel.com/ > > > Signed-off-by: Dhruva Gole <d-gole@ti.com> > > > > Thanks for your patch but another similar fix was already pending. I have sent > > the pull request there: > > > > https://lore.kernel.org/lkml/Z6JjZMdbDoAX_AVW@pavilion.home/T/#u > > 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? 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. > > -- > Best regards, > Dhruva Gole > Texas Instruments Incorporated
© 2016 - 2025 Red Hat, Inc.