diff mbox series

powercap: dtpm_devfreq: Fix possible memory leak in __dtpm_devfreq_setup()

Message ID 20241026082525.474914-1-ruanjinjie@huawei.com (mailing list archive)
State New
Headers show
Series powercap: dtpm_devfreq: Fix possible memory leak in __dtpm_devfreq_setup() | expand

Commit Message

Jinjie Ruan Oct. 26, 2024, 8:25 a.m. UTC
If dev_pm_qos_add_request() fails, dtpm_devfreq will fail
to free, which cause the memory leak, add a new goto label
to free it.

Fixes: e44655617317 ("powercap/drivers/dtpm: Add dtpm devfreq with energy model support")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/powercap/dtpm_devfreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Jinjie Ruan Nov. 7, 2024, 1:30 a.m. UTC | #1
Gentle ping.

On 2024/10/26 16:25, Jinjie Ruan wrote:
> If dev_pm_qos_add_request() fails, dtpm_devfreq will fail
> to free, which cause the memory leak, add a new goto label
> to free it.
> 
> Fixes: e44655617317 ("powercap/drivers/dtpm: Add dtpm devfreq with energy model support")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/powercap/dtpm_devfreq.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfreq.c
> index d1dff6ccab12..85b6982901d1 100644
> --- a/drivers/powercap/dtpm_devfreq.c
> +++ b/drivers/powercap/dtpm_devfreq.c
> @@ -171,8 +171,7 @@ static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent)
>  	ret = dtpm_register(dev_name(dev), &dtpm_devfreq->dtpm, parent);
>  	if (ret) {
>  		pr_err("Failed to register '%s': %d\n", dev_name(dev), ret);
> -		kfree(dtpm_devfreq);
> -		return ret;
> +		goto out_dtpm_free;
>  	}
>  
>  	ret = dev_pm_qos_add_request(dev, &dtpm_devfreq->qos_req,
> @@ -190,6 +189,8 @@ static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent)
>  out_dtpm_unregister:
>  	dtpm_unregister(&dtpm_devfreq->dtpm);
>  
> +out_dtpm_free:
> +	kfree(dtpm_devfreq);
>  	return ret;
>  }
>
diff mbox series

Patch

diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfreq.c
index d1dff6ccab12..85b6982901d1 100644
--- a/drivers/powercap/dtpm_devfreq.c
+++ b/drivers/powercap/dtpm_devfreq.c
@@ -171,8 +171,7 @@  static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent)
 	ret = dtpm_register(dev_name(dev), &dtpm_devfreq->dtpm, parent);
 	if (ret) {
 		pr_err("Failed to register '%s': %d\n", dev_name(dev), ret);
-		kfree(dtpm_devfreq);
-		return ret;
+		goto out_dtpm_free;
 	}
 
 	ret = dev_pm_qos_add_request(dev, &dtpm_devfreq->qos_req,
@@ -190,6 +189,8 @@  static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent)
 out_dtpm_unregister:
 	dtpm_unregister(&dtpm_devfreq->dtpm);
 
+out_dtpm_free:
+	kfree(dtpm_devfreq);
 	return ret;
 }