public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Longfang Liu <liulongfang@huawei.com>
To: <robin.murphy@arm.com>, <will@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev>,
	<liulongfang@huawei.com>
Subject: [PATCH v2] iommu: fix smmu initialization memory leak problem
Date: Mon, 21 Nov 2022 11:04:21 +0800	[thread overview]
Message-ID: <20221121030421.19295-1-liulongfang@huawei.com> (raw)

When iommu_device_register() in arm_smmu_device_probe() fails,
in addition to sysfs needs to be deleted, device should also
be disabled, and the memory of iopf needs to be released to
prevent memory leak of iopf.

Changes v1 -> v2:
	-Improve arm_smmu_device_probe() abnormal exit function.

Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index ab160198edd6..b892f5233f88 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -3815,7 +3815,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
 	/* Initialise in-memory data structures */
 	ret = arm_smmu_init_structures(smmu);
 	if (ret)
-		return ret;
+		goto err_iopf;
 
 	/* Record our private device structure */
 	platform_set_drvdata(pdev, smmu);
@@ -3826,22 +3826,28 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
 	/* Reset the device */
 	ret = arm_smmu_device_reset(smmu, bypass);
 	if (ret)
-		return ret;
+		goto err_iopf;
 
 	/* And we're up. Go go go! */
 	ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL,
 				     "smmu3.%pa", &ioaddr);
 	if (ret)
-		return ret;
+		goto err_reset;
 
 	ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev);
 	if (ret) {
 		dev_err(dev, "Failed to register iommu\n");
-		iommu_device_sysfs_remove(&smmu->iommu);
-		return ret;
+		goto err_sysfs_add;
 	}
 
 	return 0;
+err_sysfs_add:
+	iommu_device_sysfs_remove(&smmu->iommu);
+err_reset:
+	arm_smmu_device_disable(smmu);
+err_iopf:
+	iopf_queue_free(smmu->evtq.iopf);
+	return ret;
 }
 
 static int arm_smmu_device_remove(struct platform_device *pdev)
-- 
2.24.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2022-11-21  3:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21  3:04 Longfang Liu [this message]
2022-11-21 18:05 ` [PATCH v2] iommu: fix smmu initialization memory leak problem Will Deacon
2022-11-22 12:00   ` liulongfang
2022-11-29 15:24     ` Will Deacon
2022-12-01 12:42       ` liulongfang
2022-12-01 13:31         ` Will Deacon
2022-12-20  3:17           ` liulongfang
2022-12-20 21:37             ` Marion & Christophe JAILLET
2023-01-10 12:00               ` Will Deacon

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=20221121030421.19295-1-liulongfang@huawei.com \
    --to=liulongfang@huawei.com \
    --cc=iommu@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox