Skip to contentSkip to conversation

gpio: eic-sprd: unregister from the irq notifier on remove()

PATCH In review Bartosz Golaszewski 3 participants 12 messages Sep 12, 2023 – Sep 13, 2023

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

PATCH 1/3 gpio: eic-sprd: unregister from the irq notifier on remove()

From: Bartosz Golaszewski <[email protected]>

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")
---
 drivers/gpio/gpio-eic-sprd.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/gpio/gpio-eic-sprd.c +17 -2
index 21a1afe358d6..9b2f9ccf8d77 100644
@@ -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[] = {
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/3 gpio: eic-sprd: use a helper variable for &pdev->dev

From: Bartosz Golaszewski <[email protected]>

Instead of dereferencing pdev everywhere, just store the address of the underlying struct device in a local variable.

---
 drivers/gpio/gpio-eic-sprd.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpio/gpio-eic-sprd.c +10 -10
index 9b2f9ccf8d77..be7f2fa5aa7b 100644
@@ -591,18 +591,19 @@ static void sprd_eic_unregister_notifier(void *data)
 static int sprd_eic_probe(struct platform_device *pdev)
 {
 	const struct sprd_eic_variant_data *pdata;
+	struct device *dev = &pdev->dev;
 	struct gpio_irq_chip *irq;
 	struct sprd_eic *sprd_eic;
 	struct resource *res;
 	int ret, i;
 
-	pdata = of_device_get_match_data(&pdev->dev);
+	pdata = of_device_get_match_data(dev);
 	if (!pdata) {
-		dev_err(&pdev->dev, "No matching driver data found.\n");
+		dev_err(dev, "No matching driver data found.\n");
 		return -EINVAL;
 	}
 
-	sprd_eic = devm_kzalloc(&pdev->dev, sizeof(*sprd_eic), GFP_KERNEL);
+	sprd_eic = devm_kzalloc(dev, sizeof(*sprd_eic), GFP_KERNEL);
 	if (!sprd_eic)
 		return -ENOMEM;
 
@@ -624,7 +625,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
 		if (!res)
 			break;
 
-		sprd_eic->base[i] = devm_ioremap_resource(&pdev->dev, res);
+		sprd_eic->base[i] = devm_ioremap_resource(dev, res);
 		if (IS_ERR(sprd_eic->base[i]))
 			return PTR_ERR(sprd_eic->base[i]);
 	}
@@ -632,7 +633,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
 	sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type];
 	sprd_eic->chip.ngpio = pdata->num_eics;
 	sprd_eic->chip.base = -1;
-	sprd_eic->chip.parent = &pdev->dev;
+	sprd_eic->chip.parent = dev;
 	sprd_eic->chip.direction_input = sprd_eic_direction_input;
 	switch (sprd_eic->type) {
 	case SPRD_EIC_DEBOUNCE:
@@ -659,9 +660,9 @@ static int sprd_eic_probe(struct platform_device *pdev)
 	irq->num_parents = 1;
 	irq->parents = &sprd_eic->irq;
 
-	ret = devm_gpiochip_add_data(&pdev->dev, &sprd_eic->chip, sprd_eic);
+	ret = devm_gpiochip_add_data(dev, &sprd_eic->chip, sprd_eic);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "Could not register gpiochip %d.\n", ret);
+		dev_err(dev, "Could not register gpiochip %d.\n", ret);
 		return ret;
 	}
 
@@ -669,11 +670,10 @@ static int sprd_eic_probe(struct platform_device *pdev)
 	ret = atomic_notifier_chain_register(&sprd_eic_irq_notifier,
 					     &sprd_eic->irq_nb);
 	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
+		return dev_err_probe(dev, ret,
 				     "Failed to register with the interrupt notifier");
 
-	return devm_add_action_or_reset(&pdev->dev,
-					sprd_eic_unregister_notifier,
+	return devm_add_action_or_reset(dev, sprd_eic_unregister_notifier,
 					&sprd_eic->irq_nb);
 }
 
Signature · 1 line
2.39.2
Reviewed-by on v1 2/3
#2 lore raw

