From patchwork Wed Mar 14 15:41:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 131616 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp1025834ljb; Wed, 14 Mar 2018 08:42:19 -0700 (PDT) X-Google-Smtp-Source: AG47ELsr8gJBtCeZFlFFmwQgCvgn2oevbO4J9WxAc0KCl7xRrUAYoiTa5XUsvz+X5ln+1Bl9tNmU X-Received: by 10.99.168.68 with SMTP id i4mr1121989pgp.420.1521042139200; Wed, 14 Mar 2018 08:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521042139; cv=none; d=google.com; s=arc-20160816; b=plFyW6dx3179Qm2kL88SASVkhmPpxqD/Ut40G5ToZQ/bfd2Be0mYWSh1Q2SKiJUa4N rBANIbPFGYEJvqRLLi+EkSfeOXvWzXWLCb8AGkcguAozqULFLQACfX5he7NsEn08dsVH tHCFWqfYN4nIekilRuPpEgN1zoCnLn2ZcKxDRU5h2jJSPXcfdnY+CooZQG08kQRqZdLh 1v/Pj08eLHjw/AV714/3eTIWYtyNPORbYjVvAan/AgMAsz7f739Do1pTGrZsJwiuion8 2I5wiMxiQEnmAbv+C0ii8zCq/mcd7qNv7HJ8iFH3trbkfBFmNLLYKaEKIZh0UZp01nUZ qzXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=SboZBW7U4apGuLeqLtJlWm5VEN3F4j//MPQG3m666IU=; b=v6cdjclaw/DFWyFmsrUj11fbiDL17r4JJdZXdZh+EHyIpBALElsGzNdGMhLZ2yw5JA 7kVuJPKAocW6iwQNajKo3szjBXOHi6Fiwx3Z4OSdTPOtRZwksrgekI+6kT9YwCMm9OpO hp21GeHLjoSmknrxeWLH7AC3kwwORoL6UcP31Gq5aGqZ2VSUHZqVtMN/ukFsB/MbIn6b 43ZIBKRLXymLsITrJ1IPNFtb03SlJbBU01/ojveuGFYlbre2fc8E0h04VOqfnwo+oAiZ CyU4ov/YxjR9FknIdD5c6rfplWbX0WyVFjpNV8s0uXimTvcUTfoCOQ9NM0s9+NzmAXEm E0Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=TJV1E2DF; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16-v6si2125241plp.87.2018.03.14.08.42.17; Wed, 14 Mar 2018 08:42:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=TJV1E2DF; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751478AbeCNPmP (ORCPT + 5 others); Wed, 14 Mar 2018 11:42:15 -0400 Received: from fllnx209.ext.ti.com ([198.47.19.16]:15591 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751350AbeCNPmP (ORCPT ); Wed, 14 Mar 2018 11:42:15 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w2EFfdr9003919; Wed, 14 Mar 2018 10:41:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1521042099; bh=Xx7bnWU1lIsChE9fw5rJ/EBTiWItSLRycwfPj2j8uD0=; h=From:To:CC:Subject:Date; b=TJV1E2DFn427Rx1Yy2Ht0P9fQr1K8MSB4ujpIrYewqQdXa/WUZuKIJ3fWVUw+ggZR S2bTaifez7pM3BdU6tTkBlMAg7mdN0jRoohitXiHe01TSyHhqgHs/u/5J+MR7ibAQN UuRM0CV+x/2sc+lSK/lCZVkiw5GlVrMltDe2h8j4= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w2EFfd84007062; Wed, 14 Mar 2018 10:41:39 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Wed, 14 Mar 2018 10:41:39 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Wed, 14 Mar 2018 10:41:39 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w2EFfd4R030469; Wed, 14 Mar 2018 10:41:39 -0500 Received: from localhost (irmo.dhcp.ti.com [128.247.58.153]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id w2EFfcx28829; Wed, 14 Mar 2018 10:41:38 -0500 (CDT) From: Suman Anna To: Laurent Pinchart , Mauro Carvalho Chehab CC: Pavel Machek , Sakari Ailus , Tony Lindgren , Suman Anna , , , Subject: [PATCH v2] media: omap3isp: fix unbalanced dma_iommu_mapping Date: Wed, 14 Mar 2018 10:41:36 -0500 Message-ID: <20180314154136.16468-1-s-anna@ti.com> X-Mailer: git-send-email 2.16.2 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org The OMAP3 ISP driver manages its MMU mappings through the IOMMU-aware ARM DMA backend. The current code creates a dma_iommu_mapping and attaches this to the ISP device, but never detaches the mapping in either the probe failure paths or the driver remove path resulting in an unbalanced mapping refcount and a memory leak. Fix this properly. Reported-by: Pavel Machek Signed-off-by: Suman Anna Acked-by: Sakari Ailus --- v2 Changes: - Dropped the error_attach label, and returned directly from the first error path (comments from Sakari) - Added Sakari's Acked-by v1: https://patchwork.kernel.org/patch/10276759/ Pavel, I dropped your Tested-by from v2 since I modified the patch, can you recheck the new patch again? Thanks. regards Suman drivers/media/platform/omap3isp/isp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.16.2 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Tested-by: Pavel Machek Reviewed-by: Laurent Pinchart diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c index 8eb000e3d8fd..f2db5128d786 100644 --- a/drivers/media/platform/omap3isp/isp.c +++ b/drivers/media/platform/omap3isp/isp.c @@ -1945,6 +1945,7 @@ static int isp_initialize_modules(struct isp_device *isp) static void isp_detach_iommu(struct isp_device *isp) { + arm_iommu_detach_device(isp->dev); arm_iommu_release_mapping(isp->mapping); isp->mapping = NULL; } @@ -1961,8 +1962,7 @@ static int isp_attach_iommu(struct isp_device *isp) mapping = arm_iommu_create_mapping(&platform_bus_type, SZ_1G, SZ_2G); if (IS_ERR(mapping)) { dev_err(isp->dev, "failed to create ARM IOMMU mapping\n"); - ret = PTR_ERR(mapping); - goto error; + return PTR_ERR(mapping); } isp->mapping = mapping; @@ -1977,7 +1977,8 @@ static int isp_attach_iommu(struct isp_device *isp) return 0; error: - isp_detach_iommu(isp); + arm_iommu_release_mapping(isp->mapping); + isp->mapping = NULL; return ret; }