2020-07-17 16:12:17

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH v4 0/2] drivers: provide devm_platform_request_irq()

It will call devm_request_irq() after platform_get_irq() function
in many drivers, And sometimes, the error handling of these two functions
is incorrect in some drivers. So this function is provided to simplify
the driver.

the first patch will provide devm_platform_request_irq(), and the
second patch will convert to devm_platform_request_irq() in some
dirver of i2c bus.

v3 -> v4:
- The patch v3 sent on May 27 may be lost somewhere in the
world, so resend it.
- add Michal's Acked-by tag in the second patch. and Thanks
for Michal's help.

v2 -> v3:
- add devm_platform_request_irq() to devres.rst by Grygorii's
suggestion.
- And also Thanks Michal, Wolfram and Linus's review and
comments.
v1 -> v2:
- I give up this series of patches in v1 version. I resend this
patches v2 by that discussion:
https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/
The patch content has not changed.

Dejin Zheng (2):
drivers: provide devm_platform_request_irq()
i2c: busses: convert to devm_platform_request_irq()

.../driver-api/driver-model/devres.rst | 1 +
drivers/base/platform.c | 33 +++++++++++++++++++
drivers/i2c/busses/i2c-bcm-kona.c | 16 ++-------
drivers/i2c/busses/i2c-cadence.c | 10 ++----
drivers/i2c/busses/i2c-digicolor.c | 10 ++----
drivers/i2c/busses/i2c-emev2.c | 5 ++-
drivers/i2c/busses/i2c-jz4780.c | 5 ++-
drivers/i2c/busses/i2c-meson.c | 13 +++-----
drivers/i2c/busses/i2c-mxs.c | 9 ++---
drivers/i2c/busses/i2c-pnx.c | 9 ++---
drivers/i2c/busses/i2c-rcar.c | 9 ++---
drivers/i2c/busses/i2c-rk3x.c | 14 ++------
drivers/i2c/busses/i2c-sirf.c | 10 ++----
drivers/i2c/busses/i2c-stu300.c | 4 +--
drivers/i2c/busses/i2c-synquacer.c | 12 ++-----
include/linux/platform_device.h | 4 +++
16 files changed, 73 insertions(+), 91 deletions(-)

--
2.25.0


2020-07-17 16:12:23

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH v4 1/2] drivers: provide devm_platform_request_irq()

It will call devm_request_irq() after platform_get_irq() function
in many drivers, And sometimes, the error handling of these two functions
is incorrect in some drivers. So this function is provided to simplify
the driver.

Cc: Michal Simek <[email protected]>
Cc: Wolfram Sang <[email protected]>
Signed-off-by: Dejin Zheng <[email protected]>
---
v3 -> v4:
- The patch v3 sent on May 27 may be lost somewhere in the
world, so resend it.
v2 -> v3:
- add devm_platform_request_irq() to devres.rst by Grygorii's
suggestion.
v1 -> v2:
- The patch content has not changed. just resend it by this discussion:
https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/

.../driver-api/driver-model/devres.rst | 1 +
drivers/base/platform.c | 33 +++++++++++++++++++
include/linux/platform_device.h | 4 +++
3 files changed, 38 insertions(+)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index eaaaafc21134..9c75903bce7c 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -326,6 +326,7 @@ IRQ
devm_request_any_context_irq()
devm_request_irq()
devm_request_threaded_irq()
+ devm_platform_request_irq()
devm_irq_alloc_descs()
devm_irq_alloc_desc()
devm_irq_alloc_desc_at()
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index e5d8a0503b4f..d4212d12bf60 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

2020-07-17 18:06:18

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH v4 1/2] drivers: provide devm_platform_request_irq()

> v3 -> v4:
> - The patch v3 sent on May 27 may be lost somewhere in the
> world, so resend it.

Can previous patch review aspects get any more attention?

https://lore.kernel.org/cocci/[email protected]/
https://lkml.org/lkml/2020/5/27/1326

Regards,
Markus