diff mbox series

[-next] drivers: soc: xilinx: add the missing kfree in xlnx_add_cb_for_suspend()

Message ID 20240706065155.452764-1-cuigaosheng1@huawei.com (mailing list archive)
State New, archived
Headers show
Series [-next] drivers: soc: xilinx: add the missing kfree in xlnx_add_cb_for_suspend() | expand

Commit Message

cuigaosheng July 6, 2024, 6:51 a.m. UTC
If we fail to allocate memory for cb_data by kmalloc, the memory
allocation for eve_data is never freed, add the missing kfree()
in the error handling path.

Fixes: 05e5ba40ea7a ("driver: soc: xilinx: Add support of multiple callbacks for same event in event management driver")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/soc/xilinx/xlnx_event_manager.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michal Simek July 8, 2024, 9:39 a.m. UTC | #1
On 7/6/24 08:51, Gaosheng Cui wrote:
> If we fail to allocate memory for cb_data by kmalloc, the memory
> allocation for eve_data is never freed, add the missing kfree()
> in the error handling path.
> 
> Fixes: 05e5ba40ea7a ("driver: soc: xilinx: Add support of multiple callbacks for same event in event management driver")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
>   drivers/soc/xilinx/xlnx_event_manager.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/xilinx/xlnx_event_manager.c b/drivers/soc/xilinx/xlnx_event_manager.c
> index f529e1346247..85df6b9c04ee 100644
> --- a/drivers/soc/xilinx/xlnx_event_manager.c
> +++ b/drivers/soc/xilinx/xlnx_event_manager.c
> @@ -188,8 +188,10 @@ static int xlnx_add_cb_for_suspend(event_cb_func_t cb_fun, void *data)
>   	INIT_LIST_HEAD(&eve_data->cb_list_head);
>   
>   	cb_data = kmalloc(sizeof(*cb_data), GFP_KERNEL);
> -	if (!cb_data)
> +	if (!cb_data) {
> +		kfree(eve_data);
>   		return -ENOMEM;
> +	}
>   	cb_data->eve_cb = cb_fun;
>   	cb_data->agent_data = data;
>   

Applied.
M
diff mbox series

Patch

diff --git a/drivers/soc/xilinx/xlnx_event_manager.c b/drivers/soc/xilinx/xlnx_event_manager.c
index f529e1346247..85df6b9c04ee 100644
--- a/drivers/soc/xilinx/xlnx_event_manager.c
+++ b/drivers/soc/xilinx/xlnx_event_manager.c
@@ -188,8 +188,10 @@  static int xlnx_add_cb_for_suspend(event_cb_func_t cb_fun, void *data)
 	INIT_LIST_HEAD(&eve_data->cb_list_head);
 
 	cb_data = kmalloc(sizeof(*cb_data), GFP_KERNEL);
-	if (!cb_data)
+	if (!cb_data) {
+		kfree(eve_data);
 		return -ENOMEM;
+	}
 	cb_data->eve_cb = cb_fun;
 	cb_data->agent_data = data;