mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings
@ 2026-10-21 20:44 Andy Shevchenko
  2026-10-21 20:44 ` [PATCH v1 1/3] gpiolib: Introduce devm_gpiochip_dispose_irq_mappings() Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-10-21 20:44 UTC (permalink / raw)
  To: Samuel Moelius, Andy Shevchenko, Bartosz Golaszewski, linux-gpio,
	linux-kernel
  Cc: Bamvor Jian Zhang, Linus Walleij, Bartosz Golaszewski

I have noticed that a few drivers use almost the same code to dispose IRQ
mappings. This series to deduplicate the efforts. I only converted a couple
of the users (there are potentially more) in order to stay in the same
subsystem.

Andy Shevchenko (3):
  gpiolib: Introduce devm_gpiochip_dispose_irq_mappings()
  gpio: mockup: Replace custom devm_gpiochip_dispose_irq_mappings()
  gpio: sim: Replace custom devm_gpiochip_dispose_irq_mappings()

 drivers/gpio/gpio-mockup.c    | 15 +--------------
 drivers/gpio/gpio-sim.c       | 17 ++++-------------
 drivers/gpio/gpiolib-devres.c | 33 +++++++++++++++++++++++++++++++++
 include/linux/gpio/driver.h   |  4 ++++
 4 files changed, 42 insertions(+), 27 deletions(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 1/3] gpiolib: Introduce devm_gpiochip_dispose_irq_mappings()
  2026-10-21 20:44 [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Andy Shevchenko
@ 2026-10-21 20:44 ` Andy Shevchenko
  2026-10-21 20:44 ` [PATCH v1 2/3] gpio: mockup: Replace custom devm_gpiochip_dispose_irq_mappings() Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-10-21 20:44 UTC (permalink / raw)
  To: Samuel Moelius, Andy Shevchenko, Bartosz Golaszewski, linux-gpio,
	linux-kernel
  Cc: Bamvor Jian Zhang, Linus Walleij, Bartosz Golaszewski

Several drivers already copy'n'paste almost the same code to dispose
IRQ mappings on remove over and over. Deduplicate that by introducing
a devm_gpiochip_dispose_irq_mappings().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-devres.c | 33 +++++++++++++++++++++++++++++++++
 include/linux/gpio/driver.h   |  4 ++++
 2 files changed, 37 insertions(+)

diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index cc0e434a37d3..94690f14a949 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -10,6 +10,7 @@
 #include <linux/err.h>
 #include <linux/export.h>
 #include <linux/gfp.h>
+#include <linux/irqdomain.h>
 #include <linux/types.h>
 
 #include <linux/gpio/consumer.h>
@@ -323,6 +324,38 @@ void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs)
 }
 EXPORT_SYMBOL_GPL(devm_gpiod_put_array);
 
+struct gpiochip_irqdomain {
+	struct gpio_chip *gc;
+	struct irq_domain *domain;
+};
+
+static void gpiochip_dispose_irq_mappings(struct device *dev, void *res)
+{
+	struct gpiochip_irqdomain *gcirq = res;
+
+	for (unsigned int i = 0; i < gcirq->gc->ngpio; i++)
+		irq_dispose_mapping(irq_find_mapping(gcirq->domain, i));
+}
+
+int devm_gpiochip_dispose_irq_mappings(struct device *dev,
+				       struct gpio_chip *gc,
+				       struct irq_domain *domain)
+{
+	struct gpiochip_irqdomain *gcirq;
+
+	gcirq = devres_alloc(gpiochip_dispose_irq_mappings, sizeof(*gcirq), GFP_KERNEL);
+	if (!gcirq)
+		return -ENOMEM;
+
+	gcirq->gc = gc;
+	gcirq->domain = domain;
+
+	devres_add(dev, gcirq);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_gpiochip_dispose_irq_mappings);
+
 static void devm_gpio_chip_release(void *data)
 {
 	struct gpio_chip *gc = data;
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index b3b938ec5332..c610b5a9f8fa 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -707,6 +707,10 @@ static inline int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
 }
 #endif
 
+int devm_gpiochip_dispose_irq_mappings(struct device *dev,
+				       struct gpio_chip *gc,
+				       struct irq_domain *domain);
+
 int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset);
 void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset);
 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
-- 
2.50.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 2/3] gpio: mockup: Replace custom devm_gpiochip_dispose_irq_mappings()
  2026-10-21 20:44 [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Andy Shevchenko
  2026-10-21 20:44 ` [PATCH v1 1/3] gpiolib: Introduce devm_gpiochip_dispose_irq_mappings() Andy Shevchenko