Re: [RFT PATCH 2/3] gpio: eic-sprd: use a helper variable for &pdev->dev

Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Instead of dereferencing pdev everywhere, just store the address of the underlying struct device in a local variable.

Quoted 75 lines
---
  drivers/gpio/gpio-eic-sprd.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpio/gpio-eic-sprd.c +10 -10
index 9b2f9ccf8d77..be7f2fa5aa7b 100644
@@ -591,18 +591,19 @@ static void sprd_eic_unregister_notifier(void *data)
  static int sprd_eic_probe(struct platform_device *pdev)
  {
  	const struct sprd_eic_variant_data *pdata;
+	struct device *dev = &pdev->dev;
  	struct gpio_irq_chip *irq;
  	struct sprd_eic *sprd_eic;
  	struct resource *res;
  	int ret, i;
 
-	pdata = of_device_get_match_data(&pdev->dev);
+	pdata = of_device_get_match_data(dev);
  	if (!pdata) {
-		dev_err(&pdev->dev, "No matching driver data found.\n");
+		dev_err(dev, "No matching driver data found.\n");
  		return -EINVAL;
  	}
 
-	sprd_eic = devm_kzalloc(&pdev->dev, sizeof(*sprd_eic), GFP_KERNEL);
+	sprd_eic = devm_kzalloc(dev, sizeof(*sprd_eic), GFP_KERNEL);
  	if (!sprd_eic)
  		return -ENOMEM;
 
@@ -624,7 +625,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
  		if (!res)
  			break;
 
-		sprd_eic->base[i] = devm_ioremap_resource(&pdev->dev, res);
+		sprd_eic->base[i] = devm_ioremap_resource(dev, res);
  		if (IS_ERR(sprd_eic->base[i]))
  			return PTR_ERR(sprd_eic->base[i]);
  	}
@@ -632,7 +633,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
  	sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type];
  	sprd_eic->chip.ngpio = pdata->num_eics;
  	sprd_eic->chip.base = -1;
