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

clocksource/drivers/clps711x: Fix resource leaks in error paths

The current implementation of clps711x_timer_init() has multiple error
paths that directly return without releasing the base I/O memory mapped
via of_iomap(). Fix of_iomap leaks in error paths.

Fixes: 04410efbb6bc ("clocksource/drivers/clps711x: Convert init function to return error")
Fixes: 2a6a8e2d9004 ("clocksource/drivers/clps711x: Remove board support")
Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20250814123324.1516495-1-zhen.ni@easystack.cn

authored by

Zhen Ni and committed by
Daniel Lezcano
cd32e596 1c4b87c9

+16 -7
+16 -7
drivers/clocksource/clps711x-timer.c
··· 78 78 unsigned int irq = irq_of_parse_and_map(np, 0); 79 79 struct clk *clock = of_clk_get(np, 0); 80 80 void __iomem *base = of_iomap(np, 0); 81 + int ret = 0; 81 82 82 83 if (!base) 83 84 return -ENOMEM; 84 - if (!irq) 85 - return -EINVAL; 86 - if (IS_ERR(clock)) 87 - return PTR_ERR(clock); 85 + if (!irq) { 86 + ret = -EINVAL; 87 + goto unmap_io; 88 + } 89 + if (IS_ERR(clock)) { 90 + ret = PTR_ERR(clock); 91 + goto unmap_io; 92 + } 88 93 89 94 switch (of_alias_get_id(np, "timer")) { 90 95 case CLPS711X_CLKSRC_CLOCKSOURCE: 91 96 clps711x_clksrc_init(clock, base); 92 97 break; 93 98 case CLPS711X_CLKSRC_CLOCKEVENT: 94 - return _clps711x_clkevt_init(clock, base, irq); 99 + ret = _clps711x_clkevt_init(clock, base, irq); 100 + break; 95 101 default: 96 - return -EINVAL; 102 + ret = -EINVAL; 103 + break; 97 104 } 98 105 99 - return 0; 106 + unmap_io: 107 + iounmap(base); 108 + return ret; 100 109 } 101 110 TIMER_OF_DECLARE(clps711x, "cirrus,ep7209-timer", clps711x_timer_init);