Skip to contentSkip to conversation

cpuidle: qcom-spm: fix device and OF node leaks at probe

PATCH Applied Johan Hovold 3 participants 6 messages Sep 8, 2025 – Sep 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover cpuidle: qcom-spm: fix device and OF node leaks at probe

This series fixes a mostly benign device reference leak during probe (e.g. to avoid it being reproduced in other drivers where it may matter more).

Included is also a related cleanup.

Johan

Johan Hovold (2):
cpuidle: qcom-spm: fix device and OF node leaks at probe
cpuidle: qcom-spm: drop unnecessary initialisations

 drivers/cpuidle/cpuidle-qcom-spm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.49.1
#1 lore raw

PATCH 1/2 cpuidle: qcom-spm: fix device and OF node leaks at probe

Make sure to drop the reference to the saw device taken by of_find_device_by_node() after retrieving its driver data during probe().

Also drop the reference to the CPU node sooner to avoid leaking it in case there is no saw node or device.

Fixes 60f3692b5f0b ("cpuidle: qcom_spm: Detach state machine from main SPM handling")
Cc AngeloGioacchino Del Regno <[email protected]>
---
 drivers/cpuidle/cpuidle-qcom-spm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-qcom-spm.c +5 -2
index 5f386761b156..f60a4cf53642 100644
@@ -96,20 +96,23 @@ static int spm_cpuidle_register(struct device *cpuidle_dev, int cpu)
 		return -ENODEV;
 
 	saw_node = of_parse_phandle(cpu_node, "qcom,saw", 0);
+	of_node_put(cpu_node);
 	if (!saw_node)
 		return -ENODEV;
 
 	pdev = of_find_device_by_node(saw_node);
 	of_node_put(saw_node);
-	of_node_put(cpu_node);
 	if (!pdev)
 		return -ENODEV;
 
 	data = devm_kzalloc(cpuidle_dev, sizeof(*data), GFP_KERNEL);
-	if (!data)
+	if (!data) {
+		put_device(&pdev->dev);
 		return -ENOMEM;
+	}
 
 	data->spm = dev_get_drvdata(&pdev->dev);
+	put_device(&pdev->dev);
 	if (!data->spm)
 		return -EINVAL;
 
Signature · 1 line
2.49.1
Reviewed-by on v1 1/2
#2 lore raw
Quoted 11 lines · Johan Hovold

Make sure to drop the reference to the saw device taken by of_find_device_by_node() after retrieving its driver data during probe().

Also drop the reference to the CPU node sooner to avoid leaking it in case there is no saw node or device.

Fixes 60f3692b5f0b ("cpuidle: qcom_spm: Detach state machine from main SPM handling")
Cc AngeloGioacchino Del Regno <[email protected]>

---

Konrad

maintainer Applied
#3 lore raw
Quoted 9 lines · Konrad Dybcio
Quoted 7 lines · Johan Hovold

Make sure to drop the reference to the saw device taken by of_find_device_by_node() after retrieving its driver data during probe().

Also drop the reference to the CPU node sooner to avoid leaking it in case there is no saw node or device.

Quoted 6 lines
Quoted 4 lines
Fixes 60f3692b5f0b ("cpuidle: qcom_spm: Detach state machine from main SPM handling")
Cc AngeloGioacchino Del Regno <[email protected]>

---

Applied as 6.18 material along with the [2/2], thanks!

#4 lore raw

PATCH 2/2 cpuidle: qcom-spm: drop unnecessary initialisations

In reply to Johan Hovold

Drop the unnecessary initialisations of the platform device and driver data pointers which are assigned on first use when registering the cpuidle device during probe.

---
 drivers/cpuidle/cpuidle-qcom-spm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-qcom-spm.c +2 -2
index f60a4cf53642..7ab6f68b96a8 100644
@@ -86,9 +86,9 @@ static const struct of_device_id qcom_idle_state_match[] = {
 
 static int spm_cpuidle_register(struct device *cpuidle_dev, int cpu)
 {
-	struct platform_device *pdev = NULL;
+	struct platform_device *pdev;
 	struct device_node *cpu_node, *saw_node;
-	struct cpuidle_qcom_spm_data *data = NULL;
+	struct cpuidle_qcom_spm_data *data;
 	int ret;
 
 	cpu_node = of_cpu_device_node_get(cpu);
Signature · 1 line
2.49.1