Skip to content

Commit 0c600ed

Browse files
Ingo Oeserdavem330
authored andcommitted
[IPV6]: Nearly complete kzalloc cleanup for net/ipv6
Stupidly use kzalloc() instead of kmalloc()/memset() everywhere where this is possible in net/ipv6/*.c . Signed-off-by: Ingo Oeser <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 78c784c commit 0c600ed

File tree

8 files changed

+16
-31
lines changed

8 files changed

+16
-31
lines changed

net/ipv6/ah6.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,10 @@ static int ah6_init_state(struct xfrm_state *x)
354354
if (x->encap)
355355
goto error;
356356

357-
ahp = kmalloc(sizeof(*ahp), GFP_KERNEL);
357+
ahp = kzalloc(sizeof(*ahp), GFP_KERNEL);
358358
if (ahp == NULL)
359359
return -ENOMEM;
360360

361-
memset(ahp, 0, sizeof(*ahp));
362-
363361
ahp->key = x->aalg->alg_key;
364362
ahp->key_len = (x->aalg->alg_key_len+7)/8;
365363
ahp->tfm = crypto_alloc_tfm(x->aalg->alg_name, 0);

net/ipv6/anycast.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ int ipv6_dev_ac_inc(struct net_device *dev, struct in6_addr *addr)
308308
* not found: create a new one.
309309
*/
310310

311-
aca = kmalloc(sizeof(struct ifacaddr6), GFP_ATOMIC);
311+
aca = kzalloc(sizeof(struct ifacaddr6), GFP_ATOMIC);
312312

313313
if (aca == NULL) {
314314
err = -ENOMEM;
@@ -322,8 +322,6 @@ int ipv6_dev_ac_inc(struct net_device *dev, struct in6_addr *addr)
322322
goto out;
323323
}
324324

