From: Andrea Righi <arighi@nvidia.com>
To: Liang Jie <buaajxlj@163.com>
Cc: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
"open list:SCHEDULER - SCHED_EXT" <sched-ext@lists.linux.dev>,
"open list:SCHEDULER" <linux-kernel@vger.kernel.org>,
liangjie@lixiang.com, kernel test robot <lkp@intel.com>,
Dan Carpenter <error27@gmail.com>
Subject: Re: [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure
Date: Tue, 16 Dec 2025 10:50:47 +0100 [thread overview]
Message-ID: <aUErd53BltjN3XaB@gpd4> (raw)
In-Reply-To: <20251216093955.2928453-1-buaajxlj@163.com>
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
>
next prev parent reply other threads:[~2025-12-16 9:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 9:39 [PATCH] sched_ext: fix uninitialized ret on alloc_percpu() failure Liang Jie
2025-12-16 9:50 ` Andrea Righi [this message]
2025-12-16 15:19 ` Emil Tsalapatis
2025-12-16 19:18 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aUErd53BltjN3XaB@gpd4 \
--to=arighi@nvidia.com \
--cc=bsegall@google.com \
--cc=buaajxlj@163.com \
--cc=changwoo@igalia.com \
--cc=dietmar.eggemann@arm.com \
--cc=error27@gmail.com \
--cc=juri.lelli@redhat.com \
--cc=liangjie@lixiang.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=void@manifault.com \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox