[1/2] reorder: invalidate buf from ready queue in drain

Message ID 20230107151939.2540148-2-vfialko@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series lib/reorder: fix drain/free issues |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Volodymyr Fialko Jan. 7, 2023, 3:19 p.m. UTC
  Set drained buffers from ready queue to NULL, since their ownership
returned to user. Otherwise it's possible that both user and library
will attempt to free the packet.

Signed-off-by: Volodymyr Fialko <vfialko@marvell.com>
---
 lib/reorder/rte_reorder.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Stephen Hemminger Feb. 7, 2023, 4:24 p.m. UTC | #1
On Sat, 7 Jan 2023 16:19:38 +0100
Volodymyr Fialko <vfialko@marvell.com> wrote:

> Set drained buffers from ready queue to NULL, since their ownership
> returned to user. Otherwise it's possible that both user and library
> will attempt to free the packet.
> 
> Signed-off-by: Volodymyr Fialko <vfialko@marvell.com>

Looks correct to me.
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  

Patch

diff --git a/lib/reorder/rte_reorder.c b/lib/reorder/rte_reorder.c
index 385ee479da..b38e71f460 100644
--- a/lib/reorder/rte_reorder.c
+++ b/lib/reorder/rte_reorder.c
@@ -389,6 +389,7 @@  rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
 	/* Try to fetch requested number of mbufs from ready buffer */
 	while ((drain_cnt < max_mbufs) && (ready_buf->tail != ready_buf->head)) {
 		mbufs[drain_cnt++] = ready_buf->entries[ready_buf->tail];
+		ready_buf->entries[ready_buf->tail] = NULL;
 		ready_buf->tail = (ready_buf->tail + 1) & ready_buf->mask;
 	}