Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1494532 > unrolled thread

[PATCH] drm: Release resources with a safer function

Started byChristophe JAILLET <christophe.jaillet@wanadoo.fr>
First post2016-10-02 08:10 +0200
Last post2016-10-05 15:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] drm: Release resources with a safer function Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-10-02 08:10 +0200
    Re: [PATCH] drm: Release resources with a safer function Ville Syrjälä <ville.syrjala@linux.intel.com> - 2016-10-03 09:20 +0200
    Re: [PATCH] drm: Release resources with a safer function Daniel Vetter <daniel@ffwll.ch> - 2016-10-05 15:20 +0200

#1494532 — [PATCH] drm: Release resources with a safer function

FromChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2016-10-02 08:10 +0200
Subject[PATCH] drm: Release resources with a safer function
Message-ID<snI8h-2YG-3@gated-at.bofh.it>
We should use 'ida_simple_remove()' instead of 'ida_remove()' when freeing
resources allocated with 'ida_simple_get()'.

This as been spotted with the following coccinelle script which tries to
detect missing 'ida_simple_remove()' call in error handling paths.

///////////////
@@
expression x;
identifier l;
@@

*   x = ida_simple_get(...);
    ...
    if (...) {
    ...
    }
    ...
    if (...) {
       ...
       goto l;
    }
    ...
*   l: ... when != ida_simple_remove(...);

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/gpu/drm/drm_connector.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 26bb78c76481..2e7430283043 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -250,10 +250,10 @@ int drm_connector_init(struct drm_device *dev,
 	connector->debugfs_entry = NULL;
 out_put_type_id:
 	if (ret)
-		ida_remove(connector_ida, connector->connector_type_id);
+		ida_simple_remove(connector_ida, connector->connector_type_id);
 out_put_id:
 	if (ret)
-		ida_remove(&config->connector_ida, connector->index);
+		ida_simple_remove(&config->connector_ida, connector->index);
 out_put:
 	if (ret)
 		drm_mode_object_unregister(dev, &connector->base);
-- 
2.7.4

[toc] | [next] | [standalone]


#1494716

FromVille Syrjälä <ville.syrjala@linux.intel.com>
Date2016-10-03 09:20 +0200
Message-ID<so5HA-Yv-9@gated-at.bofh.it>
In reply to#1494532
On Sun, Oct 02, 2016 at 08:01:22AM +0200, Christophe JAILLET wrote:
> We should use 'ida_simple_remove()' instead of 'ida_remove()' when freeing
> resources allocated with 'ida_simple_get()'.

Should fix drm_connector_cleanup() then as well...

> 
> This as been spotted with the following coccinelle script which tries to
> detect missing 'ida_simple_remove()' call in error handling paths.
> 
> ///////////////
> @@
> expression x;
> identifier l;
> @@
> 
> *   x = ida_simple_get(...);
>     ...
>     if (...) {
>     ...
>     }
>     ...
>     if (...) {
>        ...
>        goto l;
>     }
>     ...
> *   l: ... when != ida_simple_remove(...);
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/gpu/drm/drm_connector.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index 26bb78c76481..2e7430283043 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -250,10 +250,10 @@ int drm_connector_init(struct drm_device *dev,
>  	connector->debugfs_entry = NULL;
>  out_put_type_id:
>  	if (ret)
> -		ida_remove(connector_ida, connector->connector_type_id);
> +		ida_simple_remove(connector_ida, connector->connector_type_id);
>  out_put_id:
>  	if (ret)
> -		ida_remove(&config->connector_ida, connector->index);
> +		ida_simple_remove(&config->connector_ida, connector->index);
>  out_put:
>  	if (ret)
>  		drm_mode_object_unregister(dev, &connector->base);
> -- 
> 2.7.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel OTC

[toc] | [prev] | [next] | [standalone]


#1495865

FromDaniel Vetter <daniel@ffwll.ch>
Date2016-10-05 15:20 +0200
Message-ID<soUh3-1sa-1@gated-at.bofh.it>
In reply to#1494532
On Sun, Oct 02, 2016 at 08:01:22AM +0200, Christophe JAILLET wrote:
> We should use 'ida_simple_remove()' instead of 'ida_remove()' when freeing
> resources allocated with 'ida_simple_get()'.
> 
> This as been spotted with the following coccinelle script which tries to
> detect missing 'ida_simple_remove()' call in error handling paths.
> 
> ///////////////
> @@
> expression x;
> identifier l;
> @@
> 
> *   x = ida_simple_get(...);
>     ...
>     if (...) {
>     ...
>     }
>     ...
>     if (...) {
>        ...
>        goto l;
>     }
>     ...
> *   l: ... when != ida_simple_remove(...);
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

kerneldoc for ida_simple_get/remove is rather sparse, would be great to
improve that a bit. Merged this one to drm-misc now, follow-up patch for
the place Ville spotted would be great too.
-Daniel

> ---
>  drivers/gpu/drm/drm_connector.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index 26bb78c76481..2e7430283043 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -250,10 +250,10 @@ int drm_connector_init(struct drm_device *dev,
>  	connector->debugfs_entry = NULL;
>  out_put_type_id:
>  	if (ret)
> -		ida_remove(connector_ida, connector->connector_type_id);
> +		ida_simple_remove(connector_ida, connector->connector_type_id);
>  out_put_id:
>  	if (ret)
> -		ida_remove(&config->connector_ida, connector->index);
> +		ida_simple_remove(&config->connector_ida, connector->index);
>  out_put:
>  	if (ret)
>  		drm_mode_object_unregister(dev, &connector->base);
> -- 
> 2.7.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web