Skip to content

Commit 03d2f89

Browse files
Wang Chenyoshfuji
authored andcommitted
ipv4: Do cleanup for ip_mr_init
Same as ip6_mr_init(), make ip_mr_init() return errno if fails. But do not do error handling in inet_init(), just print a msg. Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com> Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
1 parent 623d1a1 commit 03d2f89

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

include/linux/igmp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
228228
extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
229229
struct group_filter __user *optval, int __user *optlen);
230230
extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt, int dif);
231-
extern void ip_mr_init(void);
232231
extern void ip_mc_init_dev(struct in_device *);
233232
extern void ip_mc_destroy_dev(struct in_device *);
234233
extern void ip_mc_up(struct in_device *);

include/linux/mroute.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ static inline int ip_mroute_opt(int opt)
147147
extern int ip_mroute_setsockopt(struct sock *, int, char __user *, int);
148148
extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
149149
extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
150-
extern void ip_mr_init(void);
151-
150+
extern int ip_mr_init(void);
152151

153152
struct vif_device
154153
{

net/ipv4/af_inet.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,14 +1479,15 @@ static int __init inet_init(void)
14791479
* Initialise the multicast router
14801480
*/
14811481
#if defined(CONFIG_IP_MROUTE)
1482-
ip_mr_init();
1482+
if (ip_mr_init())
1483+
printk(KERN_CRIT "inet_init: Cannot init ipv4 mroute\n");
14831484
#endif
14841485
/*
14851486
* Initialise per-cpu ipv4 mibs
14861487
*/
14871488

14881489
if (init_ipv4_mibs())
1489-
printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ;
1490+
printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n");
14901491

14911492
ipv4_proc_init();
14921493

net/ipv4/ipmr.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,16 +1878,36 @@ static struct net_protocol pim_protocol = {
18781878
* Setup for IP multicast routing
18791879
*/
18801880

1881-
void __init ip_mr_init(void)
1881+
int __init ip_mr_init(void)
18821882
{
1883+
int err;
1884+
18831885
mrt_cachep = kmem_cache_create("ip_mrt_cache",
18841886
sizeof(struct mfc_cache),
18851887
0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
18861888
NULL);
1889+
if (!mrt_cachep)
1890+
return -ENOMEM;
1891+
18871892
setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
1888-
register_netdevice_notifier(&ip_mr_notifier);
1893+
err = register_netdevice_notifier(&ip_mr_notifier);
1894+
if (err)
1895+
goto reg_notif_fail;
18891896
#ifdef CONFIG_PROC_FS
1890-
proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops);
1891-
proc_net_fops_create(&init_net, "ip_mr_cache", 0, &ipmr_mfc_fops);
1897+
err = -ENOMEM;
1898+
if (!proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops))
1899+
goto proc_vif_fail;
1900+
if (!proc_net_fops_create(&init_net, "ip_mr_cache", 0, &ipmr_mfc_fops))
1901+
goto proc_cache_fail;
18921902
#endif
1903+
return 0;
1904+
reg_notif_fail:
1905+
kmem_cache_destroy(mrt_cachep);
1906+
#ifdef CONFIG_PROC_FS
1907+
proc_vif_fail:
1908+
unregister_netdevice_notifier(&ip_mr_notifier);
1909+
proc_cache_fail:
1910+
proc_net_remove(&init_net, "ip_mr_vif");
1911+
#endif
1912+
return err;
18931913
}

0 commit comments

Comments
 (0)