* [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure
@ 2025-12-16 9:39 Liang Jie
2025-12-16 9:50 ` Andrea Righi
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Liang Jie @ 2025-12-16 9:39 UTC (permalink / raw)
To: Tejun Heo, David Vernet, Andrea Righi, Changwoo Min, Ingo Molnar,
Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
open list:SCHEDULER - SCHED_EXT, open list:SCHEDULER
Cc: liangjie, kernel test robot, Dan Carpenter
From: Liang Jie <liangjie@lixiang.com>
Smatch reported:
kernel/sched/ext.c:5332 scx_alloc_and_add_sched() warn: passing zero to 'ERR_PTR'
In scx_alloc_and_add_sched(), the alloc_percpu() failure path jumps to
err_free_gdsqs without initializing @ret. That can lead to returning
ERR_PTR(0), which violates the ERR_PTR() convention and confuses
callers.
Set @ret to -ENOMEM before jumping to the error path when
alloc_percpu() fails.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202512141601.yAXDAeA9-lkp@intel.com/
Reported-by: Dan Carpenter <error27@gmail.com>
Fixes: c201ea1578d3 ("sched_ext: Move event_stats_cpu into scx_sched")
Signed-off-by: Liang Jie <liangjie@lixiang.com>
---
kernel/sched/ext.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 05f5a49e9649..8ea243b04dc9 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4761,8 +4761,10 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops)
}
sch->pcpu = alloc_percpu(struct scx_sched_pcpu);
- if (!sch->pcpu)
+ if (!sch->pcpu) {
+ ret = -ENOMEM;
goto err_free_gdsqs;
+ }
sch->helper = kthread_run_worker(0, "sched_ext_helper");
if (IS_ERR(sch->helper)) {
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure
2025-12-16 9:39 [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure Liang Jie
@ 2025-12-16 9:50 ` Andrea Righi
2025-12-16 15:19 ` Emil Tsalapatis
2025-12-16 19:18 ` Tejun Heo
2 siblings, 0 replies; 4+ messages in thread
From: Andrea Righi @ 2025-12-16 9:50 UTC (permalink / raw)
To: Liang Jie
Cc: Tejun Heo, David Vernet, Changwoo Min, Ingo Molnar,
Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
open list:SCHEDULER - SCHED_EXT, open list:SCHEDULER, liangjie,
kernel test robot, Dan Carpenter
On Tue, Dec 16, 2025 at 05:39:55PM +0800, Liang Jie wrote:
> From: Liang Jie <liangjie@lixiang.com>
>
> Smatch reported:
>
> kernel/sched/ext.c:5332 scx_alloc_and_add_sched() warn: passing zero to 'ERR_PTR'
>
> In scx_alloc_and_add_sched(), the alloc_percpu() failure path jumps to
> err_free_gdsqs without initializing @ret. That can lead to returning
> ERR_PTR(0), which violates the ERR_PTR() convention and confuses
> callers.
>
> Set @ret to -ENOMEM before jumping to the error path when
> alloc_percpu() fails.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/r/202512141601.yAXDAeA9-lkp@intel.com/
> Reported-by: Dan Carpenter <error27@gmail.com>
> Fixes: c201ea1578d3 ("sched_ext: Move event_stats_cpu into scx_sched")
> Signed-off-by: Liang Jie <liangjie@lixiang.com>
Makes sense to me, good catch.
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
> ---
> kernel/sched/ext.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 05f5a49e9649..8ea243b04dc9 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -4761,8 +4761,10 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops)
> }
>
> sch->pcpu = alloc_percpu(struct scx_sched_pcpu);
> - if (!sch->pcpu)
> + if (!sch->pcpu) {
> + ret = -ENOMEM;
> goto err_free_gdsqs;
> + }
>
> sch->helper = kthread_run_worker(0, "sched_ext_helper");
> if (IS_ERR(sch->helper)) {
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure
2025-12-16 9:39 [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure Liang Jie
2025-12-16 9:50 ` Andrea Righi
@ 2025-12-16 15:19 ` Emil Tsalapatis
2025-12-16 19:18 ` Tejun Heo
2 siblings, 0 replies; 4+ messages in thread
From: Emil Tsalapatis @ 2025-12-16 15:19 UTC (permalink / raw)
To: Liang Jie, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, open list:SCHEDULER - SCHED_EXT,
open list:SCHEDULER
Cc: liangjie, kernel test robot, Dan Carpenter
On Tue Dec 16, 2025 at 4:39 AM EST, Liang Jie wrote:
> From: Liang Jie <liangjie@lixiang.com>
>
> Smatch reported:
>
> kernel/sched/ext.c:5332 scx_alloc_and_add_sched() warn: passing zero to 'ERR_PTR'
>
> In scx_alloc_and_add_sched(), the alloc_percpu() failure path jumps to
> err_free_gdsqs without initializing @ret. That can lead to returning
> ERR_PTR(0), which violates the ERR_PTR() convention and confuses
> callers.
>
> Set @ret to -ENOMEM before jumping to the error path when
> alloc_percpu() fails.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/r/202512141601.yAXDAeA9-lkp@intel.com/
> Reported-by: Dan Carpenter <error27@gmail.com>
> Fixes: c201ea1578d3 ("sched_ext: Move event_stats_cpu into scx_sched")
> Signed-off-by: Liang Jie <liangjie@lixiang.com>
> ---
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
> kernel/sched/ext.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 05f5a49e9649..8ea243b04dc9 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -4761,8 +4761,10 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops)
> }
>
> sch->pcpu = alloc_percpu(struct scx_sched_pcpu);
> - if (!sch->pcpu)
> + if (!sch->pcpu) {
> + ret = -ENOMEM;
> goto err_free_gdsqs;
> + }
>
> sch->helper = kthread_run_worker(0, "sched_ext_helper");
> if (IS_ERR(sch->helper)) {
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure
2025-12-16 9:39 [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure Liang Jie
2025-12-16 9:50 ` Andrea Righi
2025-12-16 15:19 ` Emil Tsalapatis
@ 2025-12-16 19:18 ` Tejun Heo
2 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2025-12-16 19:18 UTC (permalink / raw)
To: Liang Jie
Cc: David Vernet, Andrea Righi, Changwoo Min, Ingo Molnar,
Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
sched-ext, linux-kernel, liangjie, kernel test robot,
Dan Carpenter, Emil Tsalapatis
Applied to sched_ext/for-6.19-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-16 19:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-16 9:39 [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure Liang Jie
2025-12-16 9:50 ` Andrea Righi
2025-12-16 15:19 ` Emil Tsalapatis
2025-12-16 19:18 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox