[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241026082525.474914-1-ruanjinjie@huawei.com>
Date: Sat, 26 Oct 2024 16:25:25 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <daniel.lezcano@...nel.org>, <rafael@...nel.org>,
<linux-pm@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH] powercap: dtpm_devfreq: Fix possible memory leak in __dtpm_devfreq_setup()
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@...wei.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;
}
--
2.34.1
Powered by blists - more mailing lists