mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-24 02:52:38 +00:00
perf python: Set index error for invalid thread/cpu map items
Returning NULL for out of bound CPU or thread map items causes internal errors. Fix by correctly setting the error to be an index error. Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20250710235126.1086011-14-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
@@ -529,8 +529,10 @@ static PyObject *pyrf_cpu_map__item(PyObject *obj, Py_ssize_t i)
|
||||
{
|
||||
struct pyrf_cpu_map *pcpus = (void *)obj;
|
||||
|
||||
if (i >= perf_cpu_map__nr(pcpus->cpus))
|
||||
if (i >= perf_cpu_map__nr(pcpus->cpus)) {
|
||||
PyErr_SetString(PyExc_IndexError, "Index out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("i", perf_cpu_map__cpu(pcpus->cpus, i).cpu);
|
||||
}
|
||||
@@ -598,8 +600,10 @@ static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i)
|
||||
{
|
||||
struct pyrf_thread_map *pthreads = (void *)obj;
|
||||
|
||||
if (i >= perf_thread_map__nr(pthreads->threads))
|
||||
if (i >= perf_thread_map__nr(pthreads->threads)) {
|
||||
PyErr_SetString(PyExc_IndexError, "Index out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user