diff mbox series

[3/4] drm/tegra: gr3d: Properly clean up resources

Message ID 20180504133707.22451-3-thierry.reding@gmail.com
State Accepted
Headers show
Series [1/4] drm/tegra: dc: Free syncpoint on errors | expand

Commit Message

Thierry Reding May 4, 2018, 1:37 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

Failure to register the Tegra DRM client would leak the resources. Move
cleanup code to error unwinding gotos to fix that and share the cleanup
code with the other error paths.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/gpu/drm/tegra/gr3d.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Dmitry Osipenko May 4, 2018, 2:16 p.m. UTC | #1
On 04.05.2018 16:37, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Failure to register the Tegra DRM client would leak the resources. Move
> cleanup code to error unwinding gotos to fix that and share the cleanup
> code with the other error paths.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  drivers/gpu/drm/tegra/gr3d.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tegra/gr3d.c b/drivers/gpu/drm/tegra/gr3d.c
> index ce5120683091..e129f1afff33 100644
> --- a/drivers/gpu/drm/tegra/gr3d.c
> +++ b/drivers/gpu/drm/tegra/gr3d.c
> @@ -52,8 +52,8 @@ static int gr3d_init(struct host1x_client *client)
>  
>  	client->syncpts[0] = host1x_syncpt_request(client, flags);
>  	if (!client->syncpts[0]) {
> -		host1x_channel_put(gr3d->channel);
> -		return -ENOMEM;
> +		err = -ENOMEM;
> +		goto put;
>  	}
>  
>  	if (tegra->domain) {
> @@ -65,15 +65,30 @@ static int gr3d_init(struct host1x_client *client)
>  				dev_err(client->dev,
>  					"failed to attach to domain: %d\n",
>  					err);
> -				host1x_syncpt_free(client->syncpts[0]);
> -				host1x_channel_put(gr3d->channel);
>  				iommu_group_put(gr3d->group);
> -				return err;
> +				goto free;
>  			}
>  		}
>  	}
>  
> -	return tegra_drm_register_client(dev->dev_private, drm);
> +	err = tegra_drm_register_client(dev->dev_private, drm);
> +	if (err < 0) {
> +		dev_err(client->dev, "failed to register client: %d\n", err);
> +		goto detach;
> +	}
> +
> +	return 0;
> +
> +detach:
> +	if (gr3d->group) {
> +		iommu_detach_group(tegra->domain, gr3d->group);
> +		iommu_group_put(gr3d->group);
> +	}
> +free:
> +	host1x_syncpt_free(client->syncpts[0]);
> +put:
> +	host1x_channel_put(gr3d->channel);
> +	return err;
>  }
>  
>  static int gr3d_exit(struct host1x_client *client)
> 

Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tegra/gr3d.c b/drivers/gpu/drm/tegra/gr3d.c
index ce5120683091..e129f1afff33 100644
--- a/drivers/gpu/drm/tegra/gr3d.c
+++ b/drivers/gpu/drm/tegra/gr3d.c
@@ -52,8 +52,8 @@  static int gr3d_init(struct host1x_client *client)
 
 	client->syncpts[0] = host1x_syncpt_request(client, flags);
 	if (!client->syncpts[0]) {
-		host1x_channel_put(gr3d->channel);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto put;
 	}
 
 	if (tegra->domain) {
@@ -65,15 +65,30 @@  static int gr3d_init(struct host1x_client *client)
 				dev_err(client->dev,
 					"failed to attach to domain: %d\n",
 					err);
-				host1x_syncpt_free(client->syncpts[0]);
-				host1x_channel_put(gr3d->channel);
 				iommu_group_put(gr3d->group);
-				return err;
+				goto free;
 			}
 		}
 	}
 
-	return tegra_drm_register_client(dev->dev_private, drm);
+	err = tegra_drm_register_client(dev->dev_private, drm);
+	if (err < 0) {
+		dev_err(client->dev, "failed to register client: %d\n", err);
+		goto detach;
+	}
+
+	return 0;
+
+detach:
+	if (gr3d->group) {
+		iommu_detach_group(tegra->domain, gr3d->group);
+		iommu_group_put(gr3d->group);
+	}
+free:
+	host1x_syncpt_free(client->syncpts[0]);
+put:
+	host1x_channel_put(gr3d->channel);
+	return err;
 }
 
 static int gr3d_exit(struct host1x_client *client)