diff mbox series

driver: soc: xilinx: fix memory leak in xlnx_add_cb_for_notify_event()

Message ID 20221129010146.1026685-1-cuigaosheng1@huawei.com (mailing list archive)
State New, archived
Headers show
Series driver: soc: xilinx: fix memory leak in xlnx_add_cb_for_notify_event() | expand

Commit Message

cuigaosheng Nov. 29, 2022, 1:01 a.m. UTC
The kfree() should be called when memory fails to be allocated for
cb_data in xlnx_add_cb_for_notify_event(), otherwise there will be
a memory leak, so add kfree() to fix it.

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 Nov. 30, 2022, 5:06 p.m. UTC | #1
On 11/29/22 02:01, Gaosheng Cui wrote:
> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
> 
> 
> The kfree() should be called when memory fails to be allocated for
> cb_data in xlnx_add_cb_for_notify_event(), otherwise there will be
> a memory leak, so add kfree() to fix it.
> 
> 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 2de082765bef..c76381899ef4 100644
> --- a/drivers/soc/xilinx/xlnx_event_manager.c
> +++ b/drivers/soc/xilinx/xlnx_event_manager.c
> @@ -116,8 +116,10 @@ static int xlnx_add_cb_for_notify_event(const u32 node_id, const u32 event, cons
>                  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;
> 
> --
> 2.25.1
> 

Acked-by: Michal Simek <michal.simek@amd.com>

Thanks,
Michal
Michal Simek Dec. 8, 2022, 12:27 p.m. UTC | #2
On 11/29/22 02:01, Gaosheng Cui wrote:
> The kfree() should be called when memory fails to be allocated for
> cb_data in xlnx_add_cb_for_notify_event(), otherwise there will be
> a memory leak, so add kfree() to fix it.
> 
> 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 2de082765bef..c76381899ef4 100644
> --- a/drivers/soc/xilinx/xlnx_event_manager.c
> +++ b/drivers/soc/xilinx/xlnx_event_manager.c
> @@ -116,8 +116,10 @@ static int xlnx_add_cb_for_notify_event(const u32 node_id, const u32 event, cons
>                  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;
> 
> --
> 2.25.1
> 

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 2de082765bef..c76381899ef4 100644
--- a/drivers/soc/xilinx/xlnx_event_manager.c
+++ b/drivers/soc/xilinx/xlnx_event_manager.c
@@ -116,8 +116,10 @@  static int xlnx_add_cb_for_notify_event(const u32 node_id, const u32 event, cons
 		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;