From 6693f9c913cd2dee417e3f40f73705798df62b90 Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Mon, 9 Dec 2024 14:26:55 +0200 Subject: [PATCH] linux-gen: check odp_cpu_id() call return values Check odp_cpu_id() call return values to prevent accidentally using negative return values as array indices. Fixes Coverity warnings. Signed-off-by: Matias Elo Reviewed-by: Janne Peltonen --- platform/linux-generic/odp_schedule_scalable.c | 3 +++ platform/linux-generic/odp_system_info.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/odp_schedule_scalable.c b/platform/linux-generic/odp_schedule_scalable.c index 4947353d61..5513acb043 100644 --- a/platform/linux-generic/odp_schedule_scalable.c +++ b/platform/linux-generic/odp_schedule_scalable.c @@ -927,6 +927,9 @@ static int _schedule(odp_queue_t *from, odp_event_t ev[], int num_evts) } cpu_id = odp_cpu_id(); + if (odp_unlikely(cpu_id < 0)) + return 0; + /* Scan our schedq list from beginning to end */ for (i = 0; i < ts->num_schedq; i++) { sched_queue_t *schedq = ts->schedq_list[i]; diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index bf5845d245..7baaa6c2c6 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -9,16 +9,18 @@ #include +#include +#include +#include #include #include + #include #include #include #include #include #include -#include -#include #include #include @@ -439,6 +441,9 @@ uint64_t odp_cpu_hz(void) { int id = odp_cpu_id(); + if (odp_unlikely(id < 0)) + return -1; + if (odp_global_ro.system_info.cpu_hz_static) return cpu_hz_static(id); return cpu_hz_current(id);