lkml.org 
[lkml]   [2023]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe()
Date
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
\
 
 \ /
  Last update: 2023-09-22 04:52    [W:0.071 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site