From patchwork Fri May 4 13:37:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10380463 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 CA5F86037D for ; Fri, 4 May 2018 13:37:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9E6029453 for ; Fri, 4 May 2018 13:37:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEC9A29462; Fri, 4 May 2018 13:37:16 +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 417E229464 for ; Fri, 4 May 2018 13:37:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CFAAD6E893; Fri, 4 May 2018 13:37:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id E95586E893 for ; Fri, 4 May 2018 13:37:12 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id f2-v6so9316605wrm.3 for ; Fri, 04 May 2018 06:37:12 -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=AaztEHFoua1YK5uEuI2uMS3uuUXQ2mvEFJX9k2N5OSI=; b=YsSWKu7VjuSz7/CWmdt8pRjs952IM05piVPgt8kVBF6wThrK/kSuwHFZJPDI1dsubd CIHKk37d0njrwnKJWHjVIpqglhKOthbfiMiqVzKxgrhNvm5ZuxVqXD0YDdI4mQU33G33 olnyrP1MwkD/qtP6W8oX5EeaNRvXykJAUrukQPIvTHYuZ08jemqihzSfh9+tJOOYkoLU yFfzC4gtHPNKMcP388tMxJ2KvSngmzww79GmQTtbjLjTiNEDt3GiwcN/jXmMOUY7aIMk jk58RmqbseoP/M3ZqYewpEbdjH0Eo1x+K0+z3osYWADx+dqcxCqO9nmyQbPaBEX7PBgO RIqQ== 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=AaztEHFoua1YK5uEuI2uMS3uuUXQ2mvEFJX9k2N5OSI=; b=ZPUtqE72p8sJKspZKp+zYUmq5nXXjYqkC/6PnuIuS/+Y5m8eb7jUIfeH5QIQYpJ22d xvHEOALpS1/jvMCxQEJ/xgpaAtUm9mQG+nQYBFB2flswd+K4lEK61z08kBaabAANSn0T mbTMfFDJ5fykxKmGgFYSV2nUyEwh35luYOU5vTv4oQyVMvA28HdVqwnBW5tu502YQv6b ezuQzjEkST+O2cbnctkTnARF2ZN0ZL75FoA5nCf5yDzY/H5WesXviHxIXjrVjOkuEnu7 AoX/tqfVwUlmw6lvBCKwpCfKLhMbd2/fkqr4iurT4H8OESjrotIWNDpeDKv3Ivy7+vUN HgMg== X-Gm-Message-State: ALQs6tDnwB5f8o55iROmupXPdyjDsX2kmgaVCGL+ZN/494AhKPIFUwze 7rTwnT2CYFVCjcbM2P5+k35kGQ== X-Google-Smtp-Source: AB8JxZpiNSTfprMP/6A7bJOL0GE4n5ORsVf4GI0izOX3YfuGQzyVkpO4iRsk/qcFzUI+JbY7HMei2A== X-Received: by 2002:adf:d0cb:: with SMTP id z11-v6mr19768234wrh.281.1525441031410; Fri, 04 May 2018 06:37:11 -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 109-v6sm16708152wra.32.2018.05.04.06.37.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 May 2018 06:37:10 -0700 (PDT) From: Thierry Reding To: Thierry Reding Subject: [PATCH 2/4] drm/tegra: gr2d: Properly clean up resources Date: Fri, 4 May 2018 15:37:05 +0200 Message-Id: <20180504133707.22451-2-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/gr2d.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/tegra/gr2d.c b/drivers/gpu/drm/tegra/gr2d.c index 8eb530a85dd0..0b42e99da8ad 100644 --- a/drivers/gpu/drm/tegra/gr2d.c +++ b/drivers/gpu/drm/tegra/gr2d.c @@ -42,8 +42,9 @@ static int gr2d_init(struct host1x_client *client) client->syncpts[0] = host1x_syncpt_request(client, flags); if (!client->syncpts[0]) { - host1x_channel_put(gr2d->channel); - return -ENOMEM; + err = -ENOMEM; + dev_err(client->dev, "failed to request syncpoint: %d\n", err); + goto put; } if (tegra->domain) { @@ -55,15 +56,30 @@ static int gr2d_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(gr2d->channel); iommu_group_put(gr2d->group); - return err; + goto free; } } } - return tegra_drm_register_client(tegra, drm); + err = tegra_drm_register_client(tegra, drm); + if (err < 0) { + dev_err(client->dev, "failed to register client: %d\n", err); + goto detach; + } + + return 0; + +detach: + if (gr2d->group) { + iommu_detach_group(tegra->domain, gr2d->group); + iommu_group_put(gr2d->group); + } +free: + host1x_syncpt_free(client->syncpts[0]); +put: + host1x_channel_put(gr2d->channel); + return err; } static int gr2d_exit(struct host1x_client *client)