Skip to content

Commit

Permalink
[NET]: Conversions from kmalloc+memset to k(z|c)alloc.
Browse files Browse the repository at this point in the history
Signed-off-by: Panagiotis Issaris <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
takis authored and davem330 committed Jul 21, 2006
1 parent a0ee7c7 commit 0da974f
Show file tree
Hide file tree
Showing 94 changed files with 154 additions and 334 deletions.
3 changes: 1 addition & 2 deletions net/8021q/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,11 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
* so it cannot "appear" on us.
*/
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)
goto out_free_unregister;

/* printk(KERN_ALERT "VLAN REGISTER: Allocated new group.\n"); */
memset(grp, 0, sizeof(struct vlan_group));
grp->real_dev_ifindex = real_dev->ifindex;

hlist_add_head_rcu(&grp->hlist,
Expand Down
6 changes: 2 additions & 4 deletions net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,11 @@ static void atif_drop_device(struct net_device *dev)
static struct atalk_iface *atif_add_device(struct net_device *dev,
struct atalk_addr *sa)
{
struct atalk_iface *iface = kmalloc(sizeof(*iface), GFP_KERNEL);
struct atalk_iface *iface = kzalloc(sizeof(*iface), GFP_KERNEL);

if (!iface)
goto out;

memset(iface, 0, sizeof(*iface));
dev_hold(dev);
iface->dev = dev;
dev->atalk_ptr = iface;
Expand Down Expand Up @@ -559,12 +558,11 @@ static int atrtr_create(struct rtentry *r, struct net_device *devhint)
}

if (!rt) {
rt = kmalloc(sizeof(*rt), GFP_ATOMIC);
rt = kzalloc(sizeof(*rt), GFP_ATOMIC);

retval = -ENOBUFS;
if (!rt)
goto out_unlock;
memset(rt, 0, sizeof(*rt));

rt->next = atalk_routes;
atalk_routes = rt;
Expand Down
3 changes: 1 addition & 2 deletions net/atm/br2684.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,9 @@ Note: we do not have explicit unassign, but look at _push()

if (copy_from_user(&be, arg, sizeof be))
return -EFAULT;
brvcc = kmalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
brvcc = kzalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
if (!brvcc)
return -ENOMEM;
memset(brvcc, 0, sizeof(struct br2684_vcc));
write_lock_irq(&devs_lock);
net_dev = br2684_find_dev(&be.ifspec);
if (net_dev == NULL) {
Expand Down
3 changes: 1 addition & 2 deletions net/atm/clip.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,11 @@ static int arp_seq_open(struct inode *inode, struct file *file)
struct seq_file *seq;
int rc = -EAGAIN;

state = kmalloc(sizeof(*state), GFP_KERNEL);
state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state) {
rc = -ENOMEM;
goto out_kfree;
}
memset(state, 0, sizeof(*state));
state->ns.neigh_sub_iter = clip_seq_sub_iter;

rc = seq_open(file, &arp_seq_ops);
Expand Down
3 changes: 1 addition & 2 deletions net/atm/lec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1811,12 +1811,11 @@ make_entry(struct lec_priv *priv, unsigned char *mac_addr)
{
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) {
printk("LEC: Arp entry kmalloc failed\n");
return NULL;
}
memset(to_return, 0, sizeof(struct lec_arp_table));
memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
init_timer(&to_return->timer);
to_return->timer.function = lec_arp_expire_arp;
Expand Down
3 changes: 1 addition & 2 deletions net/atm/mpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ static struct mpoa_client *alloc_mpc(void)
{
struct mpoa_client *mpc;

mpc = kmalloc(sizeof (struct mpoa_client), GFP_KERNEL);
mpc = kzalloc(sizeof (struct mpoa_client), GFP_KERNEL);
if (mpc == NULL)
return NULL;
memset(mpc, 0, sizeof(struct mpoa_client));
rwlock_init(&mpc->ingress_lock);
rwlock_init(&mpc->egress_lock);
mpc->next = mpcs;
Expand Down
3 changes: 1 addition & 2 deletions net/atm/pppoatm.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,9 @@ static int pppoatm_assign_vcc(struct atm_vcc *atmvcc, void __user *arg)
if (be.encaps != PPPOATM_ENCAPS_AUTODETECT &&
be.encaps != PPPOATM_ENCAPS_VC && be.encaps != PPPOATM_ENCAPS_LLC)
return -EINVAL;
pvcc = kmalloc(sizeof(*pvcc), GFP_KERNEL);
pvcc = kzalloc(sizeof(*pvcc), GFP_KERNEL);
if (pvcc == NULL)
return -ENOMEM;
memset(pvcc, 0, sizeof(*pvcc));
pvcc->atmvcc = atmvcc;
pvcc->old_push = atmvcc->push;
pvcc->old_pop = atmvcc->pop;
Expand Down
3 changes: 1 addition & 2 deletions net/atm/resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ static struct atm_dev *__alloc_atm_dev(const char *type)
{
struct atm_dev *dev;

dev = kmalloc(sizeof(*dev), GFP_KERNEL);
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return NULL;
memset(dev, 0, sizeof(*dev));
dev->type = type;
dev->signal = ATM_PHY_SIG_UNKNOWN;
dev->link_rate = ATM_OC3_PCR;
Expand Down
4 changes: 1 addition & 3 deletions net/ax25/sysctl_net_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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);
return;
}

memset(ax25_table, 0x00, ax25_table_size);

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);
if (!child) {
Expand Down
7 changes: 2 additions & 5 deletions net/bridge/br_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,10 @@ static int old_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
if (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)
return -ENOMEM;

memset(indices, 0, num*sizeof(int));

get_port_ifindices(br, indices, num);
if (copy_to_user((void __user *)args[1], indices, num*sizeof(int)))
num = -EFAULT;
Expand Down Expand Up @@ -327,11 +325,10 @@ static int old_deviceless(void __user *uarg)

if (args[2] >= 2048)
return -ENOMEM;
indices = kmalloc(args[2]*sizeof(int), GFP_KERNEL);
indices = kcalloc(args[2], sizeof(int), GFP_KERNEL);
if (indices == NULL)
return -ENOMEM;

memset(indices, 0, args[2]*sizeof(int));
args[2] = get_bridge_ifindices(indices, args[2]);

ret = copy_to_user((void __user *)args[1], indices, args[2]*sizeof(int))
Expand Down
9 changes: 2 additions & 7 deletions net/decnet/dn_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,7 @@ static struct dn_ifaddr *dn_dev_alloc_ifa(void)
{
struct dn_ifaddr *ifa;

ifa = kmalloc(sizeof(*ifa), GFP_KERNEL);

if (ifa) {
memset(ifa, 0, sizeof(*ifa));
}
ifa = kzalloc(sizeof(*ifa), GFP_KERNEL);

return ifa;
}
Expand Down Expand Up @@ -1105,10 +1101,9 @@ struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
return NULL;

*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;

memset(dn_db, 0, sizeof(struct dn_dev));
memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
smp_wmb();
dev->dn_ptr = dn_db;
Expand Down
3 changes: 1 addition & 2 deletions net/decnet/dn_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,10 @@ struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r, struct dn_kern_rta
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;
if (fi == NULL)
goto failure;
memset(fi, 0, sizeof(*fi)+nhs*sizeof(struct dn_fib_nh));

fi->fib_protocol = r->rtm_protocol;
fi->fib_nhs = nhs;
Expand Down
3 changes: 1 addition & 2 deletions net/decnet/dn_neigh.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,11 @@ static int dn_neigh_seq_open(struct inode *inode, struct file *file)
{
struct seq_file *seq;
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)
goto out;

memset(s, 0, sizeof(*s));
rc = seq_open(file, &dn_neigh_seq_ops);
if (rc)
goto out_kfree;
Expand Down
3 changes: 1 addition & 2 deletions net/decnet/dn_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
return -ENOMEM;
memset(new_r, 0, sizeof(*new_r));

if (rta[RTA_SRC-1])
memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 2);
Expand Down
11 changes: 3 additions & 8 deletions net/decnet/dn_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,10 @@ static void dn_rehash_zone(struct dn_zone *dz)
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)
return;

