Skip to content

Commit

Permalink
ipv4: nexthop: Fix deadcode issue by performing a proper NULL check
Browse files Browse the repository at this point in the history
After allocating the spare nexthop group it should be tested for kzalloc()
returning NULL, instead the already used nexthop group (which cannot be
NULL at this point) had been tested so far.

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885
Reported-by: Coverity <scan-admin@coverity.com>
Signed-off-by: Patrick Eigensatz <patrickeigensatz@gmail.com>
Acked-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Patrick Eigensatz authored and David S. Miller committed Jun 1, 2020
1 parent 07f6ece commit dafe207
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/ipv4/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,10 +1185,10 @@ static struct nexthop *nexthop_create_group(struct net *net,

/* spare group used for removals */
nhg->spare = nexthop_grp_alloc(num_nh);
if (!nhg) {
if (!nhg->spare) {
kfree(nhg);
kfree(nh);
return NULL;
return ERR_PTR(-ENOMEM);
}
nhg->spare->spare = nhg;

Expand Down

0 comments on commit dafe207

Please sign in to comment.