nexthop: Fix off-by-one error in error path
authorIdo Schimmel <idosch@nvidia.com>
Thu, 7 Jan 2021 14:48:21 +0000 (16:48 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 17 Jan 2021 13:16:57 +0000 (14:16 +0100)
[ Upstream commit 07e61a979ca4dddb3661f59328b3cd109f6b0070 ]

A reference was not taken for the current nexthop entry, so do not try
to put it in the error path.

Fixes: 430a049190de ("nexthop: Add support for nexthop groups")
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/nexthop.c

index 0dc43ad..2f0fed9 100644 (file)
@@ -1277,7 +1277,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
        return nh;
 
 out_no_nh:
-       for (; i >= 0; --i)
+       for (i--; i >= 0; --i)
                nexthop_put(nhg->nh_entries[i].nh);
 
        kfree(nhg->spare);