Skip to contentSkip to conversation

pps: clients: gpio: fix interrupt handling order in remove path

PATCH Farber, Eliav 3 participants 3 messages May 27, 2025

lore
Share & tools
lore
#0 lore raw
Quoted 7 lines

Review static void pps_gpio_remove(struct platform_device *pdev) · line 231

Quoted 5 lines
(quoted diff) +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()?

As far as I understand, the main purpose of devm_*() is to provide hands-off resource management. devm_request_irq() is intended to eliminate the need for explicit cleanup in the remove() function by automatically freeing the IRQ after remove() returns.

In my opinion, calling devm_free_irq() undermines the benefit of using devm_request_irq() in the first place. If I need to explicitly free the IRQ during remove(), then I’m no longer relying on devm’s automatic cleanup - I’m effectively reverting to manual resource management while still using devm-style registration, which I find unnecessary.

That said, if you still favor devm_free_irq(), I’ll revise the patch accordingly.

Regards, Eliav

#1 lore raw
Quoted 4 lines · Eliav
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -228,6 +228,7 @@ static void pps_gpio_remove(struct platform_device *pdev)
   {
       struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
 
Quoted 8 lines
Quoted 3 lines

Review static void pps_gpio_remove(struct platform_device *pdev) · line 231

Quoted 1 line
(quoted diff) +1 -0
+     free_irq(data->irq, data);

Why not just use devm_free_irq()?

As far as I understand, the main purpose of devm_*() is to provide hands-off resource management. devm_request_irq() is intended to eliminate the need for explicit cleanup in the remove() function by automatically freeing the IRQ after remove() returns.

In linux/kernel/irq/devres.c we can read:

/**

 *      devm_free_irq - free an interrupt
 *      @dev: device to free interrupt for
 *      @irq: Interrupt line to free
 *      @dev_id: Device identity to free
 *
 *      Except for the extra @dev argument, this function takes the
 *      same arguments and performs the same function as free_irq().
 *      This function instead of free_irq() should be used to manually
 *      free IRQs allocated with devm_request_irq().

*/

Quoted 8 lines

In my opinion, calling devm_free_irq() undermines the benefit of using devm_request_irq() in the first place. If I need to explicitly free the IRQ during remove(), then I’m no longer relying on devm’s automatic cleanup - I’m effectively reverting to manual resource management while still using devm-style registration, which I find unnecessary.

That said, if you still favor devm_free_irq(), I’ll revise the patch accordingly.

Since devm_free_irq() works exactly as free_irq() and can be used to manually free IRQs allocated with devm_request_irq(), I think it is less invasive. Isn't it? :-)

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
#2 lore raw
Quoted 34 lines · Rodolfo Giometti
Quoted 4 lines · Eliav
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -228,6 +228,7 @@ static void pps_gpio_remove(struct platform_device *pdev)
   {
       struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
 
Quoted 8 lines
Quoted 3 lines

Review static void pps_gpio_remove(struct platform_device *pdev) · line 231

Quoted 1 line
(quoted diff) +1 -0
+     free_irq(data->irq, data);

Why not just use devm_free_irq()?

As far as I understand, the main purpose of devm_*() is to provide hands-off resource management. devm_request_irq() is intended to eliminate the need for explicit cleanup in the remove() function by automatically freeing the IRQ after remove() returns.

In linux/kernel/irq/devres.c we can read:

/**

 *      devm_free_irq - free an interrupt
 *      @dev: device to free interrupt for
 *      @irq: Interrupt line to free
 *      @dev_id: Device identity to free
 *
 *      Except for the extra @dev argument, this function takes the
 *      same arguments and performs the same function as free_irq().
 *      This function instead of free_irq() should be used to manually
 *      free IRQs allocated with devm_request_irq().

*/

Quoted 6 lines

In my opinion, calling devm_free_irq() undermines the benefit of using devm_request_irq() in the first place. If I need to explicitly free the IRQ during remove(), then I’m no longer relying on devm’s automatic cleanup - I’m effectively reverting to manual resource management while still using devm-style registration, which I find unnecessary.

Quoted 6 lines
Quoted 2 lines

That said, if you still favor devm_free_irq(), I’ll revise the patch accordingly.

Since devm_free_irq() works exactly as free_irq() and can be used to manually free IRQs allocated with devm_request_irq(), I think it is less invasive. Isn't it? :-)

Not always, no. irq handling is tricky, and devm for irqs is a huge source of bugs as how do you really know when your irq is going to be
removed from the system? If you don't want to use devm calls, don't,
there's no requirement to do so.

thanks,

greg k-h