[IPV4]: Fix memory leak on error path during FIB initialization.
[powerpc.git] / net / ipv4 / fib_frontend.c
index 13bf01d..d0507f4 100644 (file)
@@ -116,7 +116,8 @@ struct fib_table *fib_get_table(struct net *net, u32 id)
 }
 #endif /* CONFIG_IP_MULTIPLE_TABLES */
 
-void fib_select_default(const struct flowi *flp, struct fib_result *res)
+void fib_select_default(struct net *net,
+                       const struct flowi *flp, struct fib_result *res)
 {
        struct fib_table *tb;
        int table = RT_TABLE_MAIN;
@@ -125,7 +126,7 @@ void fib_select_default(const struct flowi *flp, struct fib_result *res)
                return;
        table = res->r->table;
 #endif
-       tb = fib_get_table(&init_net, table);
+       tb = fib_get_table(net, table);
        if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
                tb->tb_select_default(tb, flp, res);
 }
@@ -152,7 +153,7 @@ static void fib_flush(struct net *net)
  *     Find the first device with a given source address.
  */
 
-struct net_device * ip_dev_find(__be32 addr)
+struct net_device * ip_dev_find(struct net *net, __be32 addr)
 {
        struct flowi fl = { .nl_u = { .ip4_u = { .daddr = addr } } };
        struct fib_result res;
@@ -163,7 +164,7 @@ struct net_device * ip_dev_find(__be32 addr)
        res.r = NULL;
 #endif
 
-       local_table = fib_get_table(&init_net, RT_TABLE_LOCAL);
+       local_table = fib_get_table(net, RT_TABLE_LOCAL);
        if (!local_table || local_table->tb_lookup(local_table, &fl, &res))
                return NULL;
        if (res.type != RTN_LOCAL)
@@ -974,6 +975,7 @@ static struct notifier_block fib_netdev_notifier = {
 
 static int __net_init ip_fib_net_init(struct net *net)
 {
+       int err;
        unsigned int i;
 
        net->ipv4.fib_table_hash = kzalloc(
@@ -984,7 +986,14 @@ static int __net_init ip_fib_net_init(struct net *net)
        for (i = 0; i < FIB_TABLE_HASHSZ; i++)
                INIT_HLIST_HEAD(&net->ipv4.fib_table_hash[i]);
 
-       return fib4_rules_init(net);
+       err = fib4_rules_init(net);
+       if (err < 0)
+               goto fail;
+       return 0;
+
+fail:
+       kfree(net->ipv4.fib_table_hash);
+       return err;
 }
 
 static void __net_exit ip_fib_net_exit(struct net *net)