memset(ht, 0, new_divisor*sizeof(struct dn_fib_node *));
write_lock_bh(&dn_fib_tables_lock);
old_ht = dz->dz_hash;
dz->dz_hash = ht;
Expand All @@ -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)
{
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)
return NULL;

memset(dz, 0, sizeof(struct dn_zone));
if (z) {
dz->dz_divisor = 16;
dz->dz_hashmask = 0x0F;
Expand All @@ -197,14 +194,12 @@ static struct dn_zone *dn_new_zone(struct dn_hash *table, int z)
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) {
kfree(dz);
return NULL;
}

memset(dz->dz_hash, 0, dz->dz_divisor*sizeof(struct dn_fib_node*));
dz->dz_order = z;
dz->dz_mask = dnet_make_mask(z);

Expand Down
3 changes: 1 addition & 2 deletions net/econet/af_econet.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,11 @@ static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg)
edev = dev->ec_ptr;
if (edev == NULL) {
/* Magic up a new one. */
edev = kmalloc(sizeof(struct ec_device), GFP_KERNEL);
edev = kzalloc(sizeof(struct ec_device), GFP_KERNEL);
if (edev == NULL) {
err = -ENOMEM;
break;
}
memset(edev, 0, sizeof(struct ec_device));
dev->ec_ptr = edev;
} else
net2dev_map[edev->net] = NULL;
Expand Down
3 changes: 1 addition & 2 deletions net/ieee80211/ieee80211_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops)
unsigned long flags;
struct ieee80211_crypto_alg *alg;

