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

clk: mmp: pxa168: Fix memory leak in pxa168_clk_init()

In cases where mapping of mpmu/apmu/apbc registers fails, the code path
does not handle the failure gracefully, potentially leading to a memory
leak. This fix ensures proper cleanup by freeing the allocated memory
for 'pxa_unit' before returning.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Link: https://lore.kernel.org/r/20231210175232.3414584-1-visitorckw@gmail.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Kuan-Wei Chiu and committed by
Stephen Boyd
2fbabea6 bfbea9e5

+3
+3
drivers/clk/mmp/clk-of-pxa168.c
··· 308 308 pxa_unit->mpmu_base = of_iomap(np, 0); 309 309 if (!pxa_unit->mpmu_base) { 310 310 pr_err("failed to map mpmu registers\n"); 311 + kfree(pxa_unit); 311 312 return; 312 313 } 313 314 314 315 pxa_unit->apmu_base = of_iomap(np, 1); 315 316 if (!pxa_unit->apmu_base) { 316 317 pr_err("failed to map apmu registers\n"); 318 + kfree(pxa_unit); 317 319 return; 318 320 } 319 321 320 322 pxa_unit->apbc_base = of_iomap(np, 2); 321 323 if (!pxa_unit->apbc_base) { 322 324 pr_err("failed to map apbc registers\n"); 325 + kfree(pxa_unit); 323 326 return; 324 327 } 325 328