[PATCH] sched/cpupri: Return CPUPRI_INVALID for untracked priorities

From: bajing

Date: Wed Nov 04 2026 - 01:57:15 EST


From: bajing <bajing@xxxxxxxxxxxxxxxxxxxx>

convert_prio() maps task priorities to cpupri values through a switch
statement without a default case. Only CPUPRI_INVALID (-1) and
priorities in [0, MAX_RT_PRIO] are handled, but the function is called
with task_struct::prio values that can be as high as MAX_PRIO-1 (139)
for !RT tasks through cpupri_find_fitness().

If a priority outside the handled range is passed, the return value
is an uninitialized stack slot. Current call sites in rt.c guard
against passing non-RT tasks (cf. the comment before the
find_lowest_rq() call in push_rt_task()), but nothing in the cpupri
code itself enforces this, and the compiler cannot see through it,
reporting:

kernel/sched/cpupri.c:45: 'cpupri' may be used uninitialized

Add a default case returning CPUPRI_INVALID, which is a well-defined
"no valid priority" value and makes cpupri_find_fitness() report that
no CPU was found, instead of iterating over a garbage number of
priority vectors.

Built with W=12, which confirms the warning is gone; no runtime
testing was done as the default case is not reachable with the
current callers.

Signed-off-by: bajing <bajing@xxxxxxxxxxxxxxxxxxxx>
---
kernel/sched/cpupri.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/kernel/sched/cpupri.c b/kernel/sched/cpupri.c
index 8f2237e8b484..2e99d5b7b2be 100644
--- a/kernel/sched/cpupri.c
+++ b/kernel/sched/cpupri.c
@@ -60,6 +60,10 @@ static int convert_prio(int prio)
case MAX_RT_PRIO:
cpupri = CPUPRI_HIGHER; /* 100 */
break;
+
+ default:
+ cpupri = CPUPRI_INVALID;
+ break;
}

return cpupri;
--
2.43.0