325-
memset(aca, 0, sizeof(struct ifacaddr6));
326-
327325
ipv6_addr_copy(&aca->aca_addr, addr);
328326
aca->aca_idev = idev;
329327
aca->aca_rt = rt;
@@ -550,7 +548,7 @@ static int ac6_seq_open(struct inode *inode, struct file *file)
550548
{
551549
struct seq_file *seq;
552550
int rc = -ENOMEM;
553-
struct ac6_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
551+
struct ac6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
554552

555553
if (!s)
556554
goto out;
@@ -561,7 +559,6 @@ static int ac6_seq_open(struct inode *inode, struct file *file)
561559

562560
seq = file->private_data;
563561
seq->private = s;
564-
memset(s, 0, sizeof(*s));
565562
out:
566563
return rc;
567564
out_kfree:

net/ipv6/esp6.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,10 @@ static int esp6_init_state(struct xfrm_state *x)
305305
if (x->encap)
306306
goto error;
307307

308-
esp = kmalloc(sizeof(*esp), GFP_KERNEL);
308+
esp = kzalloc(sizeof(*esp), GFP_KERNEL);
309309
if (esp == NULL)
310310
return -ENOMEM;
311311

312-
memset(esp, 0, sizeof(*esp));
313-
314312
if (x->aalg) {
315313
struct xfrm_algo_desc *aalg_desc;
316314

net/ipv6/ip6_flowlabel.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,9 @@ fl_create(struct in6_flowlabel_req *freq, char __user *optval, int optlen, int *
287287
int err;
288288

289289
err = -ENOMEM;
290-
fl = kmalloc(sizeof(*fl), GFP_KERNEL);
290+
fl = kzalloc(sizeof(*fl), GFP_KERNEL);
291291
if (fl == NULL)
292292
goto done;
293-
memset(fl, 0, sizeof(*fl));
294293

295294
olen = optlen - CMSG_ALIGN(sizeof(*freq));
296295
if (olen > 0) {
@@ -663,7 +662,7 @@ static int ip6fl_seq_open(struct inode *inode, struct file *file)
663662
{
664663
struct seq_file *seq;
665664
int rc = -ENOMEM;
666-
struct ip6fl_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
665+
struct ip6fl_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
667666

668667
if (!s)
669668
goto out;
@@ -674,7 +673,6 @@ static int ip6fl_seq_open(struct inode *inode, struct file *file)
674673

675674
seq = file->private_data;
676675
seq->private = s;
677-
memset(s, 0, sizeof(*s));
678676
out:
679677
return rc;
680678
out_kfree:

net/ipv6/ipcomp6.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,10 @@ static int ipcomp6_init_state(struct xfrm_state *x)
428428
goto out;
429429

430430
err = -ENOMEM;
431-
ipcd = kmalloc(sizeof(*ipcd), GFP_KERNEL);
431+
ipcd = kzalloc(sizeof(*ipcd), GFP_KERNEL);
432432
if (!ipcd)
433433
goto out;
434434

435-
memset(ipcd, 0, sizeof(*ipcd));
436435
x->props.header_len = 0;
437436
if (x->props.mode)
438437
x->props.header_len += sizeof(struct ipv6hdr);

net/ipv6/mcast.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,10 @@ static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
767767
* for deleted items allows change reports to use common code with
768768
* non-deleted or query-response MCA's.
769769
*/
770-
pmc = kmalloc(sizeof(*pmc), GFP_ATOMIC);
770+
pmc = kzalloc(sizeof(*pmc), GFP_ATOMIC);
771771
if (!pmc)
772772
return;
773-
memset(pmc, 0, sizeof(*pmc));
773+
774774
spin_lock_bh(&im->mca_lock);
775775
spin_lock_init(&pmc->mca_lock);
776776
pmc->idev = im->idev;
@@ -893,15 +893,14 @@ int ipv6_dev_mc_inc(struct net_device *dev, struct in6_addr *addr)
893893
* not found: create a new one.
894894
*/
895895

896-
mc = kmalloc(sizeof(struct ifmcaddr6), GFP_ATOMIC);
896+
mc = kzalloc(sizeof(struct ifmcaddr6), GFP_ATOMIC);
897897

898898
if (mc == NULL) {
899899
write_unlock_bh(&idev->lock);
900900
in6_dev_put(idev);
901901
return -ENOMEM;
902902
}
903903

904-
memset(mc, 0, sizeof(struct ifmcaddr6));
905904
init_timer(&mc->mca_timer);
906905
mc->mca_timer.function = igmp6_timer_handler;
907906
mc->mca_timer.data = (unsigned long) mc;
@@ -1934,10 +1933,10 @@ static int ip6_mc_add1_src(struct ifmcaddr6 *pmc, int sfmode,
19341933
psf_prev = psf;
19351934
}
19361935
if (!psf) {
1937-
psf = kmalloc(sizeof(*psf), GFP_ATOMIC);
1936+
psf = kzalloc(sizeof(*psf), GFP_ATOMIC);
19381937
if (!psf)
19391938
return -ENOBUFS;
1940-
memset(psf, 0, sizeof(*psf));
1939+
19411940
psf->sf_addr = *psfsrc;
19421941
if (psf_prev) {
19431942
psf_prev->sf_next = psf;
@@ -2431,7 +2430,7 @@ static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
24312430
{
24322431
struct seq_file *seq;
24332432
int rc = -ENOMEM;
2434-
struct igmp6_mc_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2433+
struct igmp6_mc_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
24352434

24362435
if (!s)
24372436
goto out;
@@ -2442,7 +2441,6 @@ static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
24422441

24432442
seq = file->private_data;
24442443
seq->private = s;
2445-
memset(s, 0, sizeof(*s));
24462444
out:
24472445
return rc;
24482446
out_kfree:
@@ -2606,7 +2604,7 @@ static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
26062604
{
26072605
struct seq_file *seq;
26082606
int rc = -ENOMEM;
2609-
struct igmp6_mcf_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2607+
struct igmp6_mcf_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
26102608

26112609
if (!s)
26122610
goto out;
@@ -2617,7 +2615,6 @@ static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
26172615

26182616
seq = file->private_data;
26192617
seq->private = s;
2620-
memset(s, 0, sizeof(*s));
26212618
out:
26222619
return rc;
26232620
out_kfree:

net/ipv6/raw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,15 +1198,14 @@ static int raw6_seq_open(struct inode *inode, struct file *file)
11981198
{
11991199
struct seq_file *seq;
12001200
int rc = -ENOMEM;
1201-
struct raw6_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
1201+
struct raw6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
12021202
if (!s)
12031203
goto out;
12041204
rc = seq_open(file, &raw6_seq_ops);
12051205
if (rc)
12061206
goto out_kfree;
12071207
seq = file->private_data;
12081208
seq->private = s;
1209-
memset(s, 0, sizeof(*s));
12101209
out:
12111210
return rc;
12121211
out_kfree:

net/ipv6/route.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,11 +1877,10 @@ int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
18771877
/*
18781878
* 2. allocate and initialize walker.
18791879
*/
1880-
w = kmalloc(sizeof(*w), GFP_ATOMIC);
1880+
w = kzalloc(sizeof(*w), GFP_ATOMIC);
18811881
if (w == NULL)
18821882
return -ENOMEM;
18831883
RT6_TRACE("dump<%p", w);
1884-
memset(w, 0, sizeof(*w));
18851884
w->root = &ip6_routing_table;
18861885
w->func = fib6_dump_node;
18871886
w->args = &arg;

0 commit comments

Comments
 (0)