Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b8deabd3 authored by Jason Wang's avatar Jason Wang Committed by David S. Miller
Browse files

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: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d07d7507
Loading
Loading
Loading
Loading
+10 −17
Original line number Original line Diff line number Diff line
@@ -404,8 +404,8 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
	struct tun_struct *tun;
	struct tun_struct *tun;
	struct net_device *dev;
	struct net_device *dev;


	tun = rcu_dereference_protected(tfile->tun,
	tun = rtnl_dereference(tfile->tun);
					lockdep_rtnl_is_held());

	if (tun) {
	if (tun) {
		u16 index = tfile->queue_index;
		u16 index = tfile->queue_index;
		BUG_ON(index >= tun->numqueues);
		BUG_ON(index >= tun->numqueues);
@@ -414,8 +414,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
		rcu_assign_pointer(tun->tfiles[index],
		rcu_assign_pointer(tun->tfiles[index],
				   tun->tfiles[tun->numqueues - 1]);
				   tun->tfiles[tun->numqueues - 1]);
		rcu_assign_pointer(tfile->tun, NULL);
		rcu_assign_pointer(tfile->tun, NULL);
		ntfile = rcu_dereference_protected(tun->tfiles[index],
		ntfile = rtnl_dereference(tun->tfiles[index]);
						   lockdep_rtnl_is_held());
		ntfile->queue_index = index;
		ntfile->queue_index = index;


		--tun->numqueues;
		--tun->numqueues;
@@ -458,8 +457,7 @@ static void tun_detach_all(struct net_device *dev)
	int i, n = tun->numqueues;
	int i, n = tun->numqueues;


	for (i = 0; i < n; i++) {
	for (i = 0; i < n; i++) {
		tfile = rcu_dereference_protected(tun->tfiles[i],
		tfile = rtnl_dereference(tun->tfiles[i]);
						  lockdep_rtnl_is_held());
		BUG_ON(!tfile);
		BUG_ON(!tfile);
		wake_up_all(&tfile->wq.wait);
		wake_up_all(&tfile->wq.wait);
		rcu_assign_pointer(tfile->tun, NULL);
		rcu_assign_pointer(tfile->tun, NULL);
@@ -469,8 +467,7 @@ static void tun_detach_all(struct net_device *dev)


	synchronize_net();
	synchronize_net();
	for (i = 0; i < n; i++) {
	for (i = 0; i < n; i++) {
		tfile = rcu_dereference_protected(tun->tfiles[i],
		tfile = rtnl_dereference(tun->tfiles[i]);
						  lockdep_rtnl_is_held());
		/* Drop read queue */
		/* Drop read queue */
		skb_queue_purge(&tfile->sk.sk_receive_queue);
		skb_queue_purge(&tfile->sk.sk_receive_queue);
		sock_put(&tfile->sk);
		sock_put(&tfile->sk);
@@ -489,7 +486,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file)
	int err;
	int err;


	err = -EINVAL;
	err = -EINVAL;
	if (rcu_dereference_protected(tfile->tun, lockdep_rtnl_is_held()))
	if (rtnl_dereference(tfile->tun))
		goto out;
		goto out;
	if (tfile->detached && tun != tfile->detached)
	if (tfile->detached && tun != tfile->detached)
		goto out;
		goto out;
@@ -1740,8 +1737,7 @@ static void tun_detach_filter(struct tun_struct *tun, int n)
	struct tun_file *tfile;
	struct tun_file *tfile;


	for (i = 0; i < n; i++) {
	for (i = 0; i < n; i++) {
		tfile = rcu_dereference_protected(tun->tfiles[i],
		tfile = rtnl_dereference(tun->tfiles[i]);
						  lockdep_rtnl_is_held());
		sk_detach_filter(tfile->socket.sk);
		sk_detach_filter(tfile->socket.sk);
	}
	}


@@ -1754,8 +1750,7 @@ static int tun_attach_filter(struct tun_struct *tun)
	struct tun_file *tfile;
	struct tun_file *tfile;


	for (i = 0; i < tun->numqueues; i++) {
	for (i = 0; i < tun->numqueues; i++) {
		tfile = rcu_dereference_protected(tun->tfiles[i],
		tfile = rtnl_dereference(tun->tfiles[i]);
						  lockdep_rtnl_is_held());
		ret = sk_attach_filter(&tun->fprog, tfile->socket.sk);
		ret = sk_attach_filter(&tun->fprog, tfile->socket.sk);
		if (ret) {
		if (ret) {
			tun_detach_filter(tun, i);
			tun_detach_filter(tun, i);
@@ -1773,8 +1768,7 @@ static void tun_set_sndbuf(struct tun_struct *tun)
	int i;
	int i;


	for (i = 0; i < tun->numqueues; i++) {
	for (i = 0; i < tun->numqueues; i++) {
		tfile = rcu_dereference_protected(tun->tfiles[i],
		tfile = rtnl_dereference(tun->tfiles[i]);
						lockdep_rtnl_is_held());
		tfile->socket.sk->sk_sndbuf = tun->sndbuf;
		tfile->socket.sk->sk_sndbuf = tun->sndbuf;
	}
	}
}
}
@@ -1794,8 +1788,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
		else
		else
			ret = tun_attach(tun, file);
			ret = tun_attach(tun, file);
	} else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {
	} else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {
		tun = rcu_dereference_protected(tfile->tun,
		tun = rtnl_dereference(tfile->tun);
						lockdep_rtnl_is_held());
		if (!tun || !(tun->flags & TUN_TAP_MQ))
		if (!tun || !(tun->flags & TUN_TAP_MQ))
			ret = -EINVAL;
			ret = -EINVAL;
		else
		else