[RFT,1/3] gpio: eic-sprd: unregister from the irq notifier on remove()

Message ID 20230912094519.22769-1-brgl@bgdev.pl
State New
Headers
Series [RFT,1/3] gpio: eic-sprd: unregister from the irq notifier on remove() |

Commit Message

Bartosz Golaszewski Sept. 12, 2023, 9:45 a.m. UTC
  From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

This is a tristate module, it can be unloaded. We need to cleanup properly
and unregister from the interrupt notifier on driver detach.

Fixes: b32415652a4d ("gpio: eic-sprd: use atomic notifiers to notify all chips about irqs")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-eic-sprd.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
  

Comments

Baolin Wang Sept. 12, 2023, 11:02 a.m. UTC | #1
On 9/12/2023 5:45 PM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> This is a tristate module, it can be unloaded. We need to cleanup properly
> and unregister from the interrupt notifier on driver detach.
> 
> Fixes: b32415652a4d ("gpio: eic-sprd: use atomic notifiers to notify all chips about irqs")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

> ---
>   drivers/gpio/gpio-eic-sprd.c | 19 +++++++++++++++++--
>   1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-eic-sprd.c b/drivers/gpio/gpio-eic-sprd.c
> index 21a1afe358d6..9b2f9ccf8d77 100644
> --- a/drivers/gpio/gpio-eic-sprd.c
> +++ b/drivers/gpio/gpio-eic-sprd.c
> @@ -580,6 +580,14 @@ static const struct irq_chip sprd_eic_irq = {
>   	.flags		= IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE,
>   	GPIOCHIP_IRQ_RESOURCE_HELPERS,
>   };
> +
> +static void sprd_eic_unregister_notifier(void *data)
> +{
> +	struct notifier_block *nb = data;
> +
> +	atomic_notifier_chain_unregister(&sprd_eic_irq_notifier, nb);
> +}
> +
>   static int sprd_eic_probe(struct platform_device *pdev)
>   {
>   	const struct sprd_eic_variant_data *pdata;
> @@ -658,8 +666,15 @@ static int sprd_eic_probe(struct platform_device *pdev)
>   	}
>   
>   	sprd_eic->irq_nb.notifier_call = sprd_eic_irq_notify;
> -	return atomic_notifier_chain_register(&sprd_eic_irq_notifier,
> -					      &sprd_eic->irq_nb);
> +	ret = atomic_notifier_chain_register(&sprd_eic_irq_notifier,
> +					     &sprd_eic->irq_nb);
> +	if (ret)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "Failed to register with the interrupt notifier");
> +
> +	return devm_add_action_or_reset(&pdev->dev,
> +					sprd_eic_unregister_notifier,
> +					&sprd_eic->irq_nb);
>   }
>   
>   static const struct of_device_id sprd_eic_of_match[] = {
  
Bartosz Golaszewski Sept. 13, 2023, 12:14 p.m. UTC | #2
On Tue, Sep 12, 2023 at 1:02 PM Baolin Wang
<baolin.wang@linux.alibaba.com> wrote:
>
>
>
> On 9/12/2023 5:45 PM, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > This is a tristate module, it can be unloaded. We need to cleanup properly
> > and unregister from the interrupt notifier on driver detach.
> >
> > Fixes: b32415652a4d ("gpio: eic-sprd: use atomic notifiers to notify all chips about irqs")
> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> LGTM.
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>

Thanks, queued patches 1 and 2.

Bart

> > ---
> >   drivers/gpio/gpio-eic-sprd.c | 19 +++++++++++++++++--
> >   1 file changed, 17 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-eic-sprd.c b/drivers/gpio/gpio-eic-sprd.c
> > index 21a1afe358d6..9b2f9ccf8d77 100644
> > --- a/drivers/gpio/gpio-eic-sprd.c
> > +++ b/drivers/gpio/gpio-eic-sprd.c
> > @@ -580,6 +580,14 @@ static const struct irq_chip sprd_eic_irq = {
> >       .flags          = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE,
> >       GPIOCHIP_IRQ_RESOURCE_HELPERS,
> >   };
> > +
> > +static void sprd_eic_unregister_notifier(void *data)
> > +{
> > +     struct notifier_block *nb = data;
> > +
> > +     atomic_notifier_chain_unregister(&sprd_eic_irq_notifier, nb);
> > +}
> > +
> >   static int sprd_eic_probe(struct platform_device *pdev)
> >   {
> >       const struct sprd_eic_variant_data *pdata;
> > @@ -658,8 +666,15 @@ static int sprd_eic_probe(struct platform_device *pdev)
> >       }
> >
> >       sprd_eic->irq_nb.notifier_call = sprd_eic_irq_notify;
> > -     return atomic_notifier_chain_register(&sprd_eic_irq_notifier,
> > -                                           &sprd_eic->irq_nb);
> > +     ret = atomic_notifier_chain_register(&sprd_eic_irq_notifier,
> > +                                          &sprd_eic->irq_nb);
> > +     if (ret)
> > +             return dev_err_probe(&pdev->dev, ret,
> > +                                  "Failed to register with the interrupt notifier");
> > +
> > +     return devm_add_action_or_reset(&pdev->dev,
> > +                                     sprd_eic_unregister_notifier,
> > +                                     &sprd_eic->irq_nb);
> >   }
> >
> >   static const struct of_device_id sprd_eic_of_match[] = {
  

Patch

diff --git a/drivers/gpio/gpio-eic-sprd.c b/drivers/gpio/gpio-eic-sprd.c
index 21a1afe358d6..9b2f9ccf8d77 100644
--- a/drivers/gpio/gpio-eic-sprd.c
+++ b/drivers/gpio/gpio-eic-sprd.c
@@ -580,6 +580,14 @@  static const struct irq_chip sprd_eic_irq = {
 	.flags		= IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE,
 	GPIOCHIP_IRQ_RESOURCE_HELPERS,
 };
+
+static void sprd_eic_unregister_notifier(void *data)
+{
+	struct notifier_block *nb = data;
+
+	atomic_notifier_chain_unregister(&sprd_eic_irq_notifier, nb);
+}
+
 static int sprd_eic_probe(struct platform_device *pdev)
 {
 	const struct sprd_eic_variant_data *pdata;
@@ -658,8 +666,15 @@  static int sprd_eic_probe(struct platform_device *pdev)
 	}
 
 	sprd_eic->irq_nb.notifier_call = sprd_eic_irq_notify;
-	return atomic_notifier_chain_register(&sprd_eic_irq_notifier,
-					      &sprd_eic->irq_nb);
+	ret = atomic_notifier_chain_register(&sprd_eic_irq_notifier,
+					     &sprd_eic->irq_nb);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to register with the interrupt notifier");
+
+	return devm_add_action_or_reset(&pdev->dev,
+					sprd_eic_unregister_notifier,
+					&sprd_eic->irq_nb);
 }
 
 static const struct of_device_id sprd_eic_of_match[] = {