Commit 0da974f4 authored by Panagiotis Issaris's avatar Panagiotis Issaris Committed by David S. Miller
Browse files

[NET]: Conversions from kmalloc+memset to k(z|c)alloc.

Signed-off-by: default avatarPanagiotis Issaris <takis@issaris.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a0ee7c70
...@@ -542,12 +542,11 @@ static struct net_device *register_vlan_device(const char *eth_IF_name, ...@@ -542,12 +542,11 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
* so it cannot "appear" on us. * so it cannot "appear" on us.
*/ */
if (!grp) { /* need to add a new group */ if (!grp) { /* need to add a new group */
grp = kmalloc(sizeof(struct vlan_group), GFP_KERNEL); grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL);
if (!grp) if (!grp)
goto out_free_unregister; goto out_free_unregister;
/* printk(KERN_ALERT "VLAN REGISTER: Allocated new group.\n"); */ /* printk(KERN_ALERT "VLAN REGISTER: Allocated new group.\n"); */
memset(grp, 0, sizeof(struct vlan_group));
grp->real_dev_ifindex = real_dev->ifindex; grp->real_dev_ifindex = real_dev->ifindex;
hlist_add_head_rcu(&grp->hlist, hlist_add_head_rcu(&grp->hlist,
......
...@@ -227,12 +227,11 @@ static void atif_drop_device(struct net_device *dev) ...@@ -227,12 +227,11 @@ static void atif_drop_device(struct net_device *dev)
static struct atalk_iface *atif_add_device(struct net_device *dev, static struct atalk_iface *atif_add_device(struct net_device *dev,
struct atalk_addr *sa) struct atalk_addr *sa)
{ {
struct atalk_iface *iface = kmalloc(sizeof(*iface), GFP_KERNEL); struct atalk_iface *iface = kzalloc(sizeof(*iface), GFP_KERNEL);
if (!iface) if (!iface)
goto out; goto out;
memset(iface, 0, sizeof(*iface));
dev_hold(dev); dev_hold(dev);
iface->dev = dev; iface->dev = dev;
dev->atalk_ptr = iface; dev->atalk_ptr = iface;
...@@ -559,12 +558,11 @@ static int atrtr_create(struct rtentry *r, struct net_device *devhint) ...@@ -559,12 +558,11 @@ static int atrtr_create(struct rtentry *r, struct net_device *devhint)
} }
if (!rt) { if (!rt) {
rt = kmalloc(sizeof(*rt), GFP_ATOMIC); rt = kzalloc(sizeof(*rt), GFP_ATOMIC);
retval = -ENOBUFS; retval = -ENOBUFS;
if (!rt) if (!rt)
goto out_unlock; goto out_unlock;
memset(rt, 0, sizeof(*rt));
rt->next = atalk_routes; rt->next = atalk_routes;
atalk_routes = rt; atalk_routes = rt;
......
...@@ -508,10 +508,9 @@ Note: we do not have explicit unassign, but look at _push() ...@@ -508,10 +508,9 @@ Note: we do not have explicit unassign, but look at _push()
if (copy_from_user(&be, arg, sizeof be)) if (copy_from_user(&be, arg, sizeof be))
return -EFAULT; return -EFAULT;
brvcc = kmalloc(sizeof(struct br2684_vcc), GFP_KERNEL); brvcc = kzalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
if (!brvcc) if (!brvcc)
return -ENOMEM; return -ENOMEM;
memset(brvcc, 0, sizeof(struct br2684_vcc));
write_lock_irq(&devs_lock); write_lock_irq(&devs_lock);
net_dev = br2684_find_dev(&be.ifspec); net_dev = br2684_find_dev(&be.ifspec);
if (net_dev == NULL) { if (net_dev == NULL) {
......
...@@ -929,12 +929,11 @@ static int arp_seq_open(struct inode *inode, struct file *file) ...@@ -929,12 +929,11 @@ static int arp_seq_open(struct inode *inode, struct file *file)
struct seq_file *seq; struct seq_file *seq;
int rc = -EAGAIN; int rc = -EAGAIN;
state = kmalloc(sizeof(*state), GFP_KERNEL); state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state) { if (!state) {
rc = -ENOMEM; rc = -ENOMEM;
goto out_kfree; goto out_kfree;
} }
memset(state, 0, sizeof(*state));
state->ns.neigh_sub_iter = clip_seq_sub_iter; state->ns.neigh_sub_iter = clip_seq_sub_iter;
rc = seq_open(file, &arp_seq_ops); rc = seq_open(file, &arp_seq_ops);
......
...@@ -1811,12 +1811,11 @@ make_entry(struct lec_priv *priv, unsigned char *mac_addr) ...@@ -1811,12 +1811,11 @@ make_entry(struct lec_priv *priv, unsigned char *mac_addr)
{ {
struct lec_arp_table *to_return; struct lec_arp_table *to_return;
to_return = kmalloc(sizeof(struct lec_arp_table), GFP_ATOMIC); to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
if (!to_return) { if (!to_return) {
printk("LEC: Arp entry kmalloc failed\n"); printk("LEC: Arp entry kmalloc failed\n");
return NULL; return NULL;
} }
memset(to_return, 0, sizeof(struct lec_arp_table));
memcpy(to_return->mac_addr, mac_addr, ETH_ALEN); memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
init_timer(&to_return->timer); init_timer(&to_return->timer);
to_return->timer.function = lec_arp_expire_arp; to_return->timer.function = lec_arp_expire_arp;
......
...@@ -258,10 +258,9 @@ static struct mpoa_client *alloc_mpc(void) ...@@ -258,10 +258,9 @@ static struct mpoa_client *alloc_mpc(void)
{ {
struct mpoa_client *mpc; struct mpoa_client *mpc;
mpc = kmalloc(sizeof (struct mpoa_client), GFP_KERNEL); mpc = kzalloc(sizeof (struct mpoa_client), GFP_KERNEL);
if (mpc == NULL) if (mpc == NULL)
return NULL; return NULL;
memset(mpc, 0, sizeof(struct mpoa_client));
rwlock_init(&mpc->ingress_lock); rwlock_init(&mpc->ingress_lock);
rwlock_init(&mpc->egress_lock); rwlock_init(&mpc->egress_lock);
mpc->next = mpcs; mpc->next = mpcs;
......
...@@ -287,10 +287,9 @@ static int pppoatm_assign_vcc(struct atm_vcc *atmvcc, void __user *arg) ...@@ -287,10 +287,9 @@ static int pppoatm_assign_vcc(struct atm_vcc *atmvcc, void __user *arg)
if (be.encaps != PPPOATM_ENCAPS_AUTODETECT && if (be.encaps != PPPOATM_ENCAPS_AUTODETECT &&
be.encaps != PPPOATM_ENCAPS_VC && be.encaps != PPPOATM_ENCAPS_LLC) be.encaps != PPPOATM_ENCAPS_VC && be.encaps != PPPOATM_ENCAPS_LLC)
return -EINVAL; return -EINVAL;
pvcc = kmalloc(sizeof(*pvcc), GFP_KERNEL); pvcc = kzalloc(sizeof(*pvcc), GFP_KERNEL);
if (pvcc == NULL) if (pvcc == NULL)
return -ENOMEM; return -ENOMEM;
memset(pvcc, 0, sizeof(*pvcc));
pvcc->atmvcc = atmvcc; pvcc->atmvcc = atmvcc;
pvcc->old_push = atmvcc->push; pvcc->old_push = atmvcc->push;
pvcc->old_pop = atmvcc->pop; pvcc->old_pop = atmvcc->pop;
......
...@@ -33,10 +33,9 @@ static struct atm_dev *__alloc_atm_dev(const char *type) ...@@ -33,10 +33,9 @@ static struct atm_dev *__alloc_atm_dev(const char *type)
{ {
struct atm_dev *dev; struct atm_dev *dev;
dev = kmalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return NULL; return NULL;
memset(dev, 0, sizeof(*dev));
dev->type = type; dev->type = type;
dev->signal = ATM_PHY_SIG_UNKNOWN; dev->signal = ATM_PHY_SIG_UNKNOWN;
dev->link_rate = ATM_OC3_PCR; dev->link_rate = ATM_OC3_PCR;
......
...@@ -203,13 +203,11 @@ void ax25_register_sysctl(void) ...@@ -203,13 +203,11 @@ void ax25_register_sysctl(void)
for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
ax25_table_size += sizeof(ctl_table); ax25_table_size += sizeof(ctl_table);
if ((ax25_table = kmalloc(ax25_table_size, GFP_ATOMIC)) == NULL) { if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
spin_unlock_bh(&ax25_dev_lock); spin_unlock_bh(&ax25_dev_lock);
return; return;
} }
memset(ax25_table, 0x00, ax25_table_size);
for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) { for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
ctl_table *child = kmalloc(sizeof(ax25_param_table), GFP_ATOMIC); ctl_table *child = kmalloc(sizeof(ax25_param_table), GFP_ATOMIC);
if (!child) { if (!child) {
......
...@@ -162,12 +162,10 @@ static int old_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) ...@@ -162,12 +162,10 @@ static int old_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
if (num > BR_MAX_PORTS) if (num > BR_MAX_PORTS)
num = BR_MAX_PORTS; num = BR_MAX_PORTS;
indices = kmalloc(num*sizeof(int), GFP_KERNEL); indices = kcalloc(num, sizeof(int), GFP_KERNEL);
if (indices == NULL) if (indices == NULL)
return -ENOMEM; return -ENOMEM;
memset(indices, 0, num*sizeof(int));
get_port_ifindices(br, indices, num); get_port_ifindices(br, indices, num);
if (copy_to_user((void __user *)args[1], indices, num*sizeof(int))) if (copy_to_user((void __user *)args[1], indices, num*sizeof(int)))
num = -EFAULT; num = -EFAULT;
...@@ -327,11 +325,10 @@ static int old_deviceless(void __user *uarg) ...@@ -327,11 +325,10 @@ static int old_deviceless(void __user *uarg)
if (args[2] >= 2048) if (args[2] >= 2048)
return -ENOMEM; return -ENOMEM;
indices = kmalloc(args[2]*sizeof(int), GFP_KERNEL); indices = kcalloc(args[2], sizeof(int), GFP_KERNEL);
if (indices == NULL) if (indices == NULL)
return -ENOMEM; return -ENOMEM;
memset(indices, 0, args[2]*sizeof(int));
args[2] = get_bridge_ifindices(indices, args[2]); args[2] = get_bridge_ifindices(indices, args[2]);
ret = copy_to_user((void __user *)args[1], indices, args[2]*sizeof(int)) ret = copy_to_user((void __user *)args[1], indices, args[2]*sizeof(int))
......
...@@ -413,11 +413,7 @@ static struct dn_ifaddr *dn_dev_alloc_ifa(void) ...@@ -413,11 +413,7 @@ static struct dn_ifaddr *dn_dev_alloc_ifa(void)
{ {
struct dn_ifaddr *ifa; struct dn_ifaddr *ifa;
ifa = kmalloc(sizeof(*ifa), GFP_KERNEL); ifa = kzalloc(sizeof(*ifa), GFP_KERNEL);
if (ifa) {
memset(ifa, 0, sizeof(*ifa));
}
return ifa; return ifa;
} }
...@@ -1105,10 +1101,9 @@ struct dn_dev *dn_dev_create(struct net_device *dev, int *err) ...@@ -1105,10 +1101,9 @@ struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
return NULL; return NULL;
*err = -ENOBUFS; *err = -ENOBUFS;
if ((dn_db = kmalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL) if ((dn_db = kzalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
return NULL; return NULL;
memset(dn_db, 0, sizeof(struct dn_dev));
memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms)); memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
smp_wmb(); smp_wmb();
dev->dn_ptr = dn_db; dev->dn_ptr = dn_db;
......
...@@ -283,11 +283,10 @@ struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r, struct dn_kern_rta ...@@ -283,11 +283,10 @@ struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r, struct dn_kern_rta
goto err_inval; goto err_inval;
} }
fi = kmalloc(sizeof(*fi)+nhs*sizeof(struct dn_fib_nh), GFP_KERNEL); fi = kzalloc(sizeof(*fi)+nhs*sizeof(struct dn_fib_nh), GFP_KERNEL);
err = -ENOBUFS; err = -ENOBUFS;
if (fi == NULL) if (fi == NULL)
goto failure; goto failure;
memset(fi, 0, sizeof(*fi)+nhs*sizeof(struct dn_fib_nh));
fi->fib_protocol = r->rtm_protocol; fi->fib_protocol = r->rtm_protocol;
fi->fib_nhs = nhs; fi->fib_nhs = nhs;
......
...@@ -580,12 +580,11 @@ static int dn_neigh_seq_open(struct inode *inode, struct file *file) ...@@ -580,12 +580,11 @@ static int dn_neigh_seq_open(struct inode *inode, struct file *file)
{ {
struct seq_file *seq; struct seq_file *seq;
int rc = -ENOMEM; int rc = -ENOMEM;
struct neigh_seq_state *s = kmalloc(sizeof(*s), GFP_KERNEL); struct neigh_seq_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s) if (!s)
goto out; goto out;
memset(s, 0, sizeof(*s));
rc = seq_open(file, &dn_neigh_seq_ops); rc = seq_open(file, &dn_neigh_seq_ops);
if (rc) if (rc)
goto out_kfree; goto out_kfree;
......
...@@ -151,10 +151,9 @@ int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -151,10 +151,9 @@ int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
} }
} }
new_r = kmalloc(sizeof(*new_r), GFP_KERNEL); new_r = kzalloc(sizeof(*new_r), GFP_KERNEL);
if (!new_r) if (!new_r)
return -ENOMEM; return -ENOMEM;
memset(new_r, 0, sizeof(*new_r));
if (rta[RTA_SRC-1]) if (rta[RTA_SRC-1])
memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 2); memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 2);
......
...@@ -158,12 +158,10 @@ static void dn_rehash_zone(struct dn_zone *dz) ...@@ -158,12 +158,10 @@ static void dn_rehash_zone(struct dn_zone *dz)
break; break;
} }
ht = kmalloc(new_divisor*sizeof(struct dn_fib_node*), GFP_KERNEL); ht = kcalloc(new_divisor, sizeof(struct dn_fib_node*), GFP_KERNEL);
if (ht == NULL) if (ht == NULL)
return; return;
memset(ht, 0, new_divisor*sizeof(struct dn_fib_node *));
write_lock_bh(&dn_fib_tables_lock); write_lock_bh(&dn_fib_tables_lock);
old_ht = dz->dz_hash; old_ht = dz->dz_hash;
dz->dz_hash = ht; dz->dz_hash = ht;
...@@ -184,11 +182,10 @@ static void dn_free_node(struct dn_fib_node *f) ...@@ -184,11 +182,10 @@ static void dn_free_node(struct dn_fib_node *f)
static struct dn_zone *dn_new_zone(struct dn_hash *table, int z) static struct dn_zone *dn_new_zone(struct dn_hash *table, int z)
{ {
int i; int i;
struct dn_zone *dz = kmalloc(sizeof(struct dn_zone), GFP_KERNEL); struct dn_zone *dz = kzalloc(sizeof(struct dn_zone), GFP_KERNEL);
if (!dz) if (!dz)
return NULL; return NULL;
memset(dz, 0, sizeof(struct dn_zone));
if (z) { if (z) {
dz->dz_divisor = 16; dz->dz_divisor = 16;
dz->dz_hashmask = 0x0F; dz->dz_hashmask = 0x0F;
...@@ -197,14 +194,12 @@ static struct dn_zone *dn_new_zone(struct dn_hash *table, int z) ...@@ -197,14 +194,12 @@ static struct dn_zone *dn_new_zone(struct dn_hash *table, int z)
dz->dz_hashmask = 0; dz->dz_hashmask = 0;
} }
dz->dz_hash = kmalloc(dz->dz_divisor*sizeof(struct dn_fib_node *), GFP_KERNEL); dz->dz_hash = kcalloc(dz->dz_divisor, sizeof(struct dn_fib_node *), GFP_KERNEL);
if (!dz->dz_hash) { if (!dz->dz_hash) {
kfree(dz); kfree(dz);
return NULL; return NULL;
} }
memset(dz->dz_hash, 0, dz->dz_divisor*sizeof(struct dn_fib_node*));
dz->dz_order = z; dz->dz_order = z;
dz->dz_mask = dnet_make_mask(z); dz->dz_mask = dnet_make_mask(z);
......
...@@ -673,12 +673,11 @@ static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg) ...@@ -673,12 +673,11 @@ static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg)
edev = dev->ec_ptr; edev = dev->ec_ptr;
if (edev == NULL) { if (edev == NULL) {
/* Magic up a new one. */ /* Magic up a new one. */
edev = kmalloc(sizeof(struct ec_device), GFP_KERNEL); edev = kzalloc(sizeof(struct ec_device), GFP_KERNEL);
if (edev == NULL) { if (edev == NULL) {
err = -ENOMEM; err = -ENOMEM;
break; break;
} }
memset(edev, 0, sizeof(struct ec_device));
dev->ec_ptr = edev; dev->ec_ptr = edev;
} else } else
net2dev_map[edev->net] = NULL; net2dev_map[edev->net] = NULL;
......
...@@ -110,11 +110,10 @@ int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops) ...@@ -110,11 +110,10 @@ int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops)
unsigned long flags; unsigned long flags;
struct ieee80211_crypto_alg *alg; struct ieee80211_crypto_alg *alg;
alg = kmalloc(sizeof(*alg), GFP_KERNEL); alg = kzalloc(sizeof(*alg), GFP_KERNEL);
if (alg == NULL) if (alg == NULL)
return -ENOMEM; return -ENOMEM;
memset(alg, 0, sizeof(*alg));
alg->ops = ops; alg->ops = ops;
spin_lock_irqsave(&ieee80211_crypto_lock, flags); spin_lock_irqsave(&ieee80211_crypto_lock, flags);
......
...@@ -76,10 +76,9 @@ static void *ieee80211_ccmp_init(int key_idx) ...@@ -76,10 +76,9 @@ static void *ieee80211_ccmp_init(int key_idx)
{ {
struct ieee80211_ccmp_data *priv; struct ieee80211_ccmp_data *priv;
priv = kmalloc(sizeof(*priv), GFP_ATOMIC); priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL) if (priv == NULL)
goto fail; goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = key_idx; priv->key_idx = key_idx;
priv->tfm = crypto_alloc_tfm("aes", 0); priv->tfm = crypto_alloc_tfm("aes", 0);
......
...@@ -39,10 +39,9 @@ static void *prism2_wep_init(int keyidx) ...@@ -39,10 +39,9 @@ static void *prism2_wep_init(int keyidx)
{ {
struct prism2_wep_data *priv; struct prism2_wep_data *priv;
priv = kmalloc(sizeof(*priv), GFP_ATOMIC); priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL) if (priv == NULL)
goto fail; goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = keyidx; priv->key_idx = keyidx;
priv->tfm = crypto_alloc_tfm("arc4", 0); priv->tfm = crypto_alloc_tfm("arc4", 0);
......
...@@ -369,11 +369,10 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee, ...@@ -369,11 +369,10 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
struct ieee80211_crypt_data *new_crypt; struct ieee80211_crypt_data *new_crypt;
/* take WEP into use */ /* take WEP into use */
new_crypt = kmalloc(sizeof(struct ieee80211_crypt_data), new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
GFP_KERNEL); GFP_KERNEL);
if (new_crypt == NULL) if (new_crypt == NULL)
return -ENOMEM; return -ENOMEM;
memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
new_crypt->ops = ieee80211_get_crypto_ops("WEP"); new_crypt->ops = ieee80211_get_crypto_ops("WEP");
if (!new_crypt->ops) { if (!new_crypt->ops) {
request_module("ieee80211_crypt_wep"); request_module("ieee80211_crypt_wep");
...@@ -616,13 +615,11 @@ int ieee80211_wx_set_encodeext(struct ieee80211_device *ieee, ...@@ -616,13 +615,11 @@ int ieee80211_wx_set_encodeext(struct ieee80211_device *ieee,
ieee80211_crypt_delayed_deinit(ieee, crypt); ieee80211_crypt_delayed_deinit(ieee, crypt);
new_crypt = (struct ieee80211_crypt_data *) new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
kmalloc(sizeof(*new_crypt), GFP_KERNEL);
if (new_crypt == NULL) { if (new_crypt == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto done; goto done;
} }
memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
new_crypt->ops = ops; new_crypt->ops = ops;
if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
new_crypt->priv = new_crypt->ops->init(idx); new_crypt->priv = new_crypt->ops->init(idx);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment