From patchwork Fri May 4 13:37:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10380465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0507A6038F for ; Fri, 4 May 2018 13:37:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E701D293FD for ; Fri, 4 May 2018 13:37:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBC7129468; Fri, 4 May 2018 13:37:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9CEC629462 for ; Fri, 4 May 2018 13:37:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 36BE46E897; Fri, 4 May 2018 13:37:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id DCFC76E897 for ; Fri, 4 May 2018 13:37:14 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id p18-v6so21159764wrm.1 for ; Fri, 04 May 2018 06:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BuCvP1R1yibhEqaAg25/eRS2ue5NPqqMfGjSb/GyIYY=; b=TKpG/SKJf5/NzkpcwOYNKfBpSJXeayjf2NUJ1fhg/MRfn5YXs+gAWfHs/0P3tyokEu bXIzGWrYnLocICKTljELQwbDVag76OqKjGDUdJmm7mFtM92Phazpe1nsehtiVUXsiwBy Gwzu0q9Vd4UV/0aFHe+4LV+4C0XUAIp7TmQSJwCfSKZQzklCvE12KU/kDAS1QutyGb1Y Dvr6C4Fm0RJ49xMYrp4x8oTPCwcw1pPPOyLk1WC5SA+ynFMyIQBfV09jxciMwHxjosYd 4F36oq0lvCR431vh+GoCYQRBUmRmCXwqzEseAD4LMCwD3OYV9ujphbbkSXRolu3BS337 rYUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BuCvP1R1yibhEqaAg25/eRS2ue5NPqqMfGjSb/GyIYY=; b=EYB1ssGSUh7wzRjxTzyl7iezDgYdIgDfvcnyyMnprKFQEDfb5EDIO0JTw1d7z+iQ8i hMiiMF/Zrb18zy9d1jJCMC1X3JFkET50y2U/0qDIYQtwFfxDXty4rSX5qXZ6k00mad1B oX/ExWOrY4W/iV6RXFCTeKLrtpD05zrkdXn/+i3+m43jXRCR58HK6qrA0IZRDsy64klE x6xUJMk5nqqDICPUHRIQUYF67s/yW26iNALC94rBRg5yFQLmbrpndHzmpGULOLKbWu1j gX82Bzf4cVnEdpT4D3tKEpfspQDo+oYmPizsMmdwSK2raw13zi9isKPzMq6c8KoZz744 0xnw== X-Gm-Message-State: ALQs6tAxivG5fYxl00XTraBRtAnK0pC+scUPQ3saTzcnlYaXOfilYHK9 hxCb6RywvZX1/InVMJAMDi1WBg== X-Google-Smtp-Source: AB8JxZqo7tAVRwQYddzVP+mUzceLX3nxlXiNyeWoENLWZdBDMeB+VCd+AUHiqmJmD7ASGMrm23FVkA== X-Received: by 2002:adf:83a2:: with SMTP id 31-v6mr21503042wre.19.1525441033247; Fri, 04 May 2018 06:37:13 -0700 (PDT) Received: from localhost (p200300E41F041C0032947E635CB49D15.dip0.t-ipconnect.de. [2003:e4:1f04:1c00:3294:7e63:5cb4:9d15]) by smtp.gmail.com with ESMTPSA id y42-v6sm21952682wry.21.2018.05.04.06.37.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 May 2018 06:37:12 -0700 (PDT) From: Thierry Reding To: Thierry Reding Subject: [PATCH 3/4] drm/tegra: gr3d: Properly clean up resources Date: Fri, 4 May 2018 15:37:06 +0200 Message-Id: <20180504133707.22451-3-thierry.reding@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180504133707.22451-1-thierry.reding@gmail.com> References: <20180504133707.22451-1-thierry.reding@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-tegra@vger.kernel.org, Dmitry Osipenko , dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding 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 Reviewed-by: Dmitry Osipenko --- 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)