public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] memory: mtk-smi: fix device leaks on probe
@ 2025-11-21 16:46 Johan Hovold
  2025-11-21 16:46 ` [PATCH 1/3] memory: mtk-smi: fix device leaks on common probe Johan Hovold
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Johan Hovold @ 2025-11-21 16:46 UTC (permalink / raw)
  To: Yong Wu, Krzysztof Kozlowski
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, linux-mediatek,
	linux-kernel, Johan Hovold

Make sure to drop the reference taken when looking up the SMI device
during probe on late probe failure (e.g. probe deferral) and on driver
unbind.

Included is also a related cleanup.

Johan


Johan Hovold (3):
  memory: mtk-smi: fix device leaks on common probe
  memory: mtk-smi: fix device leak on larb probe
  memory: mtk-smi: clean up device link creation

 drivers/memory/mtk-smi.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

-- 
2.51.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] memory: mtk-smi: fix device leaks on common probe
  2025-11-21 16:46 [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Johan Hovold
@ 2025-11-21 16:46 ` Johan Hovold
  2025-12-16  7:16   ` Krzysztof Kozlowski
  2025-11-21 16:46 ` [PATCH 2/3] memory: mtk-smi: fix device leak on larb probe Johan Hovold
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Johan Hovold @ 2025-11-21 16:46 UTC (permalink / raw)
  To: Yong Wu, Krzysztof Kozlowski
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, linux-mediatek,
	linux-kernel, Johan Hovold, stable, Miaoqian Lin

Make sure to drop the reference taken when looking up the SMI device
during common probe on late probe failure (e.g. probe deferral) and on
driver unbind.

Fixes: 47404757702e ("memory: mtk-smi: Add device link for smi-sub-common")
Fixes: 038ae37c510f ("memory: mtk-smi: add missing put_device() call in mtk_smi_device_link_common")
Cc: stable@vger.kernel.org	# 5.16: 038ae37c510f
Cc: Yong Wu <yong.wu@mediatek.com>
Cc: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/memory/mtk-smi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index 733e22f695ab..dd6150d200e8 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -674,6 +674,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
 err_pm_disable:
 	pm_runtime_disable(dev);
 	device_link_remove(dev, larb->smi_common_dev);
+	put_device(larb->smi_common_dev);
 	return ret;
 }
 
@@ -917,6 +918,7 @@ static void mtk_smi_common_remove(struct platform_device *pdev)
 	if (common->plat->type == MTK_SMI_GEN2_SUB_COMM)
 		device_link_remove(&pdev->dev, common->smi_common_dev);
 	pm_runtime_disable(&pdev->dev);
