[PATCH] clocksource: timer-cadence-ttc: Fix resource leaks in error paths

Markus Elfring Markus.Elfring at web.de
Wed Nov 26 02:34:33 PST 2025


> The ttc_setup_clocksource() and ttc_setup_clockevent() fail to
> unregister the clock notifier in their error paths, potentially
> leading to a resource leak. Additionally, ttc_setup_clocksource()
> leaks the prepared clock reference upon failure.
…

You may occasionally put more than 65 characters into text lines
of such a change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc7#n658


…
> +++ b/drivers/clocksource/timer-cadence-ttc.c
…
> @@ -377,6 +380,10 @@ static int __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
>  
>  	err = clocksource_register_hz(&ttccs->cs, ttccs->ttc.freq / PRESCALE);
>  	if (err) {
> +		if (notifier_registered)
> +			clk_notifier_unregister(ttccs->ttc.clk,
> +					&ttccs->ttc.clk_rate_change_nb);
> +		clk_disable_unprepare(ttccs->ttc.clk);
>  		kfree(ttccs);
>  		return err;
>  	}

How do you think about to avoid repeated kfree() calls in such a function implementation?


> @@ -465,13 +472,16 @@ static int __init ttc_setup_clockevent(struct clk *clk,
…
> +out_clk_notifier_unregister:
> +	clk_notifier_unregister(ttcce->ttc.clk,
> +			&ttcce->ttc.clk_rate_change_nb);
…

You may specify this function call in a single line.

Regards,
Markus



More information about the linux-arm-kernel mailing list