2022-03-01 14:09:21

by Yeqi Fu

[permalink] [raw]
Subject: [PATCH] dpaa2 ethernet switch driver: Fix memory leak in dpaa2_switch_acl_entry_remove()

[why]
The error handling branch did not properly free the memory of cmd_buf
before return, which would cause memory leak.

[how]
Fix this by adding kfree to the error handling branch.

Signed-off-by: Q1IQ <[email protected]>
---
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
index cacd454ac696..e85ca01718a9 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
@@ -172,6 +172,7 @@ dpaa2_switch_acl_entry_remove(struct dpaa2_switch_filter_block *block,
DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(dev, acl_entry_cfg->key_iova))) {
dev_err(dev, "DMA mapping failed\n");
+ kfree(cmd_buff);
return -EFAULT;
}

@@ -182,6 +183,7 @@ dpaa2_switch_acl_entry_remove(struct dpaa2_switch_filter_block *block,
DMA_TO_DEVICE);
if (err) {
dev_err(dev, "dpsw_acl_remove_entry() failed %d\n", err);
+ kfree(cmd_buff);
return err;
}

--
2.30.1 (Apple Git-130)


2022-03-02 10:24:58

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH] dpaa2 ethernet switch driver: Fix memory leak in dpaa2_switch_acl_entry_remove()

On Tue, 1 Mar 2022 17:24:50 +0800 Q1IQ wrote:
> @@ -182,6 +183,7 @@ dpaa2_switch_acl_entry_remove(struct dpaa2_switch_filter_block *block,
> DMA_TO_DEVICE);
> if (err) {
> dev_err(dev, "dpsw_acl_remove_entry() failed %d\n", err);
> + kfree(cmd_buff);
> return err;
> }

Same comments apply to this patch as to the other patch you sent.