2020-12-02 08:50:09

by Tian Tao

[permalink] [raw]
Subject: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq

Add new api devm_drm_irq_install() to register interrupts,
no need to call drm_irq_uninstall() when the drm module is removed.

Signed-off-by: Tian Tao <[email protected]>
---
drivers/gpu/drm/drm_irq.c | 35 +++++++++++++++++++++++++++++++++++
include/drm/drm_irq.h | 2 +-
2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 09d6e9e..b363dec 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -214,6 +214,41 @@ int drm_irq_uninstall(struct drm_device *dev)
}
EXPORT_SYMBOL(drm_irq_uninstall);

+static void devm_drm_irq_uninstall(void *data)
+{
+ drm_irq_uninstall(data);
+}
+
+/**
+ * devm_drm_irq_install - install IRQ handler
+ * @dev: DRM device
+ * @irq: IRQ number to install the handler for
+ *
+ * devm_drm_irq_install is a help function of drm_irq_install.
+ *
+ * if the driver uses devm_drm_irq_install, there is no need
+ * to call drm_irq_uninstall when the drm module get unloaded,
+ * as this will done automagically.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int devm_drm_irq_install(struct drm_device *dev, int irq)
+{
+ int ret;
+
+ ret = drm_irq_install(dev, irq);
+ if (ret)
+ return ret;
+
+ ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
+ if (ret)
+ devm_drm_irq_uninstall(dev);
+
+ return ret;
+}
+EXPORT_SYMBOL(devm_drm_irq_install);
+
#if IS_ENABLED(CONFIG_DRM_LEGACY)
int drm_legacy_irq_control(struct drm_device *dev, void *data,
struct drm_file *file_priv)
diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
index d77f6e6..631b22f 100644
--- a/include/drm/drm_irq.h
+++ b/include/drm/drm_irq.h
@@ -28,5 +28,5 @@ struct drm_device;

int drm_irq_install(struct drm_device *dev, int irq);
int drm_irq_uninstall(struct drm_device *dev);
-
+int devm_drm_irq_install(struct drm_device *dev, int irq);
#endif
--
2.7.4


2020-12-02 09:04:38

by Thomas Zimmermann

[permalink] [raw]
Subject: Re: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq

Hi

Am 02.12.20 um 09:47 schrieb Tian Tao:
> Add new api devm_drm_irq_install() to register interrupts,
> no need to call drm_irq_uninstall() when the drm module is removed.
>
> Signed-off-by: Tian Tao <[email protected]>
> ---
> drivers/gpu/drm/drm_irq.c | 35 +++++++++++++++++++++++++++++++++++
> include/drm/drm_irq.h | 2 +-
> 2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 09d6e9e..b363dec 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -214,6 +214,41 @@ int drm_irq_uninstall(struct drm_device *dev)
> }
> EXPORT_SYMBOL(drm_irq_uninstall);
>
> +static void devm_drm_irq_uninstall(void *data)
> +{
> + drm_irq_uninstall(data);
> +}
> +
> +/**
> + * devm_drm_irq_install - install IRQ handler
> + * @dev: DRM device
> + * @irq: IRQ number to install the handler for
> + *
> + * devm_drm_irq_install is a help function of drm_irq_install.
> + *
> + * if the driver uses devm_drm_irq_install, there is no need
> + * to call drm_irq_uninstall when the drm module get unloaded,
> + * as this will done automagically.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int devm_drm_irq_install(struct drm_device *dev, int irq)
> +{
> + int ret;
> +
> + ret = drm_irq_install(dev, irq);
> + if (ret)
> + return ret;
> +
> + ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
> + if (ret)
> + devm_drm_irq_uninstall(dev);

If anything went wrong, devm_add_action_or_reset() will have already
cleaned up for you. [1] So just return the result of
devm_add_action_or_reset().

Best regards
Thomas

[1]
https://elixir.bootlin.com/linux/latest/source/include/linux/device.h#L255

> +
> + return ret;
> +}
> +EXPORT_SYMBOL(devm_drm_irq_install);
> +
> #if IS_ENABLED(CONFIG_DRM_LEGACY)
> int drm_legacy_irq_control(struct drm_device *dev, void *data,
> struct drm_file *file_priv)
> diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
> index d77f6e6..631b22f 100644
> --- a/include/drm/drm_irq.h
> +++ b/include/drm/drm_irq.h
> @@ -28,5 +28,5 @@ struct drm_device;
>
> int drm_irq_install(struct drm_device *dev, int irq);
> int drm_irq_uninstall(struct drm_device *dev);
> -
> +int devm_drm_irq_install(struct drm_device *dev, int irq);
> #endif
>

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


Attachments:
OpenPGP_signature (855.00 B)
OpenPGP digital signature

2020-12-03 20:12:37

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq

Hi Tian.

On Wed, Dec 02, 2020 at 04:47:14PM +0800, Tian Tao wrote:
> Add new api devm_drm_irq_install() to register interrupts,
> no need to call drm_irq_uninstall() when the drm module is removed.
>
> Signed-off-by: Tian Tao <[email protected]>

Just a few details to fix.

Sam

> ---
> drivers/gpu/drm/drm_irq.c | 35 +++++++++++++++++++++++++++++++++++
> include/drm/drm_irq.h | 2 +-
> 2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 09d6e9e..b363dec 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -214,6 +214,41 @@ int drm_irq_uninstall(struct drm_device *dev)
> }
> EXPORT_SYMBOL(drm_irq_uninstall);
>
> +static void devm_drm_irq_uninstall(void *data)
> +{
> + drm_irq_uninstall(data);
> +}
> +
> +/**
> + * devm_drm_irq_install - install IRQ handler
> + * @dev: DRM device
> + * @irq: IRQ number to install the handler for
> + *
> + * devm_drm_irq_install is a help function of drm_irq_install.
Drop the extra space after "is a"
> + *
> + * if the driver uses devm_drm_irq_install, there is no need
Start with capital "I" in If
> + * to call drm_irq_uninstall when the drm module get unloaded,
> + * as this will done automagically.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int devm_drm_irq_install(struct drm_device *dev, int irq)
> +{
> + int ret;
> +
> + ret = drm_irq_install(dev, irq);
> + if (ret)
> + return ret;
> +
> + ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
> + if (ret)
> + devm_drm_irq_uninstall(dev);
devm_add_action_or_reset() will call devm_drm_irq_uninstall() if ret is
!= 0. See include/device.h.

I guess that is the "_or_reset" part of the name that can tell us that.
So you can drop the if condition as it just will cause the code to call
drm_irq_uninstall() twice.

> +
> + return ret;
> +}
> +EXPORT_SYMBOL(devm_drm_irq_install);
> +
> #if IS_ENABLED(CONFIG_DRM_LEGACY)
> int drm_legacy_irq_control(struct drm_device *dev, void *data,
> struct drm_file *file_priv)
> diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
> index d77f6e6..631b22f 100644
> --- a/include/drm/drm_irq.h
> +++ b/include/drm/drm_irq.h
> @@ -28,5 +28,5 @@ struct drm_device;
>
> int drm_irq_install(struct drm_device *dev, int irq);
> int drm_irq_uninstall(struct drm_device *dev);
> -
> +int devm_drm_irq_install(struct drm_device *dev, int irq);
> #endif
> --
> 2.7.4
>
> _______________________________________________
> dri-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

2020-12-03 21:36:24

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq

Hi Tian,

> > + ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
> > + if (ret)
> > + devm_drm_irq_uninstall(dev);
> devm_add_action_or_reset() will call devm_drm_irq_uninstall() if ret is
> != 0. See include/device.h.
>
> I guess that is the "_or_reset" part of the name that can tell us that.
> So you can drop the if condition as it just will cause the code to call
> drm_irq_uninstall() twice.

Noticed this was fixed in v2 - so all is fine here.

Sam