+	put_device(common->smi_common_dev);
 }
 
 static int __maybe_unused mtk_smi_common_resume(struct device *dev)
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] memory: mtk-smi: fix device leak on larb probe
  2025-11-21 16:46 [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Johan Hovold
  2025-11-21 16:46 ` [PATCH 1/3] memory: mtk-smi: fix device leaks on common probe Johan Hovold
@ 2025-11-21 16:46 ` Johan Hovold
  2025-11-21 16:46 ` [PATCH 3/3] memory: mtk-smi: clean up device link creation Johan Hovold
  2025-12-16  7:22 ` [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Krzysztof Kozlowski
  3 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2025-11-21 16:46 UTC (permalink / raw)
  To: Yong Wu, Krzysztof Kozlowski
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, linux-mediatek,
	linux-kernel, Johan Hovold, stable, Miaoqian Lin

Make sure to drop the reference taken when looking up the SMI device
during larb probe on late probe failure (e.g. probe deferral) and on
driver unbind.

Fixes: cc8bbe1a8312 ("memory: mediatek: Add SMI driver")
Fixes: 038ae37c510f ("memory: mtk-smi: add missing put_device() call in mtk_smi_device_link_common")
Cc: stable@vger.kernel.org	# 4.6: 038ae37c510f
Cc: Yong Wu <yong.wu@mediatek.com>
Cc: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/memory/mtk-smi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index dd6150d200e8..3609bfd3c64b 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -685,6 +685,7 @@ static void mtk_smi_larb_remove(struct platform_device *pdev)
 	device_link_remove(&pdev->dev, larb->smi_common_dev);
 	pm_runtime_disable(&pdev->dev);
 	component_del(&pdev->dev, &mtk_smi_larb_component_ops);
+	put_device(larb->smi_common_dev);
 }
 
 static int __maybe_unused mtk_smi_larb_resume(struct device *dev)
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] memory: mtk-smi: clean up device link creation
  2025-11-21 16:46 [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Johan Hovold
  2025-11-21 16:46 ` [PATCH 1/3] memory: mtk-smi: fix device leaks on common probe Johan Hovold
  2025-11-21 16:46 ` [PATCH 2/3] memory: mtk-smi: fix device leak on larb probe Johan Hovold
@ 2025-11-21 16:46 ` Johan Hovold
  2025-12-16  7:22 ` [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Krzysztof Kozlowski
  3 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2025-11-21 16:46 UTC (permalink / raw)
  To: Yong Wu, Krzysztof Kozlowski
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, linux-mediatek,
	linux-kernel, Johan Hovold

Clean up device link creation by bailing out early in case the SMI
platform device lookup fails.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/memory/mtk-smi.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index 3609bfd3c64b..aaeba8ab211e 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -595,25 +595,28 @@ static int mtk_smi_device_link_common(struct device *dev, struct device **com_de
 
 	smi_com_pdev = of_find_device_by_node(smi_com_node);
 	of_node_put(smi_com_node);
-	if (smi_com_pdev) {
-		/* smi common is the supplier, Make sure it is ready before */
-		if (!platform_get_drvdata(smi_com_pdev)) {
-			put_device(&smi_com_pdev->dev);
-			return -EPROBE_DEFER;
-		}
-		smi_com_dev = &smi_com_pdev->dev;
-		link = device_link_add(dev, smi_com_dev,
-				       DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
-		if (!link) {
-			dev_err(dev, "Unable to link smi-common dev\n");
-			put_device(&smi_com_pdev->dev);
-			return -ENODEV;
-		}
-		*com_dev = smi_com_dev;
-	} else {
+	if (!smi_com_pdev) {
 		dev_err(dev, "Failed to get the smi_common device\n");
 		return -EINVAL;
 	}
+
+	/* smi common is the supplier, Make sure it is ready before */
+	if (!platform_get_drvdata(smi_com_pdev)) {
+		put_device(&smi_com_pdev->dev);
+		return -EPROBE_DEFER;
+	}
+
+	smi_com_dev = &smi_com_pdev->dev;
+	link = device_link_add(dev, smi_com_dev,
+			       DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+	if (!link) {
+		dev_err(dev, "Unable to link smi-common dev\n");
+		put_device(&smi_com_pdev->dev);
+		return -ENODEV;
+	}
+
+	*com_dev = smi_com_dev;
+
 	return 0;
 }
 
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] memory: mtk-smi: fix device leaks on common probe
  2025-11-21 16:46 ` [PATCH 1/3] memory: mtk-smi: fix device leaks on common probe Johan Hovold
@ 2025-12-16  7:16   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2025-12-16  7:16 UTC (permalink / raw)
  To: Johan Hovold, Yong Wu
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, linux-mediatek,
	linux-kernel, stable, Miaoqian Lin

On 21/11/2025 17:46, Johan Hovold wrote:
> Make sure to drop the reference taken when looking up the SMI device
> during common probe on late probe failure (e.g. probe deferral) and on
> driver unbind.
> 
> Fixes: 47404757702e ("memory: mtk-smi: Add device link for smi-sub-common")
> Fixes: 038ae37c510f ("memory: mtk-smi: add missing put_device() call in mtk_smi_device_link_common")
> Cc: stable@vger.kernel.org	# 5.16: 038ae37c510f
> Cc: Yong Wu <yong.wu@mediatek.com>
> Cc: Miaoqian Lin <linmq006@gmail.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>

Thanks Johan.

Side note:
Three weeks and no reviews from Mediatek developers (not necessarily SoC
maintainers, I know your queue is long). So please remember Mediatek: in
case you ever wonder why your patches are waiting on the list for very
long, here is your answer.


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] memory: mtk-smi: fix device leaks on probe
  2025-11-21 16:46 [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Johan Hovold
                   ` (2 preceding siblings ...)
  2025-11-21 16:46 ` [PATCH 3/3] memory: mtk-smi: clean up device link creation Johan Hovold
@ 2025-12-16  7:22 ` Krzysztof Kozlowski
  3 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2025-12-16  7:22 UTC (permalink / raw)
  To: Yong Wu, Johan Hovold
  Cc: Krzysztof Kozlowski, Matthias Brugger, AngeloGioacchino Del Regno,
	linux-mediatek, linux-kernel


On Fri, 21 Nov 2025 17:46:21 +0100, Johan Hovold wrote:
> Make sure to drop the reference taken when looking up the SMI device
> during probe on late probe failure (e.g. probe deferral) and on driver
> unbind.
> 
> Included is also a related cleanup.
> 
> Johan
> 
> [...]

I fixed up stable-cc syntax - missing final Cc, because only prerequisite was
mentioned.

Applied, thanks!

[1/3] memory: mtk-smi: fix device leaks on common probe
      https://git.kernel.org/krzk/linux-mem-ctrl/c/6cfa038bddd710f544076ea2ef7792fc82fbedd6
[2/3] memory: mtk-smi: fix device leak on larb probe
      https://git.kernel.org/krzk/linux-mem-ctrl/c/9dae65913b32d05dbc8ff4b8a6bf04a0e49a8eb6
[3/3] memory: mtk-smi: clean up device link creation
      https://git.kernel.org/krzk/linux-mem-ctrl/c/78da7027e2a99edea0d7e97b25d75be4698a8728

Best regards,
-- 
Krzysztof Kozlowski <krzk@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-12-16  7:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-21 16:46 [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Johan Hovold
2025-11-21 16:46 ` [PATCH 1/3] memory: mtk-smi: fix device leaks on common probe Johan Hovold
2025-12-16  7:16   ` Krzysztof Kozlowski
2025-11-21 16:46 ` [PATCH 2/3] memory: mtk-smi: fix device leak on larb probe Johan Hovold
2025-11-21 16:46 ` [PATCH 3/3] memory: mtk-smi: clean up device link creation Johan Hovold
2025-12-16  7:22 ` [PATCH 0/3] memory: mtk-smi: fix device leaks on probe Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox