All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: linux-tegra@vger.kernel.org, Dmitry Osipenko <digetx@gmail.com>,
	dri-devel@lists.freedesktop.org
Subject: [PATCH 3/4] drm/tegra: gr3d: Properly clean up resources
Date: Fri,  4 May 2018 15:37:06 +0200	[thread overview]
Message-ID: <20180504133707.22451-3-thierry.reding@gmail.com> (raw)
In-Reply-To: <20180504133707.22451-1-thierry.reding@gmail.com>

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

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

  parent reply	other threads:[~2018-05-04 13:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-04 13:37 [PATCH 1/4] drm/tegra: dc: Free syncpoint on errors Thierry Reding
2018-05-04 13:37 ` [PATCH 2/4] drm/tegra: gr2d: Properly clean up resources Thierry Reding
2018-05-04 14:16   ` Dmitry Osipenko
2018-05-07 20:57   ` Dmitry Osipenko
2018-05-04 13:37 ` Thierry Reding [this message]
2018-05-04 14:16   ` [PATCH 3/4] drm/tegra: gr3d: " Dmitry Osipenko
2018-05-04 13:37 ` [PATCH 4/4] drm/tegra: Refactor IOMMU attach/detach Thierry Reding
2018-05-04 14:23   ` Dmitry Osipenko
2018-05-04 15:10     ` Thierry Reding
2018-05-04 15:17       ` Dmitry Osipenko
2018-05-04 15:25         ` Thierry Reding
2018-05-10 23:42   ` Dmitry Osipenko
2018-05-04 14:14 ` [PATCH 1/4] drm/tegra: dc: Free syncpoint on errors Dmitry Osipenko
2018-05-04 15:16 ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180504133707.22451-3-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=digetx@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-tegra@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.