linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: Release resources with a safer function
@ 2016-10-02  6:01 Christophe JAILLET
  2016-10-03  7:18 ` Ville Syrjälä
  2016-10-05 13:17 ` Daniel Vetter
  0 siblings, 2 replies; 5+ messages in thread
From: Christophe JAILLET @ 2016-10-02  6:01 UTC (permalink / raw)
  To: airlied; +Cc: dri-devel, linux-kernel, kernel-janitors, Christophe JAILLET

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

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

* Re: [PATCH] drm: Release resources with a safer function
  2016-10-02  6:01 [PATCH] drm: Release resources with a safer function Christophe JAILLET
@ 2016-10-03  7:18 ` Ville Syrjälä
  2016-10-05 13:17 ` Daniel Vetter
  1 sibling, 0 replies; 5+ messages in thread
From: Ville Syrjälä @ 2016-10-03  7:18 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: airlied, kernel-janitors, linux-kernel, dri-devel

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

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

* Re: [PATCH] drm: Release resources with a safer function
  2016-10-02  6:01 [PATCH] drm: Release resources with a safer function Christophe JAILLET
  2016-10-03  7:18 ` Ville Syrjälä
@ 2016-10-05 13:17 ` Daniel Vetter
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Vetter @ 2016-10-05 13:17 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: airlied, kernel-janitors, linux-kernel, dri-devel

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

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

* Re: [PATCH] drm: Release resources with a safer function
  2016-10-07  7:27 Christophe JAILLET
@ 2016-10-10  9:22 ` Daniel Vetter
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Vetter @ 2016-10-10  9:22 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: airlied, daniel, dri-devel, linux-kernel, kernel-janitors

On Fri, Oct 07, 2016 at 09:27:41AM +0200, Christophe JAILLET wrote:
> We should use 'ida_simple_remove()' instead of 'ida_remove()' when freeing
> resources allocated with 'ida_simple_get()'.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied to drm-misc, thanks.
-Daniel

> ---
>  drivers/gpu/drm/drm_connector.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index 2e7430283043..2db7fb510b6c 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -341,11 +341,11 @@ void drm_connector_cleanup(struct drm_connector *connector)
>  	list_for_each_entry_safe(mode, t, &connector->modes, head)
>  		drm_mode_remove(connector, mode);
>  
> -	ida_remove(&drm_connector_enum_list[connector->connector_type].ida,
> -		   connector->connector_type_id);
> +	ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
> +			  connector->connector_type_id);
>  
> -	ida_remove(&dev->mode_config.connector_ida,
> -		   connector->index);
> +	ida_simple_remove(&dev->mode_config.connector_ida,
> +			  connector->index);
>  
>  	kfree(connector->display_info.bus_formats);
>  	drm_mode_object_unregister(dev, &connector->base);
> -- 
> 2.7.4
> 

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

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

* [PATCH] drm: Release resources with a safer function
@ 2016-10-07  7:27 Christophe JAILLET
  2016-10-10  9:22 ` Daniel Vetter
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe JAILLET @ 2016-10-07  7:27 UTC (permalink / raw)
  To: airlied, daniel
  Cc: dri-devel, linux-kernel, kernel-janitors, Christophe JAILLET

We should use 'ida_simple_remove()' instead of 'ida_remove()' when freeing
resources allocated with 'ida_simple_get()'.

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

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 2e7430283043..2db7fb510b6c 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -341,11 +341,11 @@ void drm_connector_cleanup(struct drm_connector *connector)
 	list_for_each_entry_safe(mode, t, &connector->modes, head)
 		drm_mode_remove(connector, mode);
 
-	ida_remove(&drm_connector_enum_list[connector->connector_type].ida,
-		   connector->connector_type_id);
+	ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
+			  connector->connector_type_id);
 
-	ida_remove(&dev->mode_config.connector_ida,
-		   connector->index);
+	ida_simple_remove(&dev->mode_config.connector_ida,
+			  connector->index);
 
 	kfree(connector->display_info.bus_formats);
 	drm_mode_object_unregister(dev, &connector->base);
-- 
2.7.4

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

end of thread, other threads:[~2016-10-10  9:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-02  6:01 [PATCH] drm: Release resources with a safer function Christophe JAILLET
2016-10-03  7:18 ` Ville Syrjälä
2016-10-05 13:17 ` Daniel Vetter
2016-10-07  7:27 Christophe JAILLET
2016-10-10  9:22 ` Daniel Vetter

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