From patchwork Mon Mar 12 16:52:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 131391 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp972541ljb; Mon, 12 Mar 2018 09:52:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELuQMVlQkzzo6WTfesYZ4b2RBFNcTdzkCYQabORSAY8Lbi4SzznSaBj4jhGCKyZS/zZGVsys X-Received: by 10.99.126.20 with SMTP id z20mr3948953pgc.38.1520873572607; Mon, 12 Mar 2018 09:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520873572; cv=none; d=google.com; s=arc-20160816; b=zDjEW+TaactvnaVfdH1HbxlaJlA1Z6fw0rI1BfyhrR8Ai+14z4Cfim+lP8JNbpJ2Fy KRuCLPSPkhyhDUwoGhseu9K7ruhtzmSTWUzgZcEh5h/pw0tTiOwGKyGMDIxpS+BqjtOE /U/DHlIzb49f6kwzIO1ovrEKxur2fwHc5fbP4nHI4Gme02P3m1fk3hvjWfXKCvJHqNXG dapV20N6YdG22ivwrV2bzmWEUgMQSQgFsmUWdjZ3Uz9Vk9XnQfyC3ciUCuMJ5cwVlGjT qNE1krzK7jGrHtPOdPR+y0gjY6kf2bF7kBC+qa0qSooTMkTnS2iMcmGQ7rN69qL0OU49 uLlQ== 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=dZYcjkxiHeDkpz1xttsjw0V0Jl88f+iTOe0qoMkVnWs=; b=IxGw72Qnx+qpO60wjLENhvYwkBTipD7ReOKWhpqRF9/BFbOuwBuLrblRQKnTyZMh3H s3lmfN2XeekyfVmLa7YmNckWnsV7GyhOvx91Ng8sbNcieWZgdkrB00XBcqlAyxNtTyqC AMV77nkB7ZxynfumhXM/SiZD/72aybW+NY19qXxOVbf/MDhM3OSzqvx7jeQFbdS20NgK QEcVDslBZR1I8c9rQQH6C8/iiynoUV7OHry1WuhsYOGXy4fLlQ3ItJIYjfGKosYTmIe3 ACXJOtOlVYFYrjTECUXR+vaY8/iPs66dmSp15QLTPSHUDYS7KDJXdIUrtQJSlGAL0V1Z tPVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=aN9W4tr3; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=pass (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 n5si5293169pgc.459.2018.03.12.09.52.52; Mon, 12 Mar 2018 09:52:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=aN9W4tr3; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751458AbeCLQws (ORCPT + 5 others); Mon, 12 Mar 2018 12:52:48 -0400 Received: from fllnx210.ext.ti.com ([198.47.19.17]:52387 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751320AbeCLQwr (ORCPT ); Mon, 12 Mar 2018 12:52:47 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id w2CGq9hC010764; Mon, 12 Mar 2018 11:52:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1520873529; bh=lrimqyfLd4CpHVfuIkmuouYwxHxhMaCQFlBKj2/1Bpo=; h=From:To:CC:Subject:Date; b=aN9W4tr3aqXwwTMM3ZmCJKKDkN/PuWSBMLnCPSwiwhwCGKX51me2ximjx0iTqxQ4i iyiyIdqhrmAXYBvrWE7Jp3mNMdwXUysyib11Vj8IR4YMgGwHdnmTlR1cMuZg8nn6Or AqmTYp6br1qx9IZNlOmy48DDxQlc0C+TfI5GvtjI= 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 w2CGq9vC020585; Mon, 12 Mar 2018 11:52:09 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) 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; Mon, 12 Mar 2018 11:52:08 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Mon, 12 Mar 2018 11:52:09 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w2CGq8ew014498; Mon, 12 Mar 2018 11:52:08 -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 w2CGq8x15943; Mon, 12 Mar 2018 11:52:08 -0500 (CDT) From: Suman Anna To: Laurent Pinchart , Mauro Carvalho Chehab CC: Pavel Machek , Sakari Ailus , Tony Lindgren , Suman Anna , , , Subject: [PATCH] media: omap3isp: fix unbalanced dma_iommu_mapping Date: Mon, 12 Mar 2018 11:52:07 -0500 Message-ID: <20180312165207.12436-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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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 Tested-by: Pavel Machek --- Hi Mauro, Laurent, This fixes an issue reported by Pavel and discussed on this thread, https://marc.info/?l=linux-omap&m=152051945803598&w=2 Posting this again to the appropriate lists. regards Suman drivers/media/platform/omap3isp/isp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.16.2 diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c index 8eb000e3d8fd..c7d667bfc2af 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; } @@ -1971,13 +1972,15 @@ static int isp_attach_iommu(struct isp_device *isp) ret = arm_iommu_attach_device(isp->dev, mapping); if (ret < 0) { dev_err(isp->dev, "failed to attach device to VA mapping\n"); - goto error; + goto error_attach; } return 0; +error_attach: + arm_iommu_release_mapping(isp->mapping); + isp->mapping = NULL; error: - isp_detach_iommu(isp); return ret; }