Messages in this thread | | | Subject | Re: [PATCH] sched/cpupri: fix the task priority BUG_ON checks | From | Dietmar Eggemann <> | Date | Tue, 6 Apr 2021 13:42:27 +0200 |
| |
On 26/03/2021 04:15, Zeng Tao wrote: > 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. > > Fixes: 934fc3314b39 ("sched/cpupri: Remap CPUPRI_NORMAL to MAX_RT_PRIO-1") > Signed-off-by: Zeng Tao <prime.zeng@hisilicon.com> > --- > kernel/sched/cpupri.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/kernel/sched/cpupri.c b/kernel/sched/cpupri.c > index ec9be78..c5a0e6e 100644 > --- a/kernel/sched/cpupri.c > +++ b/kernel/sched/cpupri.c > @@ -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; > >
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.
Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
| |