@ 2026-10-21 20:44 ` Andy Shevchenko
  2026-10-21 20:44 ` [PATCH v1 3/3] gpio: sim: " Andy Shevchenko
  2026-10-22  9:11 ` [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Bartosz Golaszewski
  3 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-10-21 20:44 UTC (permalink / raw)
  To: Samuel Moelius, Andy Shevchenko, Bartosz Golaszewski, linux-gpio,
	linux-kernel
  Cc: Bamvor Jian Zhang, Linus Walleij, Bartosz Golaszewski

Replace custom implementation of devm_gpiochip_dispose_irq_mappings().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-mockup.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 1c6a2f3414f1..f782b55240b3 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -400,19 +400,6 @@ static void gpio_mockup_debugfs_cleanup(void *data)
 	debugfs_remove_recursive(chip->dbg_dir);
 }
 
-static void gpio_mockup_dispose_mappings(void *data)
-{
-	struct gpio_mockup_chip *chip = data;
-	struct gpio_chip *gc = &chip->gc;
-	int i, irq;
-
-	for (i = 0; i < gc->ngpio; i++) {
-		irq = irq_find_mapping(chip->irq_sim_domain, i);
-		if (irq)
-			irq_dispose_mapping(irq);
-	}
-}
-
 static int gpio_mockup_probe(struct platform_device *pdev)
 {
 	struct gpio_mockup_chip *chip;
@@ -473,7 +460,7 @@ static int gpio_mockup_probe(struct platform_device *pdev)
 	if (IS_ERR(chip->irq_sim_domain))
 		return PTR_ERR(chip->irq_sim_domain);
 
-	rv = devm_add_action_or_reset(dev, gpio_mockup_dispose_mappings, chip);
+	rv = devm_gpiochip_dispose_irq_mappings(dev, gc, chip->irq_sim_domain);
 	if (rv)
 		return rv;
 
-- 
2.50.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 3/3] gpio: sim: Replace custom devm_gpiochip_dispose_irq_mappings()
  2026-10-21 20:44 [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Andy Shevchenko
  2026-10-21 20:44 ` [PATCH v1 1/3] gpiolib: Introduce devm_gpiochip_dispose_irq_mappings() Andy Shevchenko
  2026-10-21 20:44 ` [PATCH v1 2/3] gpio: mockup: Replace custom devm_gpiochip_dispose_irq_mappings() Andy Shevchenko
@ 2026-10-21 20:44 ` Andy Shevchenko
  2026-10-22  9:11 ` [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Bartosz Golaszewski
  3 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-10-21 20:44 UTC (permalink / raw)
  To: Samuel Moelius, Andy Shevchenko, Bartosz Golaszewski, linux-gpio,
	linux-kernel
  Cc: Bamvor Jian Zhang, Linus Walleij, Bartosz Golaszewski

Replace custom implementation of devm_gpiochip_dispose_irq_mappings().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-sim.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 34b45d0d3575..5667871f21c2 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -338,15 +338,6 @@ static void gpio_sim_put_device(void *data)
 	put_device(dev);
 }
 
-static void gpio_sim_dispose_mappings(void *data)
-{
-	struct gpio_sim_chip *chip = data;
-	unsigned int i;
-
-	for (i = 0; i < chip->gc.ngpio; i++)
-		irq_dispose_mapping(irq_find_mapping(chip->irq_sim, i));
-}
-
 static void gpio_sim_sysfs_remove(void *data)
 {
 	struct gpio_sim_chip *chip = data;
@@ -467,10 +458,6 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
 	if (IS_ERR(chip->irq_sim))
 		return PTR_ERR(chip->irq_sim);
 
-	ret = devm_add_action_or_reset(dev, gpio_sim_dispose_mappings, chip);
-	if (ret)
-		return ret;
-
 	ret = devm_mutex_init(dev, &chip->lock);
 	if (ret)
 		return ret;
@@ -496,6 +483,10 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
 	gc->dbg_show = PTR_IF(IS_ENABLED(CONFIG_DEBUG_FS), gpio_sim_dbg_show);
 	gc->can_sleep = true;
 
+	ret = devm_gpiochip_dispose_irq_mappings(dev, gc, chip->irq_sim);
+	if (ret)
+		return ret;
+
 	ret = devm_gpiochip_add_data(dev, gc, chip);
 	if (ret)
 		return ret;
-- 
2.50.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings
  2026-10-21 20:44 [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Andy Shevchenko
                   ` (2 preceding siblings ...)
  2026-10-21 20:44 ` [PATCH v1 3/3] gpio: sim: " Andy Shevchenko
@ 2026-10-22  9:11 ` Bartosz Golaszewski
  2026-10-22 13:32   ` Andy Shevchenko
  3 siblings, 1 reply; 8+ messages in thread
From: Bartosz Golaszewski @ 2026-10-22  9:11 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bamvor Jian Zhang, Linus Walleij, Bartosz Golaszewski,
	Samuel Moelius, Bartosz Golaszewski, linux-gpio, linux-kernel

On Wed, 21 Oct 2026 22:44:42 +0200, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> said:
> I have noticed that a few drivers use almost the same code to dispose IRQ
> mappings. This series to deduplicate the efforts. I only converted a couple
> of the users (there are potentially more) in order to stay in the same
> subsystem.
>

The "few" being 2 testing drivers of which one (mockup) should ideally go away.
Do we really want to add more code to GPIO core that will only be used in
testing module(s)? I don't think this is useful, sorry.

Bartosz

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings
  2026-10-22  9:11 ` [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Bartosz Golaszewski
@ 2026-10-22 13:32   ` Andy Shevchenko
  2026-10-22 14:05     ` Bartosz Golaszewski
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-10-22 13:32 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Bamvor Jian Zhang, Linus Walleij, Samuel Moelius,
	Bartosz Golaszewski, linux-gpio, linux-kernel

On Thu, Oct 22, 2026 at 02:11:38AM -0700, Bartosz Golaszewski wrote:
> On Wed, 21 Oct 2026 22:44:42 +0200, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> said:
> > I have noticed that a few drivers use almost the same code to dispose IRQ
> > mappings. This series to deduplicate the efforts. I only converted a couple
> > of the users (there are potentially more) in order to stay in the same
> > subsystem.
> The "few" being 2 testing drivers of which one (mockup) should ideally go away.
> Do we really want to add more code to GPIO core that will only be used in
> testing module(s)? I don't think this is useful, sorry.

I meant a few. As I pointed these were chosen explicitly for the sake of not
crossing the subsystem boundaries. I looked at Broadcom one, it is so big mess
but I think I can get an advantage on it. Also there are other drivers that
just need more work to check (and many of them are outside of drivers/gpio),
but I'm pretty sure the new API has a good potential.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings
  2026-10-22 13:32   ` Andy Shevchenko
@ 2026-10-22 14:05     ` Bartosz Golaszewski
  2026-10-22 14:39       ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Bartosz Golaszewski @ 2026-10-22 14:05 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bamvor Jian Zhang, Linus Walleij, Samuel Moelius,
	Bartosz Golaszewski, linux-gpio, linux-kernel,
	Bartosz Golaszewski

On Thu, 22 Oct 2026 15:32:44 +0200, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> said:
> On Thu, Oct 22, 2026 at 02:11:38AM -0700, Bartosz Golaszewski wrote:
>> On Wed, 21 Oct 2026 22:44:42 +0200, Andy Shevchenko
>> <andriy.shevchenko@linux.intel.com> said:
>> > I have noticed that a few drivers use almost the same code to dispose IRQ
>> > mappings. This series to deduplicate the efforts. I only converted a couple
>> > of the users (there are potentially more) in order to stay in the same
>> > subsystem.
>> The "few" being 2 testing drivers of which one (mockup) should ideally go away.
>> Do we really want to add more code to GPIO core that will only be used in
>> testing module(s)? I don't think this is useful, sorry.
>
> I meant a few. As I pointed these were chosen explicitly for the sake of not
> crossing the subsystem boundaries. I looked at Broadcom one, it is so big mess
> but I think I can get an advantage on it. Also there are other drivers that
> just need more work to check (and many of them are outside of drivers/gpio),
> but I'm pretty sure the new API has a good potential.
>

Would it be possible to provide at least one more user other than the testing
drivers?

Bart

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings
  2026-10-22 14:05     ` Bartosz Golaszewski
@ 2026-10-22 14:39       ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-10-22 14:39 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Bamvor Jian Zhang, Linus Walleij, Samuel Moelius,
	Bartosz Golaszewski, linux-gpio, linux-kernel

On Thu, Oct 22, 2026 at 07:05:55AM -0700, Bartosz Golaszewski wrote:
> On Thu, 22 Oct 2026 15:32:44 +0200, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> said:
> > On Thu, Oct 22, 2026 at 02:11:38AM -0700, Bartosz Golaszewski wrote:
> >> On Wed, 21 Oct 2026 22:44:42 +0200, Andy Shevchenko
> >> <andriy.shevchenko@linux.intel.com> said:
> >> > I have noticed that a few drivers use almost the same code to dispose IRQ
> >> > mappings. This series to deduplicate the efforts. I only converted a couple
> >> > of the users (there are potentially more) in order to stay in the same
> >> > subsystem.
> >> The "few" being 2 testing drivers of which one (mockup) should ideally go away.
> >> Do we really want to add more code to GPIO core that will only be used in
> >> testing module(s)? I don't think this is useful, sorry.
> >
> > I meant a few. As I pointed these were chosen explicitly for the sake of not
> > crossing the subsystem boundaries. I looked at Broadcom one, it is so big mess
> > but I think I can get an advantage on it. Also there are other drivers that
> > just need more work to check (and many of them are outside of drivers/gpio),
> > but I'm pretty sure the new API has a good potential.
> 
> Would it be possible to provide at least one more user other than the testing
> drivers?

Sure.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-22 14:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 20:44 [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Andy Shevchenko
2026-10-21 20:44 ` [PATCH v1 1/3] gpiolib: Introduce devm_gpiochip_dispose_irq_mappings() Andy Shevchenko
2026-10-21 20:44 ` [PATCH v1 2/3] gpio: mockup: Replace custom devm_gpiochip_dispose_irq_mappings() Andy Shevchenko
2026-10-21 20:44 ` [PATCH v1 3/3] gpio: sim: " Andy Shevchenko
2026-10-22  9:11 ` [PATCH v1 0/3] gpio: Introduce helper to dispose IRQ mappings Bartosz Golaszewski
2026-10-22 13:32   ` Andy Shevchenko
2026-10-22 14:05     ` Bartosz Golaszewski
2026-10-22 14:39       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®