alg = kmalloc(sizeof(*alg), GFP_KERNEL);
alg = kzalloc(sizeof(*alg), GFP_KERNEL);
if (alg == NULL)
return -ENOMEM;

memset(alg, 0, sizeof(*alg));
alg->ops = ops;

spin_lock_irqsave(&ieee80211_crypto_lock, flags);
Expand Down
3 changes: 1 addition & 2 deletions net/ieee80211/ieee80211_crypt_ccmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ static void *ieee80211_ccmp_init(int key_idx)
{
struct ieee80211_ccmp_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = key_idx;

priv->tfm = crypto_alloc_tfm("aes", 0);
Expand Down
3 changes: 1 addition & 2 deletions net/ieee80211/ieee80211_crypt_wep.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ static void *prism2_wep_init(int keyidx)
{
struct prism2_wep_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = keyidx;

priv->tfm = crypto_alloc_tfm("arc4", 0);
Expand Down
7 changes: 2 additions & 5 deletions net/ieee80211/ieee80211_wx.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,10 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
struct ieee80211_crypt_data *new_crypt;

/* take WEP into use */
new_crypt = kmalloc(sizeof(struct ieee80211_crypt_data),
new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
GFP_KERNEL);
if (new_crypt == NULL)
return -ENOMEM;
memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
new_crypt->ops = ieee80211_get_crypto_ops("WEP");
if (!new_crypt->ops) {
request_module("ieee80211_crypt_wep");
Expand Down Expand Up @@ -616,13 +615,11 @@ int ieee80211_wx_set_encodeext(struct ieee80211_device *ieee,

ieee80211_crypt_delayed_deinit(ieee, crypt);

new_crypt = (struct ieee80211_crypt_data *)
kmalloc(sizeof(*new_crypt), GFP_KERNEL);
new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
if (new_crypt == NULL) {
ret = -ENOMEM;
goto done;
}
memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
new_crypt->ops = ops;
if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
new_crypt->priv = new_crypt->ops->init(idx);
Expand Down
3 changes: 1 addition & 2 deletions net/ieee80211/softmac/ieee80211softmac_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ ieee80211softmac_alloc_mgt(u32 size)
if(size > IEEE80211_DATA_LEN)
return NULL;
/* Allocate the frame */
data = kmalloc(size, GFP_ATOMIC);
memset(data, 0, size);
data = kzalloc(size, GFP_ATOMIC);
return data;
}

Expand Down
4 changes: 1 addition & 3 deletions net/ipv4/ah4.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,10 @@ static int ah_init_state(struct xfrm_state *x)
if (x->encap)
goto error;

ahp = kmalloc(sizeof(*ahp), GFP_KERNEL);
ahp = kzalloc(sizeof(*ahp), GFP_KERNEL);
if (ahp == NULL)
return -ENOMEM;

memset(ahp, 0, sizeof(*ahp));

ahp->key = x->aalg->alg_key;
ahp->key_len = (x->aalg->alg_key_len+7)/8;
ahp->tfm = crypto_alloc_tfm(x->aalg->alg_name, 0);
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,12 +1372,11 @@ static int arp_seq_open(struct inode *inode, struct file *file)
{
struct seq_file *seq;
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)
goto out;

memset(s, 0, sizeof(*s));
rc = seq_open(file, &arp_seq_ops);
if (rc)
goto out_kfree;
Expand Down
Loading

0 comments on commit 0da974f

Please sign in to comment.