All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>, Sven Peter <sven@kernel.org>,
	Janne Grunau <j@jannau.net>,
	Rob Clark <robin.clark@oss.qualcomm.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Yong Wu <yong.wu@mediatek.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Chen-Yu Tsai <wens@csie.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Krishna Reddy <vdumpa@nvidia.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	Johan Hovold <johan@kernel.org>,
	stable@vger.kernel.org, Yu Kuai <yukuai3@huawei.com>
Subject: [PATCH v2 02/14] iommu/qcom: fix device leak on of_xlate()
Date: Tue,  7 Oct 2025 11:43:15 +0200	[thread overview]
Message-ID: <20251007094327.11734-3-johan@kernel.org> (raw)
In-Reply-To: <20251007094327.11734-1-johan@kernel.org>

Make sure to drop the reference taken to the iommu platform device when
looking up its driver data during of_xlate().

Note that commit e2eae09939a8 ("iommu/qcom: add missing put_device()
call in qcom_iommu_of_xlate()") fixed the leak in a couple of error
paths, but the reference is still leaking on success and late failures.

Fixes: 0ae349a0f33f ("iommu/qcom: Add qcom_iommu")
Cc: stable@vger.kernel.org	# 4.14: e2eae09939a8
Cc: Rob Clark <robin.clark@oss.qualcomm.com>
Cc: Yu Kuai <yukuai3@huawei.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index c5be95e56031..9c1166a3af6c 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -565,14 +565,14 @@ static int qcom_iommu_of_xlate(struct device *dev,
 
 	qcom_iommu = platform_get_drvdata(iommu_pdev);
 
+	put_device(&iommu_pdev->dev);
+
 	/* make sure the asid specified in dt is valid, so we don't have
 	 * to sanity check this elsewhere:
 	 */
 	if (WARN_ON(asid > qcom_iommu->max_asid) ||
-	    WARN_ON(qcom_iommu->ctxs[asid] == NULL)) {
-		put_device(&iommu_pdev->dev);
+	    WARN_ON(qcom_iommu->ctxs[asid] == NULL))
 		return -EINVAL;
-	}
 
 	if (!dev_iommu_priv_get(dev)) {
 		dev_iommu_priv_set(dev, qcom_iommu);
@@ -581,10 +581,8 @@ static int qcom_iommu_of_xlate(struct device *dev,
 		 * multiple different iommu devices.  Multiple context
 		 * banks are ok, but multiple devices are not:
 		 */
-		if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev))) {
-			put_device(&iommu_pdev->dev);
+		if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))
 			return -EINVAL;
-		}
 	}
 
 	return iommu_fwspec_add_ids(dev, &asid, 1);
-- 
2.49.1


  parent reply	other threads:[~2025-10-07  9:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  9:43 [PATCH v2 00/14] iommu: fix device leaks Johan Hovold
2025-10-07  9:43 ` [PATCH v2 01/14] iommu/apple-dart: fix device leak on of_xlate() Johan Hovold
2025-10-07  9:43 ` Johan Hovold [this message]
2025-10-07  9:43 ` [PATCH v2 03/14] iommu/exynos: " Johan Hovold
2025-10-07  9:49   ` Marek Szyprowski
2025-10-07  9:43 ` [PATCH v2 04/14] iommu/ipmmu-vmsa: " Johan Hovold
2025-10-07  9:43 ` [PATCH v2 05/14] iommu/mediatek: " Johan Hovold
2025-10-18  6:50   ` Yong Wu (吴勇)
2025-10-07  9:43 ` [PATCH v2 06/14] iommu/mediatek: fix device leaks on probe() Johan Hovold
2025-10-18  6:54   ` Yong Wu (吴勇)
2025-10-20  5:02     ` Johan Hovold
2025-10-07  9:43 ` [PATCH v2 07/14] iommu/mediatek: simplify dt parsing error handling Johan Hovold
2025-10-07  9:43 ` [PATCH v2 08/14] iommu/mediatek-v1: fix device leak on probe_device() Johan Hovold
2025-10-18  6:51   ` Yong Wu (吴勇)
2025-10-07  9:43 ` [PATCH v2 09/14] iommu/mediatek-v1: fix device leaks on probe() Johan Hovold
2025-10-07  9:43 ` [PATCH v2 10/14] iommu/mediatek-v1: add missing larb count sanity check Johan Hovold
2025-10-18  6:51   ` Yong Wu (吴勇)
2025-10-07  9:43 ` [PATCH v2 11/14] iommu/omap: fix device leaks on probe_device() Johan Hovold
2025-10-07  9:43 ` [PATCH v2 12/14] iommu/omap: simplify probe_device() error handling Johan Hovold
2025-10-07  9:43 ` [PATCH v2 13/14] iommu/sun50i: fix device leak on of_xlate() Johan Hovold
2025-10-07  9:43 ` [PATCH v2 14/14] iommu/tegra: fix device leak on probe_device() Johan Hovold
2025-10-09  7:56   ` Thierry Reding
2025-10-09  8:27     ` Johan Hovold
2025-10-09 10:15       ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251007094327.11734-3-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=iommu@lists.linux.dev \
    --cc=j@jannau.net \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=matthias.bgg@gmail.com \
    --cc=robin.clark@oss.qualcomm.com \
    --cc=robin.murphy@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=sven@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=vdumpa@nvidia.com \
    --cc=wens@csie.org \
    --cc=will@kernel.org \
    --cc=yong.wu@mediatek.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.