diff options
author | Jason Wang <jasowang@redhat.com> | 2013-01-11 11:59:32 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-01-11 22:42:02 -0500 |
commit | b8deabd3eebaa96cf8d6e290d67b03f36c7f7a41 (patch) | |
tree | a571817b2de3d0f113458f60c64649069f344ddf /drivers/net | |
parent | d07d7507bfb4e23735c9b83e397c43e1e8a173e8 (diff) |
tuntap: switch to use rtnl_dereference()
Switch to use rtnl_dereference() instead of the open code, suggested by Eric.
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/tun.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 99b58d862174..aa963c44450a 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -404,8 +404,8 @@ static void __tun_detach(struct tun_file *tfile, bool clean) | |||
404 | struct tun_struct *tun; | 404 | struct tun_struct *tun; |
405 | struct net_device *dev; | 405 | struct net_device *dev; |
406 | 406 | ||
407 | tun = rcu_dereference_protected(tfile->tun, | 407 | tun = rtnl_dereference(tfile->tun); |
408 | lockdep_rtnl_is_held()); | 408 | |
409 | if (tun) { | 409 | if (tun) { |
410 | u16 index = tfile->queue_index; | 410 | u16 index = tfile->queue_index; |
411 | BUG_ON(index >= tun->numqueues); | 411 | BUG_ON(index >= tun->numqueues); |
@@ -414,8 +414,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean) | |||
414 | rcu_assign_pointer(tun->tfiles[index], | 414 | rcu_assign_pointer(tun->tfiles[index], |
415 | tun->tfiles[tun->numqueues - 1]); | 415 | tun->tfiles[tun->numqueues - 1]); |
416 | rcu_assign_pointer(tfile->tun, NULL); | 416 | rcu_assign_pointer(tfile->tun, NULL); |
417 | ntfile = rcu_dereference_protected(tun->tfiles[index], | 417 | ntfile = rtnl_dereference(tun->tfiles[index]); |
418 | lockdep_rtnl_is_held()); | ||
419 | ntfile->queue_index = index; | 418 | ntfile->queue_index = index; |
420 | 419 | ||
421 | --tun->numqueues; | 420 | --tun->numqueues; |
@@ -458,8 +457,7 @@ static void tun_detach_all(struct net_device *dev) | |||
458 | int i, n = tun->numqueues; | 457 | int i, n = tun->numqueues; |
459 | 458 | ||
460 | for (i = 0; i < n; i++) { | 459 | for (i = 0; i < n; i++) { |
461 | tfile = rcu_dereference_protected(tun->tfiles[i], | 460 | tfile = rtnl_dereference(tun->tfiles[i]); |
462 | lockdep_rtnl_is_held()); | ||
463 | BUG_ON(!tfile); | 461 | BUG_ON(!tfile); |
464 | wake_up_all(&tfile->wq.wait); | 462 | wake_up_all(&tfile->wq.wait); |
465 | rcu_assign_pointer(tfile->tun, NULL); | 463 | rcu_assign_pointer(tfile->tun, NULL); |
@@ -469,8 +467,7 @@ static void tun_detach_all(struct net_device *dev) | |||
469 | 467 | ||
470 | synchronize_net(); | 468 | synchronize_net(); |
471 | for (i = 0; i < n; i++) { | 469 | for (i = 0; i < n; i++) { |
472 | tfile = rcu_dereference_protected(tun->tfiles[i], | 470 | tfile = rtnl_dereference(tun->tfiles[i]); |
473 | lockdep_rtnl_is_held()); | ||
474 | /* Drop read queue */ | 471 | /* Drop read queue */ |
475 | skb_queue_purge(&tfile->sk.sk_receive_queue); | 472 | skb_queue_purge(&tfile->sk.sk_receive_queue); |
476 | sock_put(&tfile->sk); | 473 | sock_put(&tfile->sk); |
@@ -489,7 +486,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file) | |||
489 | int err; | 486 | int err; |
490 | 487 | ||
491 | err = -EINVAL; | 488 | err = -EINVAL; |
492 | if (rcu_dereference_protected(tfile->tun, lockdep_rtnl_is_held())) | 489 | if (rtnl_dereference(tfile->tun)) |
493 | goto out; | 490 | goto out; |
494 | if (tfile->detached && tun != tfile->detached) | 491 | if (tfile->detached && tun != tfile->detached) |
495 | goto out; | 492 | goto out; |
@@ -1740,8 +1737,7 @@ static void tun_detach_filter(struct tun_struct *tun, int n) | |||
1740 | struct tun_file *tfile; | 1737 | struct tun_file *tfile; |
1741 | 1738 | ||
1742 | for (i = 0; i < n; i++) { | 1739 | for (i = 0; i < n; i++) { |
1743 | tfile = rcu_dereference_protected(tun->tfiles[i], | 1740 | tfile = rtnl_dereference(tun->tfiles[i]); |
1744 | lockdep_rtnl_is_held()); | ||
1745 | sk_detach_filter(tfile->socket.sk); | 1741 | sk_detach_filter(tfile->socket.sk); |
1746 | } | 1742 | } |
1747 | 1743 | ||
@@ -1754,8 +1750,7 @@ static int tun_attach_filter(struct tun_struct *tun) | |||
1754 | struct tun_file *tfile; | 1750 | struct tun_file *tfile; |
1755 | 1751 | ||
1756 | for (i = 0; i < tun->numqueues; i++) { | 1752 | for (i = 0; i < tun->numqueues; i++) { |
1757 | tfile = rcu_dereference_protected(tun->tfiles[i], | 1753 | tfile = rtnl_dereference(tun->tfiles[i]); |
1758 | lockdep_rtnl_is_held()); | ||
1759 | ret = sk_attach_filter(&tun->fprog, tfile->socket.sk); | 1754 | ret = sk_attach_filter(&tun->fprog, tfile->socket.sk); |
1760 | if (ret) { | 1755 | if (ret) { |
1761 | tun_detach_filter(tun, i); | 1756 | tun_detach_filter(tun, i); |
@@ -1773,8 +1768,7 @@ static void tun_set_sndbuf(struct tun_struct *tun) | |||
1773 | int i; | 1768 | int i; |
1774 | 1769 | ||
1775 | for (i = 0; i < tun->numqueues; i++) { | 1770 | for (i = 0; i < tun->numqueues; i++) { |
1776 | tfile = rcu_dereference_protected(tun->tfiles[i], | 1771 | tfile = rtnl_dereference(tun->tfiles[i]); |
1777 | lockdep_rtnl_is_held()); | ||
1778 | tfile->socket.sk->sk_sndbuf = tun->sndbuf; | 1772 | tfile->socket.sk->sk_sndbuf = tun->sndbuf; |
1779 | } | 1773 | } |
1780 | } | 1774 | } |
@@ -1794,8 +1788,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr) | |||
1794 | else | 1788 | else |
1795 | ret = tun_attach(tun, file); | 1789 | ret = tun_attach(tun, file); |
1796 | } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) { | 1790 | } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) { |
1797 | tun = rcu_dereference_protected(tfile->tun, | 1791 | tun = rtnl_dereference(tfile->tun); |
1798 | lockdep_rtnl_is_held()); | ||
1799 | if (!tun || !(tun->flags & TUN_TAP_MQ)) | 1792 | if (!tun || !(tun->flags & TUN_TAP_MQ)) |
1800 | ret = -EINVAL; | 1793 | ret = -EINVAL; |
1801 | else | 1794 | else |