-	sprd_eic->chip.parent = &pdev->dev;
+	sprd_eic->chip.parent = dev;
  	sprd_eic->chip.direction_input = sprd_eic_direction_input;
  	switch (sprd_eic->type) {
  	case SPRD_EIC_DEBOUNCE:
@@ -659,9 +660,9 @@ static int sprd_eic_probe(struct platform_device *pdev)
  	irq->num_parents = 1;
  	irq->parents = &sprd_eic->irq;
 
-	ret = devm_gpiochip_add_data(&pdev->dev, &sprd_eic->chip, sprd_eic);
+	ret = devm_gpiochip_add_data(dev, &sprd_eic->chip, sprd_eic);
  	if (ret < 0) {
-		dev_err(&pdev->dev, "Could not register gpiochip %d.\n", ret);
+		dev_err(dev, "Could not register gpiochip %d.\n", ret);
  		return ret;
  	}
 
@@ -669,11 +670,10 @@ static int sprd_eic_probe(struct platform_device *pdev)
  	ret = atomic_notifier_chain_register(&sprd_eic_irq_notifier,
  					     &sprd_eic->irq_nb);
  	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
+		return dev_err_probe(dev, ret,
  				     "Failed to register with the interrupt notifier");
 
-	return devm_add_action_or_reset(&pdev->dev,
-					sprd_eic_unregister_notifier,
+	return devm_add_action_or_reset(dev, sprd_eic_unregister_notifier,
  					&sprd_eic->irq_nb);
  }
 
#3 lore raw

Re: [RFT PATCH 2/3] gpio: eic-sprd: use a helper variable for &pdev->dev

In reply to Bartosz Golaszewski
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Instead of dereferencing pdev everywhere, just store the address of the underlying struct device in a local variable.

...

drivers/gpio/gpio-eic-sprd.c static int sprd_eic_probe(struct platform_device *pdev) · line 677

Quoted 4 lines
drivers/gpio/gpio-eic-sprd.c +1 -2
-	return devm_add_action_or_reset(&pdev->dev,
-					sprd_eic_unregister_notifier,
+	return devm_add_action_or_reset(dev, sprd_eic_unregister_notifier,
 					&sprd_eic->irq_nb);

Ping-pong style detected: Lines added / modified by previous patch in the same series got modified again.

If you look at how I do that, I introduce the temporary variable with my new code and then reuse it later on.

OTOH, I see that the first one is supposed to be backported (?) in such case perhaps it's fine.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [RFT PATCH 2/3] gpio: eic-sprd: use a helper variable for &pdev->dev

Quoted 14 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Instead of dereferencing pdev everywhere, just store the address of the underlying struct device in a local variable.

...

drivers/gpio/gpio-eic-sprd.c static int sprd_eic_probe(struct platform_device *pdev) · line 677

Quoted 4 lines
drivers/gpio/gpio-eic-sprd.c +1 -2
-     return devm_add_action_or_reset(&pdev->dev,
-                                     sprd_eic_unregister_notifier,
+     return devm_add_action_or_reset(dev, sprd_eic_unregister_notifier,
                                      &sprd_eic->irq_nb);
Quoted 8 lines

Ping-pong style detected: Lines added / modified by previous patch in the same series got modified again.

If you look at how I do that, I introduce the temporary variable with my new code and then reuse it later on.

OTOH, I see that the first one is supposed to be backported (?) in such case perhaps it's fine.

I would typically do the same but the fix comes first in series.

Bart

#5 lore raw

PATCH 3/3 gpio: eic-sprd: use devm_platform_ioremap_resource()

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Make two calls into one by using devm_platform_ioremap_resource().

---
 drivers/gpio/gpio-eic-sprd.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-eic-sprd.c +1 -6
index be7f2fa5aa7b..1e548e4e4cb8 100644
@@ -594,7 +594,6 @@ static int sprd_eic_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct gpio_irq_chip *irq;
 	struct sprd_eic *sprd_eic;
-	struct resource *res;
 	int ret, i;
 
 	pdata = of_device_get_match_data(dev);
@@ -621,11 +620,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
 		 * have one bank EIC, thus base[1] and base[2] can be
 		 * optional.
 		 */
-		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-		if (!res)
-			break;
-
-		sprd_eic->base[i] = devm_ioremap_resource(dev, res);
+		sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, i);
 		if (IS_ERR(sprd_eic->base[i]))
 			return PTR_ERR(sprd_eic->base[i]);
 	}
Signature · 1 line
2.39.2
#6 lore raw

Re: [RFT PATCH 3/3] gpio: eic-sprd: use devm_platform_ioremap_resource()

Quoted 5 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Make two calls into one by using devm_platform_ioremap_resource().

Please don't do this. See the previous commit: 4ed7d7dd4890bb8120a3e77c16191a695fdfcc5a ("Revert "gpio: eic-sprd: Use devm_platform_ioremap_resource()"")

Quoted 29 lines
---
  drivers/gpio/gpio-eic-sprd.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-eic-sprd.c +1 -6
index be7f2fa5aa7b..1e548e4e4cb8 100644
@@ -594,7 +594,6 @@ static int sprd_eic_probe(struct platform_device *pdev)
  	struct device *dev = &pdev->dev;
  	struct gpio_irq_chip *irq;
  	struct sprd_eic *sprd_eic;
-	struct resource *res;
  	int ret, i;
 
  	pdata = of_device_get_match_data(dev);
@@ -621,11 +620,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
  		 * have one bank EIC, thus base[1] and base[2] can be
  		 * optional.
  		 */
-		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-		if (!res)
-			break;
-
-		sprd_eic->base[i] = devm_ioremap_resource(dev, res);
+		sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, i);
  		if (IS_ERR(sprd_eic->base[i]))
  			return PTR_ERR(sprd_eic->base[i]);
  	}
#7 lore raw

Re: [RFT PATCH 3/3] gpio: eic-sprd: use devm_platform_ioremap_resource()

Quoted 6 lines · Baolin Wang
Quoted 2 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 3 lines

Make two calls into one by using devm_platform_ioremap_resource().

Please don't do this. See the previous commit:
4ed7d7dd4890bb8120a3e77c16191a695fdfcc5a ("Revert "gpio: eic-sprd: Use devm_platform_ioremap_resource()"")

Ah, I see. Dropped. Could use a comment describing the problem though.

Bart

