[v3] ethernet: atheros: fix a memleak in atl1e_setup_ring_resources

Message ID 20231214130407.3481513-1-alexious@zju.edu.cn
State New
Headers
Series [v3] ethernet: atheros: fix a memleak in atl1e_setup_ring_resources |

Commit Message

Zhipeng Lu Dec. 14, 2023, 1:04 p.m. UTC
  In the error handling of 'offset > adapter->ring_size', the
tx_ring->tx_buffer allocated by kzalloc should be freed,
instead of 'goto failed' instantly.

Fixes: a6a5325239c2 ("atl1e: Atheros L1E Gigabit Ethernet driver")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
Reviewed-by: Suman Ghosh <sumang@marvell.com>
---

Changelog:

v2: Setting tx_ring->tx_buffer to NULL after free.
v3: Moving free and set-null operation to a new label free_buffer.
---
 drivers/net/ethernet/atheros/atl1e/atl1e_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

patchwork-bot+netdevbpf@kernel.org Dec. 15, 2023, 11 a.m. UTC | #1
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu, 14 Dec 2023 21:04:04 +0800 you wrote:
> In the error handling of 'offset > adapter->ring_size', the
> tx_ring->tx_buffer allocated by kzalloc should be freed,
> instead of 'goto failed' instantly.
> 
> Fixes: a6a5325239c2 ("atl1e: Atheros L1E Gigabit Ethernet driver")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> Reviewed-by: Suman Ghosh <sumang@marvell.com>
> 
> [...]

Here is the summary with links:
  - [v3] ethernet: atheros: fix a memleak in atl1e_setup_ring_resources
    https://git.kernel.org/netdev/net/c/309fdb1c33fe

You are awesome, thank you!
  

Patch

diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
index 5935be190b9e..5f2a6fcba967 100644
--- a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
+++ b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
@@ -866,10 +866,13 @@  static int atl1e_setup_ring_resources(struct atl1e_adapter *adapter)
 		netdev_err(adapter->netdev, "offset(%d) > ring size(%d) !!\n",
 			   offset, adapter->ring_size);
 		err = -1;
-		goto failed;
+		goto free_buffer;
 	}
 
 	return 0;
+free_buffer:
+	kfree(tx_ring->tx_buffer);
+	tx_ring->tx_buffer = NULL;
 failed:
 	if (adapter->ring_vir_addr != NULL) {
 		dma_free_coherent(&pdev->dev, adapter->ring_size,