sched/deadline: Add bounds check in cpudl_maximum()
PATCH 1/1 sched/deadline: Add bounds check in cpudl_maximum()
Add a bounds check to cpudl_maximum() to prevent accessing cp->elements[0] when the heap is empty. Return -1 when cp->size is 0 to indicate that no valid CPU is available in the deadline heap.
Without this check, accessing cp->elements[0] when the heap is empty could lead to undefined behavior.
Signed-off-by Kaushlendra Kumar <[email protected]>
--- kernel/sched/cpudeadline.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/sched/cpudeadline.c +2 -0
@@ -103,6 +103,8 @@ static void cpudl_heapify(struct cpudl *cp, int idx)static inline int cpudl_maximum (struct cpudl *cp) { +if (cp->size ==0 ) +return -1 ;return cp->elements[0 ].cpu; }
Signature · 1 line
2.34.1