Skip to contentSkip to conversation

soc: amlogic: Fix refcount leak in meson-secure-pwrc.c

PATCH Applied Liang He 3 participants 5 messages Jun 16, 2022 – Jun 17, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 soc: amlogic: Fix refcount leak in meson-secure-pwrc.c

In meson_secure_pwrc_probe(), there is a refcount leak in one fail path.

---
 drivers/soc/amlogic/meson-secure-pwrc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soc/amlogic/meson-secure-pwrc.c +3 -1
index a10a417a87db..e93518763526 100644
@@ -152,8 +152,10 @@ static int meson_secure_pwrc_probe(struct platform_device *pdev)
 	}
 
 	pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL);
-	if (!pwrc)
+	if (!pwrc) {
+		of_node_put(sm_np);
 		return -ENOMEM;
+	}
 
 	pwrc->fw = meson_sm_get(sm_np);
 	of_node_put(sm_np);
Signature · 1 line
2.25.1
reviewer Acked-by on v1 1/1
#1 lore raw

Hello,

Quoted 5 lines · Liang He

In meson_secure_pwrc_probe(), there is a refcount leak in one fail path.

[...]

drivers/soc/amlogic/meson-secure-pwrc.c static int meson_secure_pwrc_probe(struct platform_device *pdev) · line 158

Quoted 6 lines
        pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL);
drivers/soc/amlogic/meson-secure-pwrc.c +3 -1
-       if (!pwrc)
+       if (!pwrc) {
+               of_node_put(sm_np);
                return -ENOMEM;
+       }

Another approach would be to just move devm_kzalloc() a few lines further up (above of_find_compatible_node()).
That would catch similar issues in future when someone wants to add more code right after devm_kzalloc(). That said, I don't think that this is a likely scenario so the patch is fine for me as-is.

Thanks a lot for submitting this!

Best regards,
Martin

author
#2 lore raw
Quoted 23 lines · Martin Blumenstingl

Hello,

Quoted 5 lines · Liang He

In meson_secure_pwrc_probe(), there is a refcount leak in one fail path.

[...]

drivers/soc/amlogic/meson-secure-pwrc.c static int meson_secure_pwrc_probe(struct platform_device *pdev) · line 158

Quoted 6 lines
        pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL);
drivers/soc/amlogic/meson-secure-pwrc.c +3 -1
-       if (!pwrc)
+       if (!pwrc) {
+               of_node_put(sm_np);
                return -ENOMEM;
+       }

Another approach would be to just move devm_kzalloc() a few lines further up (above of_find_compatible_node()).
That would catch similar issues in future when someone wants to add more code right after devm_kzalloc(). That said, I don't think that this is a likely scenario so the patch is fine for me as-is.

Quoted 5 lines

Thanks a lot for submitting this!

Best regards,
Martin

Thanks for your confirm.

Liang

Reviewed-by on v1 1/1
#3 lore raw
In reply to Liang He
Quoted 4 lines · Liang He

In meson_secure_pwrc_probe(), there is a refcount leak in one fail path.

Fixes b3dde5013e13 ("soc: amlogic: Add support for Secure power domains controller")
Quoted 10 lines
---
  drivers/soc/amlogic/meson-secure-pwrc.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soc/amlogic/meson-secure-pwrc.c +0 -0
index a10a417a87db..e93518763526 100644
@@ -152,8 +152,10 @@ static int meson_secure_pwrc_probe(struct platform_device *pdev)
  	}

drivers/soc/amlogic/meson-secure-pwrc.c static int meson_secure_pwrc_probe(struct platform_device *pdev) · line 161

Quoted 10 lines
drivers/soc/amlogic/meson-secure-pwrc.c +3 -1
 
  	pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL);
-	if (!pwrc)
+	if (!pwrc) {
+		of_node_put(sm_np);
  		return -ENOMEM;
+	}
 
  	pwrc->fw = meson_sm_get(sm_np);
  	of_node_put(sm_np);
#4 lore raw
In reply to Liang He

Hi,

Quoted 4 lines · Liang He

In meson_secure_pwrc_probe(), there is a refcount leak in one fail path.

Thanks, Applied to https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git (v5.20/drivers)

[1/1] soc: amlogic: Fix refcount leak in meson-secure-pwrc.c

      https://git.kernel.org/amlogic/c/d18529a4c12f66d83daac78045ea54063bd43257

These changes has been applied on the intermediate git tree [1].

The v5.20/drivers branch will then be sent via a formal Pull Request to the Linux SoC maintainers for inclusion in their intermediate git branches in order to be sent to Linus during the next merge window, or sooner if it's a set of fixes.

In the cases of fixes, those will be merged in the current release candidate kernel and as soon they appear on the Linux master branch they will be backported to the previous Stable and Long-Stable kernels [2].

The intermediate git branches are merged daily in the linux-next tree [3], people are encouraged testing these pre-release kernels and report issues on the relevant mailing-lists.

If problems are discovered on those changes, please submit a signed-off-by revert patch followed by a corrective changeset.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git
[2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
[3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

Signature · 1 line
Neil