[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250728123251.384375-2-panchuang@vivo.com>
Date: Mon, 28 Jul 2025 20:32:51 +0800
From: Pan Chuang <panchuang@...o.com>
To: tglx@...utronix.de,
linux-kernel@...r.kernel.org
Cc: miquel.raynal@...tlin.com,
Jonathan.Cameron@...wei.com,
u.kleine-koenig@...gutronix.de,
angeg.delregno@...labora.com,
krzk@...nel.org,
a.fatoum@...gutronix.de,
frank.li@...o.com,
Pan Chuang <panchuang@...o.com>
Subject: [PATCH v7 1/1] genirq/devres: Add dev_err_probe() in devm_request_threaded_irq() and devm_request_any_context_irq()
Modify devm_request_thread_irq() and devm_request_any_context_irq(), in
order to print an error message by default when the request fails.
Converting drivers to use this API has the following benefits:
1.More than 2,000 lines of code can be saved by removing redundant error
messages in drivers.
2.Upper-layer functions can directly return error codes without missing
debugging information.
3.Having proper and consistent information about why the device cannot
be used is useful.
Signed-off-by: Pan Chuang <panchuang@...o.com>
Signed-off-by: Yangtao Li <frank.li@...o.com>
---
kernel/irq/devres.c | 78 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 74 insertions(+), 4 deletions(-)
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
index eb16a58e0322..a1b934c1ecc8 100644
--- a/kernel/irq/devres.c
+++ b/kernel/irq/devres.c
@@ -31,7 +31,7 @@ static int devm_irq_match(struct device *dev, void *res, void *data)
}
/**
- * devm_request_threaded_irq - allocate an interrupt line for a managed device
+ * __devm_request_threaded_irq - allocate an interrupt line for a managed device
* @dev: device to request interrupt for
* @irq: Interrupt line to allocate
* @handler: Function to be called when the IRQ occurs
@@ -49,7 +49,7 @@ static int devm_irq_match(struct device *dev, void *res, void *data)
* If an IRQ allocated with this function needs to be freed
* separately, devm_free_irq() must be used.
*/
-int devm_request_threaded_irq(struct device *dev, unsigned int irq,
+static int __devm_request_threaded_irq(struct device *dev, unsigned int irq,
irq_handler_t handler, irq_handler_t thread_fn,
unsigned long irqflags, const char *devname,
void *dev_id)
@@ -78,10 +78,46 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
return 0;
}
+
+/**
+ * devm_request_threaded_irq - allocate an interrupt line for a managed device with error logging
+ * @dev: Device to request interrupt for
+ * @irq: Interrupt line to allocate
+ * @handler: Function to be called when the IRQ occurs
+ * @thread_fn: Function to be called in a threaded interrupt context. NULL
+ * for devices which handle everything in @handler
+ * @irqflags: Interrupt type flags
+ * @devname: An ascii name for the claiming device, dev_name(dev) if NULL
+ * @dev_id: A cookie passed back to the handler function
+ *
+ * This function extends __devm_request_threaded_irq by adding detailed error
+ * logging via dev_err_probe() when the underlying request fails. It ensures the
+ * interrupt is automatically freed on driver detach and provides contextual
+ * information (e.g., IRQ number, handler address, device name) in error messages.
+ *
+ * Return: 0 on success or a negative error number.
+ */
+int devm_request_threaded_irq(struct device *dev, unsigned int irq,
+ irq_handler_t handler, irq_handler_t thread_fn,
+ unsigned long irqflags, const char *devname,
+ void *dev_id)
+{
+ int rc;
+
+ rc = __devm_request_threaded_irq(dev, irq, handler, thread_fn, irqflags,
+ devname, dev_id);
+ if (rc < 0) {
+ return dev_err_probe(dev, rc, "request_irq(%u) %pS %pS %s\n",
+ irq, handler, thread_fn,
+ devname ? : dev_name(dev));
+ }
+
+ return 0;
+}
EXPORT_SYMBOL(devm_request_threaded_irq);
/**
- * devm_request_any_context_irq - allocate an interrupt line for a managed device
+ * __devm_request_any_context_irq - allocate an interrupt line for a managed device
* @dev: device to request interrupt for
* @irq: Interrupt line to allocate
* @handler: Function to be called when the IRQ occurs
@@ -97,7 +133,7 @@ EXPORT_SYMBOL(devm_request_threaded_irq);
* If an IRQ allocated with this function needs to be freed
* separately, devm_free_irq() must be used.
*/
-int devm_request_any_context_irq(struct device *dev, unsigned int irq,
+static int __devm_request_any_context_irq(struct device *dev, unsigned int irq,
irq_handler_t handler, unsigned long irqflags,
const char *devname, void *dev_id)
{
@@ -124,6 +160,40 @@ int devm_request_any_context_irq(struct device *dev, unsigned int irq,
return rc;
}
+
+/**
+ * devm_request_any_context_irq - allocate an interrupt line for a managed device with error logging
+ * @dev: Device to request interrupt for
+ * @irq: Interrupt line to allocate
+ * @handler: Function to be called when the IRQ occurs
+ * @irqflags: Interrupt type flags
+ * @devname: An ascii name for the claiming device, dev_name(dev) if NULL
+ * @dev_id: A cookie passed back to the handler function
+ *
+ * This function extends __devm_request_any_context_irq by adding detailed error
+ * logging via dev_err_probe() when the underlying request fails. It ensures the
+ * interrupt is automatically freed on driver detach and provides contextual
+ * information (e.g., IRQ number, handler address, device name) in error messages.
+ *
+ * On failure, it returns a negative value. On success, it returns either
+ * IRQC_IS_HARDIRQ or IRQC_IS_NESTED.
+ */
+int devm_request_any_context_irq(struct device *dev, unsigned int irq,
+ irq_handler_t handler, unsigned long irqflags,
+ const char *devname, void *dev_id)
+{
+ int rc;
+
+ rc = __devm_request_any_context_irq(dev, irq, handler, irqflags,
+ devname, dev_id);
+ if (rc < 0) {
+ return dev_err_probe(dev, rc, "request_irq(%u) %pS %s\n",
+ irq, handler, devname ? : dev_name(dev));
+ }
+
+ return rc;
+
+}
EXPORT_SYMBOL(devm_request_any_context_irq);
/**
--
2.34.1
Powered by blists - more mailing lists