[PATCH nf-next,v3 3/5] net: do not advance stack index from dev_fwd_path()

Pablo Neira Ayuso <[email protected]> Tue, 28 Jul 2026 13:09:40 +0200
Newsgroups gmane.comp.security.firewalls.netfilter.devel
Message-ID <[email protected]>
Update stack index from dev_fill_forward_path() instead, once the
forward path slot has been populated.

Adjust existing drivers that recycle dev_fill_forward_path() as a
way to reach the mtk SoC WDMA info.

Acked-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
---
v3: remove k index variable per Lorenzo.

 drivers/net/ethernet/airoha/airoha_ppe.c        | 2 +-
 drivers/net/ethernet/mediatek/mtk_ppe_offload.c | 2 +-
 net/core/dev.c                                  | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/airoha/airoha_ppe.c b/drivers/net/ethernet/airoha/airoha_ppe.c
index e4c3644dd6ec..72755ca974fa 100644
--- a/drivers/net/ethernet/airoha/airoha_ppe.c
+++ b/drivers/net/ethernet/airoha/airoha_ppe.c
@@ -292,7 +292,7 @@ static int airoha_ppe_get_wdma_info(struct net_device *dev, const u8 *addr,
 	if (err)
 		return err;
 
-	path = &stack.path[stack.num_paths - 1];
+	path = &stack.path[stack.num_paths];
 	if (path->type != DEV_PATH_MTK_WDMA)
 		return -EINVAL;
 
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
index cc8c4ef8038f..7dab360b8be3 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -107,7 +107,7 @@ mtk_flow_get_wdma_info(struct net_device *dev, const u8 *addr, struct mtk_wdma_i
 	if (err)
 		return err;
 
-	path = &stack.path[stack.num_paths - 1];
+	path = &stack.path[stack.num_paths];
 	if (path->type != DEV_PATH_MTK_WDMA)
 		return -1;
 
diff --git a/net/core/dev.c b/net/core/dev.c
index c1c1be1a6962..96c01f6e9dea 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -742,12 +742,10 @@ EXPORT_SYMBOL_GPL(dev_fill_metadata_dst);
 
 static struct net_device_path *dev_fwd_path(struct net_device_path_stack *stack)
 {
-	int k = stack->num_paths++;
-
-	if (k >= NET_DEVICE_PATH_STACK_MAX)
+	if (stack->num_paths + 1 >= NET_DEVICE_PATH_STACK_MAX)
 		return NULL;
 
-	return &stack->path[k];
+	return &stack->path[stack->num_paths];
 }
 
 int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
@@ -773,6 +771,7 @@ int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
 		if (ret < 0)
 			return -1;
 
+		stack->num_paths++;
 		if (WARN_ON_ONCE(last_dev == ctx.dev))
 			return -1;
 	}
@@ -785,6 +784,7 @@ int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
 		return -1;
 	path->type = DEV_PATH_ETHERNET;
 	path->dev = ctx.dev;
+	stack->num_paths++;
 
 	return ret;
 }
-- 
2.47.3