Skip to content

Commit

Permalink
linux-gen: check odp_cpu_id() call return values
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Janne Peltonen <[email protected]>
  • Loading branch information
MatiasElo committed Dec 9, 2024
1 parent 477ac44 commit 55ac75a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions platform/linux-generic/odp_schedule_scalable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 7 additions & 2 deletions platform/linux-generic/odp_system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@

#include <odp_posix_extensions.h>

#include <odp/api/align.h>
#include <odp/api/cpu.h>
#include <odp/api/hints.h>
#include <odp/api/system_info.h>
#include <odp/api/version.h>

#include <odp_global_data.h>
#include <odp_sysinfo_internal.h>
#include <odp_init_internal.h>
#include <odp_libconfig_internal.h>
#include <odp_debug_internal.h>
#include <odp_config_internal.h>
#include <odp/api/align.h>
#include <odp/api/cpu.h>

#include <errno.h>
#include <string.h>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 55ac75a

Please sign in to comment.