Skip to contentSkip to conversation

clocksource/nxp-pit: fix IRQ leak on cpuhp_setup_state error path

PATCH Applied WenTao Liang 2 participants 2 messages Jun 28 – Aug 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 clocksource/nxp-pit: fix IRQ leak on cpuhp_setup_state error path

When cpuhp_setup_state fails after pit_clockevent_per_cpu_init has successfully called request_irq, the error handling jumps directly to out_pit_clocksource_unregister without freeing the registered IRQ.

This leaks the IRQ line and, since kfree(pit) follows, leaves a dangling pointer registered as the interrupt handler's dev_id, potentially leading to a use-after-free if the IRQ fires afterwards.

Fix it by calling pit_clockevent_per_cpu_exit to properly release the IRQ before falling through to the existing cleanup chain.

Fixes bee33f22d7c3 ("clocksource/drivers/nxp-pit: Add NXP Automotive s32g2 / s32g3 support")

---
Changes in v2:
- Fix patch format based on reviewer feedback
- Call pit_clockevent_per_cpu_exit inline before goto instead of adding a separate error label (out_pit_clockevent_unregister)

---
 drivers/clocksource/timer-nxp-pit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clocksource/timer-nxp-pit.c +3 -1
index bc5157e2ba57..2f70d1d5e21b 100644
@@ -328,8 +328,10 @@ static int pit_timer_init(struct device_node *np)
 	if (pit_instances == max_pit_instances) {
 		ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "PIT timer:starting",
 					pit_clockevent_starting_cpu, NULL);
-		if (ret < 0)
+		if (ret < 0) {
+			pit_clockevent_per_cpu_exit(pit, pit_instances);
 			goto out_pit_clocksource_unregister;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.39.5 (Apple Git-154)
merge bot Applied
#1 lore raw

[tip: timers/clocksource] clocksource/drivers/nxp-pit: Fix IRQ leak on cpuhp_setup_state error path

The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     05520e035f8332c8e33f3011b5ca016fde61793d
Gitweb:        https://git.kernel.org/tip/05520e035f8332c8e33f3011b5ca016fde61793d
Author:        WenTao Liang <[email protected]>
AuthorDate:    Sun, 28 Jun 2026 21:07:00 +08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 13 Aug 2026 18:13:01 +02:00

clocksource/drivers/nxp-pit: Fix IRQ leak on cpuhp_setup_state error path

When cpuhp_setup_state fails after pit_clockevent_per_cpu_init has successfully called request_irq, the error handling jumps directly to out_pit_clocksource_unregister without freeing the registered IRQ.

This leaks the IRQ line and, since kfree(pit) follows, leaves a dangling pointer registered as the interrupt handler's dev_id, potentially leading to a use-after-free if the IRQ fires afterwards.

Fix it by calling pit_clockevent_per_cpu_exit to properly release the IRQ before falling through to the existing cleanup chain.

Fixes bee33f22d7c3 ("clocksource/drivers/nxp-pit: Add NXP Automotive s32g2 / s32g3 support")
---
 drivers/clocksource/timer-nxp-pit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clocksource/timer-nxp-pit.c +3 -1
index bc5157e..2f70d1d 100644
@@ -328,8 +328,10 @@ static int pit_timer_init(struct device_node *np)
 	if (pit_instances == max_pit_instances) {
 		ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "PIT timer:starting",
 					pit_clockevent_starting_cpu, NULL);
-		if (ret < 0)
+		if (ret < 0) {
+			pit_clockevent_per_cpu_exit(pit, pit_instances);
 			goto out_pit_clocksource_unregister;
+		}
 	}
 
 	return 0;