Re: [PATCH] cpupower: idle_monitor: add NULL check after calloc()
From: Shuah Khan
Date: Fri Sep 04 2026 - 14:50:38 EST
On 9/2/26 00:52, longlong yan wrote:
Twenty calloc() calls across five idle monitor files lack NULL return
checks, leading to potential NULL pointer dereferences on allocation
failure:
- mperf_monitor.c mperf_register(): nine consecutive calloc() calls
for per-CPU counters are used directly without any NULL check.
- snb_idle.c snb_register(): is_valid and per-CSTATE previous/current
counters are allocated without NULL checks.
- nhm_idle.c intel_nhm_register(): same pattern as snb_idle.
- hsw_ext_idle.c hsw_ext_register(): same pattern as snb_idle.
- amd_fam14h_idle.c amd_fam14h_register(): per-state previous/current
counters are allocated without NULL checks.
Add NULL checks after each allocation, returning NULL on failure,
consistent with existing error handling in the same functions (e.g.,
hardware capability checks already return NULL on failure).
There is no need to add null checks for these small amounts
of memory from tools like this one.
How did you test these error paths?
Sorry I won't take this patch.
Signed-off-by: longlong yan <yanlonglong@xxxxxxxxxx>
---
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c | 2 ++
tools/power/cpupower/utils/idle_monitor/hsw_ext_idle.c | 4 ++++
tools/power/cpupower/utils/idle_monitor/mperf_monitor.c | 5 +++++
tools/power/cpupower/utils/idle_monitor/nhm_idle.c | 4 ++++
tools/power/cpupower/utils/idle_monitor/snb_idle.c | 4 ++++
5 files changed, 19 insertions(+)
thanks,
-- Shuah