[PATCH] sched/deadline: Add bounds check in cpudl_maximum()

Kaushlendra Kumar posted 1 patch 2 weeks, 5 days ago
kernel/sched/cpudeadline.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] sched/deadline: Add bounds check in cpudl_maximum()
Posted by Kaushlendra Kumar 2 weeks, 5 days ago
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 <kaushlendra.kumar@intel.com>
---
 kernel/sched/cpudeadline.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index 0f7127b3a05c..dd736e3879c8 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -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;
 }
 
-- 
2.34.1