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: 10282481 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 C15D9602C2 for ; Wed, 14 Mar 2018 15:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B119C27F60 for ; Wed, 14 Mar 2018 15:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A56DB27F81; Wed, 14 Mar 2018 15:42:24 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B15627F60 for ; Wed, 14 Mar 2018 15:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=U1SlPajc1/LvHBAyMBx6+KyZDXA+tRMP3KbWvtW80YA=; b=Zx2+q7NZSgFe12 9wuKBrZ/4FGBJ2nIljiRydxKmqr4Xgrr/rWLVq4OBoZmuknNq2zxxMZVknse8pQnZCXDcFvu0qAkP G2SfYDiRdSO9DnHbhflq/uWSyZohYFHULUPfwE5LN/Z073C3XH94f5DW6/nnulnu/QuFYnCn4nWYD EYZWWeY2n8tSQo1aLRt6u2cQH2KouaWnIo5Q3qy/+u6WcGT1dtChbdvlR6aiFADDrmdcObm42aXvW TajMzP98nrcr/eQIFv8O7/ZUDqZCwZspOU55lfUoK92DWoaVvX5X7HpbHWNEVzVia8BwfZShqs6ed WFwvYxXWiUdKL+b1YMAg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ew8Xe-0007R7-B4; Wed, 14 Mar 2018 15:42:14 +0000 Received: from fllnx209.ext.ti.com ([198.47.19.16]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ew8XZ-0007P9-I9 for linux-arm-kernel@lists.infradead.org; Wed, 14 Mar 2018 15:42:11 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180314_084209_862647_70D6D0B6 X-CRM114-Status: GOOD ( 17.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tony Lindgren , Sakari Ailus , Pavel Machek , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Pavel Machek Reviewed-by: Laurent Pinchart --- 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(-) 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; }