* [PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe()
@ 2023-09-22 2:52 Ma Ke
2023-10-24 2:00 ` Stephen Boyd
0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2023-09-22 2:52 UTC (permalink / raw)
To: mchehab+huawei, sboyd; +Cc: linux-kernel, Ma Ke
spmi_controller_alloc() allocates a memory space for ctrl. When some
errors occur, ctrl should be handled by spmi_controller_put() and set
spmi_controller->controller = NULL because spmi_controller->controller
has a dangling pointer to the freed memory. When the failure happens,
the function returns without calling spmi_controller_put() and setting
spmi_controller->controller = NULL, which will lead to a memory leak.
When the failure happens, we can fix it by calling spmi_controller_put()
and setting spmi_controller->controller = NULL in all of the places
where we call spmi_controller_put().
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
drivers/spmi/hisi-spmi-controller.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c
index 9cbd473487cb..5b3cfa7f5056 100644
--- a/drivers/spmi/hisi-spmi-controller.c
+++ b/drivers/spmi/hisi-spmi-controller.c
@@ -321,6 +321,7 @@ static int spmi_controller_probe(struct platform_device *pdev)
err_put_controller:
spmi_controller_put(ctrl);
+ spmi_controller->controller = NULL;
return ret;
}
--
2.37.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe()
2023-09-22 2:52 [PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe() Ma Ke
@ 2023-10-24 2:00 ` Stephen Boyd
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2023-10-24 2:00 UTC (permalink / raw)
To: Ma Ke, mchehab+huawei; +Cc: linux-kernel, Ma Ke
Quoting Ma Ke (2023-09-21 19:52:16)
> spmi_controller_alloc() allocates a memory space for ctrl. When some
> errors occur, ctrl should be handled by spmi_controller_put() and set
> spmi_controller->controller = NULL because spmi_controller->controller
> has a dangling pointer to the freed memory. When the failure happens,
> the function returns without calling spmi_controller_put() and setting
> spmi_controller->controller = NULL, which will lead to a memory leak.
>
> When the failure happens, we can fix it by calling spmi_controller_put()
> and setting spmi_controller->controller = NULL in all of the places
> where we call spmi_controller_put().
>
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
> drivers/spmi/hisi-spmi-controller.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c
> index 9cbd473487cb..5b3cfa7f5056 100644
> --- a/drivers/spmi/hisi-spmi-controller.c
> +++ b/drivers/spmi/hisi-spmi-controller.c
> @@ -321,6 +321,7 @@ static int spmi_controller_probe(struct platform_device *pdev)
>
> err_put_controller:
> spmi_controller_put(ctrl);
> + spmi_controller->controller = NULL;
The controller will most likely be freed after the put call one line
above so this will oops. No thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-24 2:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 2:52 [PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe() Ma Ke
2023-10-24 2:00 ` Stephen Boyd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome