mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 net] net: lan743x: Fix memory leak when GSO enabled
@ 2025-04-25  4:28 Thangaraj Samynathan
  2025-04-25  9:38 ` [PATCH " Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Thangaraj Samynathan @ 2025-04-25  4:28 UTC (permalink / raw)
  To: netdev
  Cc: bryan.whitehead, UNGLinuxDriver, andrew+netdev, davem, edumazet,
	kuba, pabeni, linux-kernel

The current implementation tracks the `skb` by linking it to the
LS descriptor when the  number of fragments is greater than zero,
and to the EXT descriptor when the number of fragments is zero
with GSO enabled. However, when the `skb` is mapped to the EXT
descriptor, it is not freed resulting in a memory leak. The
implementation has been modified to always map the `skb` to the
last descriptor and always be properly freed.

Fixes: 23f0703c125b ("lan743x: Add main source files for new lan743x driver")
Signed-off-by: Thangaraj Samynathan <thangaraj.s@microchip.com>
---
 drivers/net/ethernet/microchip/lan743x_main.c | 8 ++++++--
 drivers/net/ethernet/microchip/lan743x_main.h | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index 8b6b9b6efe18..73dfc85fa67e 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -1815,6 +1815,7 @@ static void lan743x_tx_frame_add_lso(struct lan743x_tx *tx,
 	if (nr_frags <= 0) {
 		tx->frame_data0 |= TX_DESC_DATA0_LS_;
 		tx->frame_data0 |= TX_DESC_DATA0_IOC_;
+		tx->frame_last = tx->frame_first;
 	}
 	tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail];
 	tx_descriptor->data0 = cpu_to_le32(tx->frame_data0);
@@ -1884,6 +1885,7 @@ static int lan743x_tx_frame_add_fragment(struct lan743x_tx *tx,
 		tx->frame_first = 0;
 		tx->frame_data0 = 0;
 		tx->frame_tail = 0;
+		tx->frame_last = 0;
 		return -ENOMEM;
 	}
 
@@ -1924,16 +1926,18 @@ static void lan743x_tx_frame_end(struct lan743x_tx *tx,
 	    TX_DESC_DATA0_DTYPE_DATA_) {
 		tx->frame_data0 |= TX_DESC_DATA0_LS_;
 		tx->frame_data0 |= TX_DESC_DATA0_IOC_;
+		tx->frame_last = tx->frame_tail;
 	}
 
-	tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail];
-	buffer_info = &tx->buffer_info[tx->frame_tail];
+	tx_descriptor = &tx->ring_cpu_ptr[tx->frame_last];
+	buffer_info = &tx->buffer_info[tx->frame_last];
 	buffer_info->skb = skb;
 	if (time_stamp)
 		buffer_info->flags |= TX_BUFFER_INFO_FLAG_TIMESTAMP_REQUESTED;
 	if (ignore_sync)
 		buffer_info->flags |= TX_BUFFER_INFO_FLAG_IGNORE_SYNC;
 
+	tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail];
 	tx_descriptor->data0 = cpu_to_le32(tx->frame_data0);
 	tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail);
 	tx->last_tail = tx->frame_tail;
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 7f73d66854be..db5fc73e41cc 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -980,6 +980,7 @@ struct lan743x_tx {
 	u32		frame_first;
 	u32		frame_data0;
 	u32		frame_tail;
+	u32		frame_last;
 
 	struct lan743x_tx_buffer_info *buffer_info;
 
-- 
2.25.1


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

* Re: [PATCH net] net: lan743x: Fix memory leak when GSO enabled
  2025-04-25  4:28 [PATCH v1 net] net: lan743x: Fix memory leak when GSO enabled Thangaraj Samynathan
@ 2025-04-25  9:38 ` Markus Elfring
  2025-04-28  4:37   ` Thangaraj.S
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2025-04-25  9:38 UTC (permalink / raw)
  To: Thangaraj Samynathan, netdev, UNGLinuxDriver
  Cc: LKML, Andrew Lunn, Bryan Whitehead, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

…
> implementation has been modified to always map the `skb` to the
> last descriptor and always be properly freed.

See also:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.15-rc3#n94

Regards,
Markus

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

* Re: [PATCH net] net: lan743x: Fix memory leak when GSO enabled
  2025-04-25  9:38 ` [PATCH " Markus Elfring
@ 2025-04-28  4:37   ` Thangaraj.S
  0 siblings, 0 replies; 3+ messages in thread
From: Thangaraj.S @ 2025-04-28  4:37 UTC (permalink / raw)
  To: Markus.Elfring, netdev, UNGLinuxDriver
  Cc: pabeni, kuba, edumazet, linux-kernel, andrew+netdev,
	Bryan.Whitehead, davem

Hi Markus,
Thanks for your comments.
Will update the description and send the patch again for review.

Thanks,
Thangaraj Samynathan
On Fri, 2025-04-25 at 11:38 +0200, Markus Elfring wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> …
> > implementation has been modified to always map the `skb` to the
> > last descriptor and always be properly freed.
> 
> See also:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.15-rc3#n94
> 
> Regards,
> Markus

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

end of thread, other threads:[~2025-04-28  4:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-25  4:28 [PATCH v1 net] net: lan743x: Fix memory leak when GSO enabled Thangaraj Samynathan
2025-04-25  9:38 ` [PATCH " Markus Elfring
2025-04-28  4:37   ` Thangaraj.S

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

all inboxes | Powered by JetHome®