Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

PM: EM: Fix memory leak in em_create_pd() error path

When ida_alloc() fails in em_create_pd(), the function returns without
freeing the previously allocated 'pd' structure, leading to a memory leak.
The 'pd' pointer is allocated either at line 436 (for CPU devices with
cpumask) or line 442 (for other devices) using kzalloc().

Additionally, the function incorrectly returns -ENOMEM when ida_alloc()
fails, ignoring the actual error code returned by ida_alloc(), which can
fail for reasons other than memory exhaustion.

Fix both issues by:
1. Freeing the 'pd' structure with kfree() when ida_alloc() fails
2. Returning the actual error code from ida_alloc() instead of -ENOMEM

This ensures proper cleanup on the error path and accurate error reporting.

Fixes: cbe5aeedecc7 ("PM: EM: Assign a unique ID when creating a performance domain")
Signed-off-by: Malaya Kumar Rout <mrout@redhat.com>
Reviewed-by: Changwoo Min <changwoo@igalia.com>
Link: https://patch.msgid.link/20260105103730.65626-1-mrout@redhat.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Malaya Kumar Rout and committed by
Rafael J. Wysocki
e25348c5 54b603f2

+4 -2
+4 -2
kernel/power/energy_model.c
··· 449 449 INIT_LIST_HEAD(&pd->node); 450 450 451 451 id = ida_alloc(&em_pd_ida, GFP_KERNEL); 452 - if (id < 0) 453 - return -ENOMEM; 452 + if (id < 0) { 453 + kfree(pd); 454 + return id; 455 + } 454 456 pd->id = id; 455 457 456 458 em_table = em_table_alloc(pd);