diff mbox series

pmdomain: imx: gpcv2: fix an OF node reference leak in imx_gpcv2_probe()

Message ID 20241215030159.1526624-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series pmdomain: imx: gpcv2: fix an OF node reference leak in imx_gpcv2_probe() | expand

Commit Message

Joe Hattori Dec. 15, 2024, 3:01 a.m. UTC
imx_gpcv2_probe() leaks an OF node reference obtained by
of_get_child_by_name(). Fix it by declaring the device node with the
__free(device_node) cleanup construct.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: 03aa12629fc4 ("soc: imx: Add GPCv2 power gating driver")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/pmdomain/imx/gpcv2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ulf Hansson Dec. 19, 2024, 2:51 p.m. UTC | #1
On Sun, 15 Dec 2024 at 04:02, Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> wrote:
>
> imx_gpcv2_probe() leaks an OF node reference obtained by
> of_get_child_by_name(). Fix it by declaring the device node with the
> __free(device_node) cleanup construct.
>
> This bug was found by an experimental static analysis tool that I am
> developing.
>
> Fixes: 03aa12629fc4 ("soc: imx: Add GPCv2 power gating driver")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>

Applied for fixes and by adding a stable tag, thanks!

Kind regards
Uffe


> ---
>  drivers/pmdomain/imx/gpcv2.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pmdomain/imx/gpcv2.c b/drivers/pmdomain/imx/gpcv2.c
> index e67ecf99ef84..9bdb80fd7210 100644
> --- a/drivers/pmdomain/imx/gpcv2.c
> +++ b/drivers/pmdomain/imx/gpcv2.c
> @@ -1458,12 +1458,12 @@ static int imx_gpcv2_probe(struct platform_device *pdev)
>                 .max_register   = SZ_4K,
>         };
>         struct device *dev = &pdev->dev;
> -       struct device_node *pgc_np;
> +       struct device_node *pgc_np __free(device_node) =
> +               of_get_child_by_name(dev->of_node, "pgc");
>         struct regmap *regmap;
>         void __iomem *base;
>         int ret;
>
> -       pgc_np = of_get_child_by_name(dev->of_node, "pgc");
>         if (!pgc_np) {
>                 dev_err(dev, "No power domains specified in DT\n");
>                 return -EINVAL;
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/pmdomain/imx/gpcv2.c b/drivers/pmdomain/imx/gpcv2.c
index e67ecf99ef84..9bdb80fd7210 100644
--- a/drivers/pmdomain/imx/gpcv2.c
+++ b/drivers/pmdomain/imx/gpcv2.c
@@ -1458,12 +1458,12 @@  static int imx_gpcv2_probe(struct platform_device *pdev)
 		.max_register   = SZ_4K,
 	};
 	struct device *dev = &pdev->dev;
-	struct device_node *pgc_np;
+	struct device_node *pgc_np __free(device_node) =
+		of_get_child_by_name(dev->of_node, "pgc");
 	struct regmap *regmap;
 	void __iomem *base;
 	int ret;
 
-	pgc_np = of_get_child_by_name(dev->of_node, "pgc");
 	if (!pgc_np) {
 		dev_err(dev, "No power domains specified in DT\n");
 		return -EINVAL;