From patchwork Tue Sep 1 15:08:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 310477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DCF0C433E2 for ; Tue, 1 Sep 2020 15:37:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0038621534 for ; Tue, 1 Sep 2020 15:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974662; bh=RirBJnGWSx+8SfHSLXWiXEKeGrvmh1KYf16yHJ8Ti0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=v+F8J1Pl0n+31dh35A397JGCua4BpoVKHUxHflhzFdzTc9UCHrARgMAKqPyr+7xTk 5QJWB5XJV1l5LAknTq1VjpKFbOqk/hcOnoVCUCkJcn493XqcfpeQZwBE3QB+n/GYWQ hJqotSB6ipIUYnLx7Ph6WCuc4acQnbIt+Ta6QpQc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731348AbgIAPhk (ORCPT ); Tue, 1 Sep 2020 11:37:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:45896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731158AbgIAPhj (ORCPT ); Tue, 1 Sep 2020 11:37:39 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4C88820E65; Tue, 1 Sep 2020 15:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974658; bh=RirBJnGWSx+8SfHSLXWiXEKeGrvmh1KYf16yHJ8Ti0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0iVTI0T25Fc7gDTgJqkOwjGwBHvo5IjqtGPJygiOyEfPKUSAuzJuHqi7r1UQeZ3Kp qbq63waxvgl1DtVe6yDvPYrIscbnMf1yJuKXgx5EncMj+0K8fm0UMnsOo8h3nsE7ld vojZ9z3iUHrDGDd11YMsu8G/A4t40sxCI9MfFYOs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Osipenko , Thierry Reding , Sasha Levin Subject: [PATCH 5.8 045/255] gpu: host1x: Put gathers BO on pinning error Date: Tue, 1 Sep 2020 17:08:21 +0200 Message-Id: <20200901151002.910083150@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901151000.800754757@linuxfoundation.org> References: <20200901151000.800754757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dmitry Osipenko [ Upstream commit fd323e9ef0a19112c0c85b85afc4848c0518174b ] This patch fixes gather's BO refcounting on a pinning error. Gather's BO won't be leaked now if something goes wrong. Signed-off-by: Dmitry Osipenko Signed-off-by: Thierry Reding Signed-off-by: Sasha Levin --- drivers/gpu/host1x/job.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c index a10643aa89aa5..2ac5a99406d98 100644 --- a/drivers/gpu/host1x/job.c +++ b/drivers/gpu/host1x/job.c @@ -102,6 +102,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) { struct host1x_client *client = job->client; struct device *dev = client->dev; + struct host1x_job_gather *g; struct iommu_domain *domain; unsigned int i; int err; @@ -184,7 +185,6 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) } for (i = 0; i < job->num_gathers; i++) { - struct host1x_job_gather *g = &job->gathers[i]; size_t gather_size = 0; struct scatterlist *sg; struct sg_table *sgt; @@ -194,6 +194,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) dma_addr_t *phys; unsigned int j; + g = &job->gathers[i]; g->bo = host1x_bo_get(g->bo); if (!g->bo) { err = -EINVAL; @@ -213,7 +214,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) sgt = host1x_bo_pin(host->dev, g->bo, phys); if (IS_ERR(sgt)) { err = PTR_ERR(sgt); - goto unpin; + goto put; } if (!IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL) && host->domain) { @@ -226,7 +227,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) host->iova_end >> shift, true); if (!alloc) { err = -ENOMEM; - goto unpin; + goto put; } err = iommu_map_sg(host->domain, @@ -235,7 +236,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) if (err == 0) { __free_iova(&host->iova, alloc); err = -EINVAL; - goto unpin; + goto put; } job->unpins[job->num_unpins].size = gather_size; @@ -245,7 +246,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) DMA_TO_DEVICE); if (!err) { err = -ENOMEM; - goto unpin; + goto put; } job->unpins[job->num_unpins].dir = DMA_TO_DEVICE; @@ -263,6 +264,8 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) return 0; +put: + host1x_bo_put(g->bo); unpin: host1x_job_unpin(job); return err;