* Re: [PATCH v2 1/2] drivers: provide devm_platform_request_irq()
@ 2020-05-24 7:00 Markus Elfring
0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2020-05-24 7:00 UTC (permalink / raw)
To: Dejin Zheng, linux-i2c, kernel-janitors
Cc: Ard Biesheuvel, Barry Song, Baruch Siach, Fabio Estevam,
Florian Fainelli, Greg Kroah-Hartman, Heiko Stübner,
Kevin Hilman, Linus Walleij, Michal Simek, Paul Cercueil,
Rafael J. Wysocki, Ray Jui, Scott Branden, Shawn Guo,
Vladimir Zapolskiy, Wolfram Sang, linux-kernel, Coccinelle
> It will call devm_request_irq() after platform_get_irq() function
> in many drivers, sometimes, it is not right for the error handling
> of these two functions in some drivers. so provide this function
> to simplify the driver.
I recommend to improve also this change description.
How do you think about a wording variant like the following?
The function “devm_request_irq” is called after the
function “platform_get_irq” in many drivers.
The exception handling is incomplete there sometimes.
Thus add a corresponding wrapper function for the simplification
of the drivers.
Will a companion script for the semantic patch language (Coccinelle software)
become helpful for further support of collateral evolution?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] drivers: provide devm_platform_request_irq()
2020-05-26 17:11 ` Grygorii Strashko
@ 2020-05-27 13:31 ` Dejin Zheng
0 siblings, 0 replies; 4+ messages in thread
From: Dejin Zheng @ 2020-05-27 13:31 UTC (permalink / raw)
To: Grygorii Strashko; +Cc: gregkh, linux-i2c, linux-kernel, Wolfram Sang
On Tue, May 26, 2020 at 08:11:22PM +0300, Grygorii Strashko wrote:
>
>
> On 23/05/2020 17:51, Dejin Zheng wrote:
> > It will call devm_request_irq() after platform_get_irq() function
> > in many drivers, sometimes, it is not right for the error handling
> > of these two functions in some drivers. so provide this function
> > to simplify the driver.
> >
> > Cc: Michal Simek <michal.simek@xilinx.com>
> > Cc: Wolfram Sang <wsa@the-dreams.de>
> > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > ---
> > v1 -> v2:
> > - The patch content has not changed. just resend it by this discussion:
> > https://patchwork.ozlabs.org/project/linux-i2c/patch/20200520144821.8069-1-zhengdejin5@gmail.com/
> >
> > drivers/base/platform.c | 33 +++++++++++++++++++++++++++++++++
> > include/linux/platform_device.h | 4 ++++
> > 2 files changed, 37 insertions(+)
> >
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index c0d0a5490ac6..1d2fd1ea3bc5 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -275,6 +275,39 @@ int platform_irq_count(struct platform_device *dev)
> > }
> > EXPORT_SYMBOL_GPL(platform_irq_count);
> > +/**
> > + * devm_platform_request_irq - get an irq and allocate an interrupt
> > + * line for a managed device
> > + * @pdev: platform device
> > + * @num: IRQ number index
> > + * @irq: get an IRQ for a device if irq != NULL
> > + * @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
> > + *
> > + * Return: zero on success, negative error number on failure.
> > + */
> > +int devm_platform_request_irq(struct platform_device *pdev, unsigned int num,
> > + unsigned int *irq, irq_handler_t handler,
> > + unsigned long irqflags, const char *devname, void *dev_id)
> > +{
> > + int tmp_irq, ret;
> > +
> > + tmp_irq = platform_get_irq(pdev, num);
> > + if (tmp_irq < 0)
> > + return tmp_irq;
> > +
> > + ret = devm_request_irq(&pdev->dev, tmp_irq, handler, irqflags,
> > + devname, dev_id);
> > + if (ret < 0)
> > + dev_err(&pdev->dev, "can't request IRQ\n");
> > + else if (irq != NULL)
> > + *irq = tmp_irq;
> > + return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(devm_platform_request_irq);
> > +
> > /**
> > * platform_get_resource_byname - get a resource for a device by name
> > * @dev: platform device
> > diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> > index 77a2aada106d..d94652deea5c 100644
> > --- a/include/linux/platform_device.h
> > +++ b/include/linux/platform_device.h
> > @@ -11,6 +11,7 @@
> > #define _PLATFORM_DEVICE_H_
> > #include <linux/device.h>
> > +#include <linux/interrupt.h>
> > #define PLATFORM_DEVID_NONE (-1)
> > #define PLATFORM_DEVID_AUTO (-2)
> > @@ -70,6 +71,9 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev,
> > extern int platform_get_irq(struct platform_device *, unsigned int);
> > extern int platform_get_irq_optional(struct platform_device *, unsigned int);
> > extern int platform_irq_count(struct platform_device *);
> > +extern int devm_platform_request_irq(struct platform_device *pdev,
> > + unsigned int num, unsigned int *irq, irq_handler_t handler,
> > + unsigned long irqflags, const char *devname, void *dev_id);
>
>
> it has to be documented in devres.rst
>
Grygorii, Thnaks! I will add it in patch v3.
BTW, the Gmail will prevent me sending messages to a large number of
recipients, So I reduced some recipients, but still retained i2c and
linux kernel mail list. sorry!
BR,
Dejin
> > extern struct resource *platform_get_resource_byname(struct platform_device *,
> > unsigned int,
> > const char *);
> >
>
>
>
> --
> Best regards,
> grygorii
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] drivers: provide devm_platform_request_irq()
2020-05-23 14:51 ` [PATCH v2 1/2] " Dejin Zheng
@ 2020-05-26 17:11 ` Grygorii Strashko
2020-05-27 13:31 ` Dejin Zheng
0 siblings, 1 reply; 4+ messages in thread
From: Grygorii Strashko @ 2020-05-26 17:11 UTC (permalink / raw)
To: Dejin Zheng, gregkh, rafael, f.fainelli, rjui, sbranden,
michal.simek, baruch, paul, khilman, shawnguo, festevam, vz,
heiko, linus.walleij, baohua, ardb, linux-i2c
Cc: linux-kernel, Wolfram Sang
On 23/05/2020 17:51, Dejin Zheng wrote:
> It will call devm_request_irq() after platform_get_irq() function
> in many drivers, sometimes, it is not right for the error handling
> of these two functions in some drivers. so provide this function
> to simplify the driver.
>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> ---
> v1 -> v2:
> - The patch content has not changed. just resend it by this discussion:
> https://patchwork.ozlabs.org/project/linux-i2c/patch/20200520144821.8069-1-zhengdejin5@gmail.com/
>
> drivers/base/platform.c | 33 +++++++++++++++++++++++++++++++++
> include/linux/platform_device.h | 4 ++++
> 2 files changed, 37 insertions(+)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index c0d0a5490ac6..1d2fd1ea3bc5 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -275,6 +275,39 @@ int platform_irq_count(struct platform_device *dev)
> }
> EXPORT_SYMBOL_GPL(platform_irq_count);
>
> +/**
> + * devm_platform_request_irq - get an irq and allocate an interrupt
> + * line for a managed device
> + * @pdev: platform device
> + * @num: IRQ number index
> + * @irq: get an IRQ for a device if irq != NULL
> + * @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
> + *
> + * Return: zero on success, negative error number on failure.
> + */
> +int devm_platform_request_irq(struct platform_device *pdev, unsigned int num,
> + unsigned int *irq, irq_handler_t handler,
> + unsigned long irqflags, const char *devname, void *dev_id)
> +{
> + int tmp_irq, ret;
> +
> + tmp_irq = platform_get_irq(pdev, num);
> + if (tmp_irq < 0)
> + return tmp_irq;
> +
> + ret = devm_request_irq(&pdev->dev, tmp_irq, handler, irqflags,
> + devname, dev_id);
> + if (ret < 0)
> + dev_err(&pdev->dev, "can't request IRQ\n");
> + else if (irq != NULL)
> + *irq = tmp_irq;
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(devm_platform_request_irq);
> +
> /**
> * platform_get_resource_byname - get a resource for a device by name
> * @dev: platform device
> diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> index 77a2aada106d..d94652deea5c 100644
> --- a/include/linux/platform_device.h
> +++ b/include/linux/platform_device.h
> @@ -11,6 +11,7 @@
> #define _PLATFORM_DEVICE_H_
>
> #include <linux/device.h>
> +#include <linux/interrupt.h>
>
> #define PLATFORM_DEVID_NONE (-1)
> #define PLATFORM_DEVID_AUTO (-2)
> @@ -70,6 +71,9 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev,
> extern int platform_get_irq(struct platform_device *, unsigned int);
> extern int platform_get_irq_optional(struct platform_device *, unsigned int);
> extern int platform_irq_count(struct platform_device *);
> +extern int devm_platform_request_irq(struct platform_device *pdev,
> + unsigned int num, unsigned int *irq, irq_handler_t handler,
> + unsigned long irqflags, const char *devname, void *dev_id);
it has to be documented in devres.rst
> extern struct resource *platform_get_resource_byname(struct platform_device *,
> unsigned int,
> const char *);
>
--
Best regards,
grygorii
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] drivers: provide devm_platform_request_irq()
2020-05-23 14:51 [PATCH v2 0/2] " Dejin Zheng
@ 2020-05-23 14:51 ` Dejin Zheng
2020-05-26 17:11 ` Grygorii Strashko
0 siblings, 1 reply; 4+ messages in thread
From: Dejin Zheng @ 2020-05-23 14:51 UTC (permalink / raw)
To: gregkh, rafael, f.fainelli, rjui, sbranden, michal.simek, baruch,
paul, khilman, shawnguo, festevam, vz, heiko, linus.walleij,
baohua, ardb, linux-i2c
Cc: linux-kernel, Dejin Zheng, Wolfram Sang
It will call devm_request_irq() after platform_get_irq() function
in many drivers, sometimes, it is not right for the error handling
of these two functions in some drivers. so provide this function
to simplify the driver.
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
v1 -> v2:
- The patch content has not changed. just resend it by this discussion:
https://patchwork.ozlabs.org/project/linux-i2c/patch/20200520144821.8069-1-zhengdejin5@gmail.com/
drivers/base/platform.c | 33 +++++++++++++++++++++++++++++++++
include/linux/platform_device.h | 4 ++++
2 files changed, 37 insertions(+)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index c0d0a5490ac6..1d2fd1ea3bc5 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -275,6 +275,39 @@ int platform_irq_count(struct platform_device *dev)
}
EXPORT_SYMBOL_GPL(platform_irq_count);
+/**
+ * devm_platform_request_irq - get an irq and allocate an interrupt
+ * line for a managed device
+ * @pdev: platform device
+ * @num: IRQ number index
+ * @irq: get an IRQ for a device if irq != NULL
+ * @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
+ *
+ * Return: zero on success, negative error number on failure.
+ */
+int devm_platform_request_irq(struct platform_device *pdev, unsigned int num,
+ unsigned int *irq, irq_handler_t handler,
+ unsigned long irqflags, const char *devname, void *dev_id)
+{
+ int tmp_irq, ret;
+
+ tmp_irq = platform_get_irq(pdev, num);
+ if (tmp_irq < 0)
+ return tmp_irq;
+
+ ret = devm_request_irq(&pdev->dev, tmp_irq, handler, irqflags,
+ devname, dev_id);
+ if (ret < 0)
+ dev_err(&pdev->dev, "can't request IRQ\n");
+ else if (irq != NULL)
+ *irq = tmp_irq;
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_platform_request_irq);
+
/**
* platform_get_resource_byname - get a resource for a device by name
* @dev: platform device
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 77a2aada106d..d94652deea5c 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -11,6 +11,7 @@
#define _PLATFORM_DEVICE_H_
#include <linux/device.h>
+#include <linux/interrupt.h>
#define PLATFORM_DEVID_NONE (-1)
#define PLATFORM_DEVID_AUTO (-2)
@@ -70,6 +71,9 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev,
extern int platform_get_irq(struct platform_device *, unsigned int);
extern int platform_get_irq_optional(struct platform_device *, unsigned int);
extern int platform_irq_count(struct platform_device *);
+extern int devm_platform_request_irq(struct platform_device *pdev,
+ unsigned int num, unsigned int *irq, irq_handler_t handler,
+ unsigned long irqflags, const char *devname, void *dev_id);
extern struct resource *platform_get_resource_byname(struct platform_device *,
unsigned int,
const char *);
--
2.25.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-05-27 13:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-24 7:00 [PATCH v2 1/2] drivers: provide devm_platform_request_irq() Markus Elfring
-- strict thread matches above, loose matches on Subject: below --
2020-05-23 14:51 [PATCH v2 0/2] " Dejin Zheng
2020-05-23 14:51 ` [PATCH v2 1/2] " Dejin Zheng
2020-05-26 17:11 ` Grygorii Strashko
2020-05-27 13:31 ` Dejin Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).