[PATCH -next] clk: imx: scu: fix memleak on platform_device_add() fails

Lin Yujun posted 1 patch 3 years, 6 months ago
drivers/clk/imx/clk-scu.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH -next] clk: imx: scu: fix memleak on platform_device_add() fails
Posted by Lin Yujun 3 years, 6 months ago
No error handling is performed when platform_device_add()
fails. Add error processing before return, and modified
the return value.

Fixes: 77d8f3068c63 ("clk: imx: scu: add two cells binding support")
Signed-off-by: Lin Yujun <linyujun809@huawei.com>
---
 drivers/clk/imx/clk-scu.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
index c56e406138db..1e6870f3671f 100644
--- a/drivers/clk/imx/clk-scu.c
+++ b/drivers/clk/imx/clk-scu.c
@@ -695,7 +695,11 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name,
 		pr_warn("%s: failed to attached the power domain %d\n",
 			name, ret);
 
-	platform_device_add(pdev);
+	ret = platform_device_add(pdev);
+	if (ret) {
+		platform_device_put(pdev);
+		return ERR_PTR(ret);
+	}
 
 	/* For API backwards compatiblilty, simply return NULL for success */
 	return NULL;
-- 
2.17.1
Re: [PATCH -next] clk: imx: scu: fix memleak on platform_device_add() fails
Posted by Stephen Boyd 3 years, 6 months ago
Quoting Lin Yujun (2022-09-13 20:32:06)
> No error handling is performed when platform_device_add()
> fails. Add error processing before return, and modified
> the return value.
> 
> Fixes: 77d8f3068c63 ("clk: imx: scu: add two cells binding support")
> Signed-off-by: Lin Yujun <linyujun809@huawei.com>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>
Re: [PATCH -next] clk: imx: scu: fix memleak on platform_device_add() fails
Posted by Stephen Boyd 3 years, 6 months ago
Quoting Lin Yujun (2022-09-13 20:32:06)
> No error handling is performed when platform_device_add()
> fails. Add error processing before return, and modified
> the return value.
> 
> Fixes: 77d8f3068c63 ("clk: imx: scu: add two cells binding support")
> Signed-off-by: Lin Yujun <linyujun809@huawei.com>
> ---

Applied to clk-next
Re: [PATCH -next] clk: imx: scu: fix memleak on platform_device_add() fails
Posted by linyujun (C) 3 years, 6 months ago
kindly ping

在 2022/9/14 11:32, Lin Yujun 写道:
> No error handling is performed when platform_device_add()
> fails. Add error processing before return, and modified
> the return value.
>
> Fixes: 77d8f3068c63 ("clk: imx: scu: add two cells binding support")
> Signed-off-by: Lin Yujun <linyujun809@huawei.com>
> ---
>   drivers/clk/imx/clk-scu.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
> index c56e406138db..1e6870f3671f 100644
> --- a/drivers/clk/imx/clk-scu.c
> +++ b/drivers/clk/imx/clk-scu.c
> @@ -695,7 +695,11 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name,
>   		pr_warn("%s: failed to attached the power domain %d\n",
>   			name, ret);
>   
> -	platform_device_add(pdev);
> +	ret = platform_device_add(pdev);
> +	if (ret) {
> +		platform_device_put(pdev);
> +		return ERR_PTR(ret);
> +	}
>   
>   	/* For API backwards compatiblilty, simply return NULL for success */
>   	return NULL;