Skip to contentSkip to conversation

sched/cpupri: handle out-of-range prio in convert_prio

PATCH New Joseph Salisbury 1 participant 1 message Mar 8 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/cpupri: handle out-of-range prio in convert_prio

convert_prio() can return an undefined value when called with an out-of-range priority because 'cpupri' is not initialized on the default path.

Initialize 'cpupri' to 'CPUPRI_INVALID' and warn once on invalid input, keeping behavior deterministic for unexpected priorities.

Fixes 6e0534f27819 ("sched: use a 2-d bitmap for searching lowest-pri CPU")
Assisted-by Codex:GPT-5
---
 kernel/sched/cpupri.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/sched/cpupri.c +5 -1
index 8f2237e8b484..b905a6bfac0c 100644
@@ -42,7 +42,7 @@
  */
 static int convert_prio(int prio)
 {
-	int cpupri;
+	int cpupri = CPUPRI_INVALID;
 
 	switch (prio) {
 	case CPUPRI_INVALID:
@@ -60,6 +60,10 @@ static int convert_prio(int prio)
 	case MAX_RT_PRIO:
 		cpupri = CPUPRI_HIGHER;		/* 100 */
 		break;
+
+	default:
+		WARN_ON_ONCE(prio < 0 || prio > MAX_RT_PRIO);
+		break;
 	}
 
 	return cpupri;
Signature · 1 line
2.47.3