dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/bridge: simplify devm_drm_panel_bridge_add_typed
@ 2021-04-08  2:07 Tian Tao
  2021-04-28 16:19 ` Robert Foss
  0 siblings, 1 reply; 2+ messages in thread
From: Tian Tao @ 2021-04-08  2:07 UTC (permalink / raw)
  To: a.hajda, narmstrong, robert.foss, airlied, daniel
  Cc: Tian Tao, dri-devel, Yicong Yang

Use devm_add_action_or_reset() instead of devres_alloc() and
devres_add(), which works the same. This will simplify the
code. There is no functional changes.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 drivers/gpu/drm/bridge/panel.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c
index c916f4b..e5ddefb 100644
--- a/drivers/gpu/drm/bridge/panel.c
+++ b/drivers/gpu/drm/bridge/panel.c
@@ -250,11 +250,9 @@ void drm_panel_bridge_remove(struct drm_bridge *bridge)
 }
 EXPORT_SYMBOL(drm_panel_bridge_remove);
 
-static void devm_drm_panel_bridge_release(struct device *dev, void *res)
+static void devm_drm_panel_bridge_release(void *bridge)
 {
-	struct drm_bridge **bridge = res;
-
-	drm_panel_bridge_remove(*bridge);
+	drm_panel_bridge_remove(bridge);
 }
 
 /**
@@ -295,20 +293,17 @@ struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
 						   struct drm_panel *panel,
 						   u32 connector_type)
 {
-	struct drm_bridge **ptr, *bridge;
-
-	ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr),
-			   GFP_KERNEL);
-	if (!ptr)
-		return ERR_PTR(-ENOMEM);
+	struct drm_bridge *bridge;
+	int ret;
 
 	bridge = drm_panel_bridge_add_typed(panel, connector_type);
-	if (!IS_ERR(bridge)) {
-		*ptr = bridge;
-		devres_add(dev, ptr);
-	} else {
-		devres_free(ptr);
-	}
+	if (IS_ERR(bridge))
+		return bridge;
+
+	ret = devm_add_action_or_reset(dev, devm_drm_panel_bridge_release,
+				       bridge);
+	if (ret)
+		return ERR_PTR(ret);
 
 	return bridge;
 }
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/bridge: simplify devm_drm_panel_bridge_add_typed
  2021-04-08  2:07 [PATCH] drm/bridge: simplify devm_drm_panel_bridge_add_typed Tian Tao
@ 2021-04-28 16:19 ` Robert Foss
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Foss @ 2021-04-28 16:19 UTC (permalink / raw)
  To: Tian Tao
  Cc: Neil Armstrong, David Airlie, dri-devel, Yicong Yang, Andrzej Hajda


[-- Attachment #1.1: Type: text/plain, Size: 2387 bytes --]

Hey Tian,

Thanks for having a look at cleanup patches.

On Thu, 8 Apr 2021 at 04:06, Tian Tao <tiantao6@hisilicon.com> wrote:

> Use devm_add_action_or_reset() instead of devres_alloc() and
> devres_add(), which works the same. This will simplify the
> code. There is no functional changes.
>
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
> ---
>  drivers/gpu/drm/bridge/panel.c | 27 +++++++++++----------------
>  1 file changed, 11 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/panel.c
> b/drivers/gpu/drm/bridge/panel.c
> index c916f4b..e5ddefb 100644
> --- a/drivers/gpu/drm/bridge/panel.c
> +++ b/drivers/gpu/drm/bridge/panel.c
> @@ -250,11 +250,9 @@ void drm_panel_bridge_remove(struct drm_bridge
> *bridge)
>  }
>  EXPORT_SYMBOL(drm_panel_bridge_remove);
>
> -static void devm_drm_panel_bridge_release(struct device *dev, void *res)
> +static void devm_drm_panel_bridge_release(void *bridge)
>  {
> -       struct drm_bridge **bridge = res;
> -
> -       drm_panel_bridge_remove(*bridge);
> +       drm_panel_bridge_remove(bridge);
>  }
>
>  /**
> @@ -295,20 +293,17 @@ struct drm_bridge
> *devm_drm_panel_bridge_add_typed(struct device *dev,
>                                                    struct drm_panel *panel,
>                                                    u32 connector_type)
>  {
> -       struct drm_bridge **ptr, *bridge;
> -
> -       ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr),
> -                          GFP_KERNEL);
> -       if (!ptr)
> -               return ERR_PTR(-ENOMEM);
> +       struct drm_bridge *bridge;
> +       int ret;
>
>         bridge = drm_panel_bridge_add_typed(panel, connector_type);
> -       if (!IS_ERR(bridge)) {
> -               *ptr = bridge;
> -               devres_add(dev, ptr);
> -       } else {
> -               devres_free(ptr);
> -       }
> +       if (IS_ERR(bridge))
> +               return bridge;
> +
> +       ret = devm_add_action_or_reset(dev, devm_drm_panel_bridge_release,
> +                                      bridge);
> +       if (ret)
> +               return ERR_PTR(ret);
>
>         return bridge;
>  }
>
>
I'm not crazy about this change. In my mind it is harder to read &
understand than the current solution. If anyone else feels otherwise, I'm
open to have my mind changed.


Rob.

[-- Attachment #1.2: Type: text/html, Size: 3292 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-28 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08  2:07 [PATCH] drm/bridge: simplify devm_drm_panel_bridge_add_typed Tian Tao
2021-04-28 16:19 ` Robert Foss

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).