aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/addrconf.c
diff options
context:
space:
mode:
authorIngo Oeser <ioe-lkml@rameria.de>2006-03-21 02:01:47 -0500
committerDavid S. Miller <davem@davemloft.net>2006-03-21 02:01:47 -0500
commit322f74a432f976328e834a8663f2e75eb5933ecc (patch)
tree78c0415bc4902862eef3b33254fc516ad24b6872 /net/ipv6/addrconf.c
parent0c600eda4b1c9f8f6d1bd643d494db5a29842fbe (diff)
[IPV6]: Cleanups for net/ipv6/addrconf.c (kzalloc, early exit) v2
Here are some possible (and trivial) cleanups. - use kzalloc() where possible - invert allocation failure test like if (object) { /* Rest of function here */ } to if (object == NULL) return NULL; /* Rest of function here */ Signed-off-by: Ingo Oeser <ioe-lkml@rameria.de> Acked-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/addrconf.c')
-rw-r--r--net/ipv6/addrconf.c141
1 files changed, 69 insertions, 72 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index eb82cd5df8c6..01c62a0d3742 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -341,84 +341,83 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
341 if (dev->mtu < IPV6_MIN_MTU) 341 if (dev->mtu < IPV6_MIN_MTU)
342 return NULL; 342 return NULL;
343 343
344 ndev = kmalloc(sizeof(struct inet6_dev), GFP_KERNEL); 344 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
345 345
346 if (ndev) { 346 if (ndev == NULL)
347 memset(ndev, 0, sizeof(struct inet6_dev)); 347 return NULL;
348 348
349 rwlock_init(&ndev->lock); 349 rwlock_init(&ndev->lock);
350 ndev->dev = dev; 350 ndev->dev = dev;
351 memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf)); 351 memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf));
352 ndev->cnf.mtu6 = dev->mtu; 352 ndev->cnf.mtu6 = dev->mtu;
353 ndev->cnf.sysctl = NULL; 353 ndev->cnf.sysctl = NULL;
354 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); 354 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
355 if (ndev->nd_parms == NULL) { 355 if (ndev->nd_parms == NULL) {
356 kfree(ndev); 356 kfree(ndev);
357 return NULL; 357 return NULL;
358 } 358 }
359 /* We refer to the device */ 359 /* We refer to the device */
360 dev_hold(dev); 360 dev_hold(dev);
361
362 if (snmp6_alloc_dev(ndev) < 0) {
363 ADBG((KERN_WARNING
364 "%s(): cannot allocate memory for statistics; dev=%s.\n",
365 __FUNCTION__, dev->name));
366 neigh_parms_release(&nd_tbl, ndev->nd_parms);
367 ndev->dead = 1;
368 in6_dev_finish_destroy(ndev);
369 return NULL;
370 }
371 361
372 if (snmp6_register_dev(ndev) < 0) { 362 if (snmp6_alloc_dev(ndev) < 0) {
373 ADBG((KERN_WARNING 363 ADBG((KERN_WARNING
374 "%s(): cannot create /proc/net/dev_snmp6/%s\n", 364 "%s(): cannot allocate memory for statistics; dev=%s.\n",
375 __FUNCTION__, dev->name)); 365 __FUNCTION__, dev->name));
376 neigh_parms_release(&nd_tbl, ndev->nd_parms); 366 neigh_parms_release(&nd_tbl, ndev->nd_parms);
377 ndev->dead = 1; 367 ndev->dead = 1;
378 in6_dev_finish_destroy(ndev); 368 in6_dev_finish_destroy(ndev);
379 return NULL; 369 return NULL;
380 } 370 }
381 371
382 /* One reference from device. We must do this before 372 if (snmp6_register_dev(ndev) < 0) {
383 * we invoke __ipv6_regen_rndid(). 373 ADBG((KERN_WARNING
384 */ 374 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
385 in6_dev_hold(ndev); 375 __FUNCTION__, dev->name));
376 neigh_parms_release(&nd_tbl, ndev->nd_parms);
377 ndev->dead = 1;
378 in6_dev_finish_destroy(ndev);
379 return NULL;
380 }
381
382 /* One reference from device. We must do this before
383 * we invoke __ipv6_regen_rndid().
384 */
385 in6_dev_hold(ndev);
386 386
387#ifdef CONFIG_IPV6_PRIVACY 387#ifdef CONFIG_IPV6_PRIVACY
388 init_timer(&ndev->regen_timer); 388 init_timer(&ndev->regen_timer);
389 ndev->regen_timer.function = ipv6_regen_rndid; 389 ndev->regen_timer.function = ipv6_regen_rndid;
390 ndev->regen_timer.data = (unsigned long) ndev; 390 ndev->regen_timer.data = (unsigned long) ndev;
391 if ((dev->flags&IFF_LOOPBACK) || 391 if ((dev->flags&IFF_LOOPBACK) ||
392 dev->type == ARPHRD_TUNNEL || 392 dev->type == ARPHRD_TUNNEL ||
393 dev->type == ARPHRD_NONE || 393 dev->type == ARPHRD_NONE ||
394 dev->type == ARPHRD_SIT) { 394 dev->type == ARPHRD_SIT) {
395 printk(KERN_INFO 395 printk(KERN_INFO
396 "%s: Disabled Privacy Extensions\n", 396 "%s: Disabled Privacy Extensions\n",
397 dev->name); 397 dev->name);
398 ndev->cnf.use_tempaddr = -1; 398 ndev->cnf.use_tempaddr = -1;
399 } else { 399 } else {
400 in6_dev_hold(ndev); 400 in6_dev_hold(ndev);
401 ipv6_regen_rndid((unsigned long) ndev); 401 ipv6_regen_rndid((unsigned long) ndev);
402 } 402 }
403#endif 403#endif
404 404
405 if (netif_carrier_ok(dev)) 405 if (netif_carrier_ok(dev))
406 ndev->if_flags |= IF_READY; 406 ndev->if_flags |= IF_READY;
407 407
408 write_lock_bh(&addrconf_lock); 408 write_lock_bh(&addrconf_lock);
409 dev->ip6_ptr = ndev; 409 dev->ip6_ptr = ndev;
410 write_unlock_bh(&addrconf_lock); 410 write_unlock_bh(&addrconf_lock);
411 411
412 ipv6_mc_init_dev(ndev); 412 ipv6_mc_init_dev(ndev);
413 ndev->tstamp = jiffies; 413 ndev->tstamp = jiffies;
414#ifdef CONFIG_SYSCTL 414#ifdef CONFIG_SYSCTL
415 neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6, 415 neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6,
416 NET_IPV6_NEIGH, "ipv6", 416 NET_IPV6_NEIGH, "ipv6",
417 &ndisc_ifinfo_sysctl_change, 417 &ndisc_ifinfo_sysctl_change,
418 NULL); 418 NULL);
419 addrconf_sysctl_register(ndev, &ndev->cnf); 419 addrconf_sysctl_register(ndev, &ndev->cnf);
420#endif 420#endif
421 }
422 return ndev; 421 return ndev;
423} 422}
424 423
@@ -536,7 +535,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
536 goto out; 535 goto out;
537 } 536 }
538 537
539 ifa = kmalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC); 538 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
540 539
541 if (ifa == NULL) { 540 if (ifa == NULL) {
542 ADBG(("ipv6_add_addr: malloc failed\n")); 541 ADBG(("ipv6_add_addr: malloc failed\n"));
@@ -550,7 +549,6 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
550 goto out; 549 goto out;
551 } 550 }
552 551
553 memset(ifa, 0, sizeof(struct inet6_ifaddr));
554 ipv6_addr_copy(&ifa->addr, addr); 552 ipv6_addr_copy(&ifa->addr, addr);
555 553
556 spin_lock_init(&ifa->lock); 554 spin_lock_init(&ifa->lock);
@@ -2669,11 +2667,10 @@ static int if6_seq_open(struct inode *inode, struct file *file)
2669{ 2667{
2670 struct seq_file *seq; 2668 struct seq_file *seq;
2671 int rc = -ENOMEM; 2669 int rc = -ENOMEM;
2672 struct if6_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL); 2670 struct if6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
2673 2671
2674 if (!s) 2672 if (!s)
2675 goto out; 2673 goto out;
2676 memset(s, 0, sizeof(*s));
2677 2674
2678 rc = seq_open(file, &if6_seq_ops); 2675 rc = seq_open(file, &if6_seq_ops);
2679 if (rc) 2676 if (rc)