From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Samuel Moelius <sam.moelius@trailofbits.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Bamvor Jian Zhang <bamv2005@gmail.com>,
Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>
Subject: [PATCH v1 1/3] gpiolib: Introduce devm_gpiochip_dispose_irq_mappings()
Date: Wed, 21 Oct 2026 22:44:43 +0200 [thread overview]
Message-ID: <20261021204654.1001101-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20261021204654.1001101-1-andriy.shevchenko@linux.intel.com>
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
next prev parent reply other threads:[~2026-10-21 20:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261021204654.1001101-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bamv2005@gmail.com \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sam.moelius@trailofbits.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®