Quoted 29 lines
Quoted 29 lines
---
  drivers/gpio/gpio-eic-sprd.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-eic-sprd.c +1 -6
index be7f2fa5aa7b..1e548e4e4cb8 100644
@@ -594,7 +594,6 @@ static int sprd_eic_probe(struct platform_device *pdev)
      struct device *dev = &pdev->dev;
      struct gpio_irq_chip *irq;
      struct sprd_eic *sprd_eic;
-     struct resource *res;
      int ret, i;
 
      pdata = of_device_get_match_data(dev);
@@ -621,11 +620,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
               * have one bank EIC, thus base[1] and base[2] can be
               * optional.
               */
-             res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-             if (!res)
-                     break;
-
-             sprd_eic->base[i] = devm_ioremap_resource(dev, res);
+             sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, i);
              if (IS_ERR(sprd_eic->base[i]))
                      return PTR_ERR(sprd_eic->base[i]);
      }
#8 lore raw

Re: [RFT PATCH 3/3] gpio: eic-sprd: use devm_platform_ioremap_resource()

Quoted 10 lines · Bartosz Golaszewski
Quoted 8 lines · Baolin Wang
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Make two calls into one by using devm_platform_ioremap_resource().

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Please don't do this. See the previous commit:
4ed7d7dd4890bb8120a3e77c16191a695fdfcc5a ("Revert "gpio: eic-sprd: Use devm_platform_ioremap_resource()"")

Ah, I see. Dropped. Could use a comment describing the problem though.

Yes, I think so, in case someone does the same thing in the future.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
---
   drivers/gpio/gpio-eic-sprd.c | 7 +------
   1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-eic-sprd.c +1 -6
index be7f2fa5aa7b..1e548e4e4cb8 100644
@@ -594,7 +594,6 @@ static int sprd_eic_probe(struct platform_device *pdev)
       struct device *dev = &pdev->dev;
       struct gpio_irq_chip *irq;
       struct sprd_eic *sprd_eic;
-     struct resource *res;
       int ret, i;
 
       pdata = of_device_get_match_data(dev);
@@ -621,11 +620,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
                * have one bank EIC, thus base[1] and base[2] can be
                * optional.
                */
-             res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-             if (!res)
-                     break;
-
-             sprd_eic->base[i] = devm_ioremap_resource(dev, res);
+             sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, i);
               if (IS_ERR(sprd_eic->base[i]))
                       return PTR_ERR(sprd_eic->base[i]);
       }
#9 lore raw

Re: [RFT PATCH 3/3] gpio: eic-sprd: use devm_platform_ioremap_resource()

In reply to Bartosz Golaszewski
Quoted 3 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Make two calls into one by using devm_platform_ioremap_resource().

...

drivers/gpio/gpio-eic-sprd.c static int sprd_eic_probe(struct platform_device *pdev) · line 625

Quoted 8 lines
drivers/gpio/gpio-eic-sprd.c +1 -5
-		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-		if (!res)
-			break;
-
-		sprd_eic->base[i] = devm_ioremap_resource(dev, res);
+		sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, i);
 		if (IS_ERR(sprd_eic->base[i]))
 			return PTR_ERR(sprd_eic->base[i]);

break != return

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v1 1/3
#10 lore raw
In reply to Bartosz Golaszewski
Quoted 7 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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")

LGTM.

Quoted 41 lines
---
  drivers/gpio/gpio-eic-sprd.c | 19 +++++++++++++++++--
  1 file changed, 17 insertions(+), 2 deletions(-)
drivers/gpio/gpio-eic-sprd.c +17 -2
index 21a1afe358d6..9b2f9ccf8d77 100644
@@ -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[] = {
#11 lore raw
Quoted 6 lines · Baolin Wang
Quoted 2 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 9 lines
Quoted 5 lines

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")

LGTM.

Thanks, queued patches 1 and 2.

Bart

Quoted 41 lines
Quoted 41 lines
---
  drivers/gpio/gpio-eic-sprd.c | 19 +++++++++++++++++--
  1 file changed, 17 insertions(+), 2 deletions(-)
drivers/gpio/gpio-eic-sprd.c +17 -2
index 21a1afe358d6..9b2f9ccf8d77 100644
@@ -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[] = {