X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=net%2Fnetlink%2Faf_netlink.c;h=e6c285edeb54f2418ca28df00d8e030b47706536;hb=9464c7cf61b9433057924c36e6e02f303a00e768;hp=1d28cbcfe71811bd835e6f82e64ac098e978ee73;hpb=41689045f6a3cbe0550e1d34e9cc20d2e8c432ba;p=linux-2.6.git diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 1d28cbcfe..e6c285ede 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -21,6 +21,7 @@ * mandatory if CONFIG_NET=y these days */ +#include #include #include @@ -160,7 +161,7 @@ static void netlink_sock_destruct(struct sock *sk) static void netlink_table_grab(void) { - write_lock_irq(&nl_table_lock); + write_lock_bh(&nl_table_lock); if (atomic_read(&nl_table_users)) { DECLARE_WAITQUEUE(wait, current); @@ -170,9 +171,9 @@ static void netlink_table_grab(void) set_current_state(TASK_UNINTERRUPTIBLE); if (atomic_read(&nl_table_users) == 0) break; - write_unlock_irq(&nl_table_lock); + write_unlock_bh(&nl_table_lock); schedule(); - write_lock_irq(&nl_table_lock); + write_lock_bh(&nl_table_lock); } __set_current_state(TASK_RUNNING); @@ -182,7 +183,7 @@ static void netlink_table_grab(void) static __inline__ void netlink_table_ungrab(void) { - write_unlock_irq(&nl_table_lock); + write_unlock_bh(&nl_table_lock); wake_up(&nl_table_wait); } @@ -566,9 +567,10 @@ static int netlink_alloc_groups(struct sock *sk) if (err) return err; - nlk->groups = kzalloc(NLGRPSZ(groups), GFP_KERNEL); + nlk->groups = kmalloc(NLGRPSZ(groups), GFP_KERNEL); if (nlk->groups == NULL) return -ENOMEM; + memset(nlk->groups, 0, NLGRPSZ(groups)); nlk->ngroups = groups; return 0; } @@ -1277,7 +1279,8 @@ netlink_kernel_create(int unit, unsigned int groups, struct netlink_sock *nlk; unsigned long *listeners = NULL; - BUG_ON(!nl_table); + if (!nl_table) + return NULL; if (unit<0 || unit>=MAX_LINKS) return NULL; @@ -1395,10 +1398,11 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, struct sock *sk; struct netlink_sock *nlk; - cb = kzalloc(sizeof(*cb), GFP_KERNEL); + cb = kmalloc(sizeof(*cb), GFP_KERNEL); if (cb == NULL) return -ENOBUFS; + memset(cb, 0, sizeof(*cb)); cb->dump = dump; cb->done = done; cb->nlh = nlh; @@ -1669,7 +1673,7 @@ static int netlink_seq_open(struct inode *inode, struct file *file) struct nl_seq_iter *iter; int err; - iter = kzalloc(sizeof(*iter), GFP_KERNEL); + iter = kmalloc(sizeof(*iter), GFP_KERNEL); if (!iter) return -ENOMEM; @@ -1679,6 +1683,7 @@ static int netlink_seq_open(struct inode *inode, struct file *file) return err; } + memset(iter, 0, sizeof(*iter)); seq = file->private_data; seq->private = iter; return 0; @@ -1747,9 +1752,14 @@ static int __init netlink_proto_init(void) if (sizeof(struct netlink_skb_parms) > sizeof(dummy_skb->cb)) netlink_skb_parms_too_large(); - nl_table = kcalloc(MAX_LINKS, sizeof(*nl_table), GFP_KERNEL); - if (!nl_table) - goto panic; + nl_table = kmalloc(sizeof(*nl_table) * MAX_LINKS, GFP_KERNEL); + if (!nl_table) { +enomem: + printk(KERN_CRIT "netlink_init: Cannot allocate nl_table\n"); + return -ENOMEM; + } + + memset(nl_table, 0, sizeof(*nl_table) * MAX_LINKS); if (num_physpages >= (128 * 1024)) max = num_physpages >> (21 - PAGE_SHIFT); @@ -1769,7 +1779,7 @@ static int __init netlink_proto_init(void) nl_pid_hash_free(nl_table[i].hash.table, 1 * sizeof(*hash->table)); kfree(nl_table); - goto panic; + goto enomem; } memset(hash->table, 0, 1 * sizeof(*hash->table)); hash->max_shift = order; @@ -1786,8 +1796,6 @@ static int __init netlink_proto_init(void) rtnetlink_init(); out: return err; -panic: - panic("netlink_init: Cannot allocate nl_table\n"); } core_initcall(netlink_proto_init);