sched/cpupri: fix the task priority BUG_ON checks
PATCH 1/1 sched/cpupri: fix the task priority BUG_ON checks
The BUG_ON checks are intended to check if the task priotity is valid, but in the function convert_prio, if the task priority is not valid, it will be converted to an uninitialized stack variable. Fix it by moving the BUG_ON checks to the default branch of convert_prio.
--- kernel/sched/cpupri.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/sched/cpupri.c +2 -4
@@ -60,6 +60,8 @@ static int convert_prio(int prio)case MAX_RT_PRIO : cpupri =CPUPRI_HIGHER ;/* 100 */ break ; +default : +BUG (); }return cpupri;
@@ -148,8 +150,6 @@ int cpupri_find_fitness(struct cpupri *cp, struct task_struct *p,int task_pri =convert_prio (p->prio);int idx, cpu; -BUG_ON (task_pri >=CPUPRI_NR_PRIORITIES ); -for (idx =0 ; idx < task_pri; idx++) {if (!__cpupri_find (cp, p, lowest_mask, idx))
@@ -215,8 +215,6 @@ void cpupri_set(struct cpupri *cp, int cpu, int newpri) newpri =convert_prio (newpri); -BUG_ON (newpri >=CPUPRI_NR_PRIORITIES ); -if (newpri == oldpri)return ;
Signature · 1 line
2.8.1
Quoted 35 lines · Zeng Tao
The
BUG_ONchecks are intended to check if the task priotity is valid, but in the functionconvert_prio, if the task priority is not valid, it will be converted to an uninitialized stack variable. Fix it by moving theBUG_ONchecks to the default branch ofconvert_prio.Fixes 934fc3314b39 ("sched/cpupri: Remap CPUPRI_NORMAL to MAX_RT_PRIO-1")Signed-off-by Zeng Tao <[email protected]>--- kernel/sched/cpupri.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)kernel/sched/cpupri.c +2
-2@@ -60,6 +60,8 @@ static int convert_prio(int prio)case MAX_RT_PRIO : cpupri =CPUPRI_HIGHER ;/* 100 */ break ; +default : +BUG (); }return cpupri;@@ -148,8 +150,6 @@ int cpupri_find_fitness(struct cpupri *cp, struct task_struct *p,int task_pri =convert_prio (p->prio);int idx, cpu; -BUG_ON (task_pri >=CPUPRI_NR_PRIORITIES ); -for (idx =0 ; idx < task_pri; idx++) {if (!__cpupri_find (cp, p, lowest_mask, idx))
kernel/sched/cpupri.c void cpupri_set(struct cpupri *cp, int cpu, int newpri) · line 220
Quoted 8 lines
kernel/sched/cpupri.c +0
-2@@ -215,8 +215,6 @@ void cpupri_set(struct cpupri *cp, int cpu, int newpri) newpri =convert_prio (newpri); -BUG_ON (newpri >=CPUPRI_NR_PRIORITIES ); -if (newpri == oldpri)return ;
LGTM. Currently, convert_prio() is never called with prio < CPUPRI_INVALID (-1) or prio > MAX_RT_PRIO (100) but in case it would then this would be caught much easier with this patch.