[PATCH net-next 5/9] net: do not advance stack index from dev_fwd_path()
Pablo Neira Ayuso <[email protected]> Fri, 31 Jul 2026 17:33:58 +0200
| Newsgroups | gmane.comp.security.firewalls.netfilter.devel,gmane.linux.network |
|---|---|
| Message-ID | <[email protected]> |
Update stack index from dev_fill_forward_path() instead, once the forward path slot has been populated. Acked-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> --- net/core/dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index c1c1be1a6962..429a55fff667 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