cpuidle: qcom-spm: fix device and OF node leaks at probe
Subsystems (2)
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
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.
--- drivers/cpuidle/cpuidle-qcom-spm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-qcom-spm.c +5 -2
@@ -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
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 duringprobe().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]>Signed-off-by Johan Hovold <[email protected]>---
Konrad
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 duringprobe().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]>Signed-off-by Johan Hovold <[email protected]>---
Reviewed-by Konrad Dybcio <[email protected]>
Applied as 6.18 material along with the [2/2], thanks!
PATCH 2/2 cpuidle: qcom-spm: drop unnecessary initialisations
In reply to Johan HovoldDrop 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
@@ -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
Re: [PATCH 2/2] cpuidle: qcom-spm: drop unnecessary initialisations
Quoted 6 lines · 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.
Signed-off-by Johan Hovold <[email protected]>---
Konrad