ipv4: nexthop: Fix deadcode issue by performing a proper NULL check
authorPatrick Eigensatz <patrickeigensatz@gmail.com>
Mon, 1 Jun 2020 11:12:01 +0000 (13:12 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 1 Jun 2020 18:05:35 +0000 (11:05 -0700)
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>
net/ipv4/nexthop.c

index ebafa5ed91ac15c76462a82e426aafbf7b632cd0..400a9f89ebdbd3f358173cbdb92ce3f0dae62e07 100644 (file)
@@ -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;