Netdev List
 help / color / mirror / Atom feed
* [PATCH] dpaa2 ethernet switch driver: Fix memory leak in dpaa2_switch_acl_entry_add()
@ 2022-03-01  9:34 Q1IQ
  2022-03-01 12:14 ` Denis Kirjanov
  0 siblings, 1 reply; 5+ messages in thread
From: Q1IQ @ 2022-03-01  9:34 UTC (permalink / raw)
  To: ioana.ciornei, davem, kuba; +Cc: netdev, linux-kernel, lyz_cs, Q1IQ

[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 <fufuyqqqqqq@gmail.com>
---
 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..4d07aee07f4c 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
@@ -132,6 +132,7 @@ int dpaa2_switch_acl_entry_add(struct dpaa2_switch_filter_block *filter_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;
 	}
 
@@ -142,6 +143,7 @@ int dpaa2_switch_acl_entry_add(struct dpaa2_switch_filter_block *filter_block,
 			 DMA_TO_DEVICE);
 	if (err) {
 		dev_err(dev, "dpsw_acl_add_entry() failed %d\n", err);
+		kfree(cmd_buff);
 		return err;
 	}
 
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-02  1:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-01  9:34 [PATCH] dpaa2 ethernet switch driver: Fix memory leak in dpaa2_switch_acl_entry_add() Q1IQ
2022-03-01 12:14 ` Denis Kirjanov
2022-03-01 14:15   ` [PATCH v1] dpaa2-switch: fix memory leak of dpaa2_switch_acl_entry_add Yeqi Fu
2022-03-01 17:03     ` Ioana Ciornei
2022-03-02  1:41     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox