pps: clients: gpio: fix interrupt handling order in remove path
PATCH 1/1 pps: clients: gpio: fix interrupt handling order in remove path
The interrupt handler in pps_gpio_probe() is registered after calling pps_register_source() using devm_request_irq(). However, in the corresponding remove function, pps_unregister_source() is called before the IRQ is freed, since devm-managed resources are released after the remove function completes.
This creates a potential race condition where an interrupt may occur after the PPS source is unregistered but before the handler is removed, possibly leading to a kernel panic.
To prevent this, switch from devm-managed IRQ registration to manual management by using request_irq() and calling free_irq() explicitly in the remove path before unregistering the PPS source. This ensures the interrupt handler is safely removed before deactivating the PPS source.
--- drivers/pps/clients/pps-gpio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pps/clients/pps-gpio.c +3 -2
@@ -210,8 +210,8 @@ static int pps_gpio_probe(struct platform_device *pdev) }/* register IRQ interrupt handler */ - ret =devm_request_irq (dev, data->irq, pps_gpio_irq_handler, -get_irqf_trigger_flags (data), data->info.name, data); + ret =request_irq (data->irq, pps_gpio_irq_handler, +get_irqf_trigger_flags (data), data->info.name, data);if (ret) {pps_unregister_source (data->pps);dev_err (dev,"failed to acquire IRQ %d\n" , data->irq);
@@ -228,6 +228,7 @@ static void pps_gpio_remove(struct platform_device *pdev) {struct pps_gpio_device_data *data =platform_get_drvdata (pdev); +free_irq (data->irq, data);pps_unregister_source (data->pps);timer_delete_sync (&data->echo_timer);/* reset echo pin in any case */
Signature · 1 line
2.47.1
Rodolfo Giometti
maintainerQuoted 36 lines · Eliav Farber
The interrupt handler in
pps_gpio_probe()is registered after callingpps_register_source()usingdevm_request_irq(). However, in the corresponding remove function,pps_unregister_source()is called before the IRQ is freed, since devm-managed resources are released after the remove function completes.This creates a potential race condition where an interrupt may occur after the PPS source is unregistered but before the handler is removed, possibly leading to a kernel panic.
To prevent this, switch from devm-managed IRQ registration to manual management by using
request_irq()and callingfree_irq()explicitly in the remove path before unregistering the PPS source. This ensures the interrupt handler is safely removed before deactivating the PPS source.Signed-off-by Eliav Farber <[email protected]>--- drivers/pps/clients/pps-gpio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/pps/clients/pps-gpio.c +2
-2@@ -210,8 +210,8 @@ static int pps_gpio_probe(struct platform_device *pdev) }/* register IRQ interrupt handler */ - ret =devm_request_irq (dev, data->irq, pps_gpio_irq_handler, -get_irqf_trigger_flags (data), data->info.name, data); + ret =request_irq (data->irq, pps_gpio_irq_handler, +get_irqf_trigger_flags (data), data->info.name, data);if (ret) {pps_unregister_source (data->pps);dev_err (dev,"failed to acquire IRQ %d\n" , data->irq);
drivers/pps/clients/pps-gpio.c static void pps_gpio_remove(struct platform_device *pdev) · line 231
Quoted 4 lines
drivers/pps/clients/pps-gpio.c +1
-0@@ -228,6 +228,7 @@ static void pps_gpio_remove(struct platform_device *pdev) {struct pps_gpio_device_data *data =platform_get_drvdata (pdev); +free_irq (data->irq, data);
Why not just use devm_free_irq()?
drivers/pps/clients/pps-gpio.c static void pps_gpio_remove(struct platform_device *pdev) · line 234
Quoted 3 lines
drivers/pps/clients/pps-gpio.c +0
-0pps_unregister_source (data->pps);timer_delete_sync (&data->echo_timer);/* reset echo pin in any case */
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming