Commit 75606dc6 authored by Ralf Baechle's avatar Ralf Baechle Committed by David S. Miller

[AX25/NETROM/ROSE]: Convert to use modern wait queue API

Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 80feaacb
...@@ -1127,22 +1127,22 @@ static int __must_check ax25_connect(struct socket *sock, ...@@ -1127,22 +1127,22 @@ static int __must_check ax25_connect(struct socket *sock,
switch (sk->sk_state) { switch (sk->sk_state) {
case TCP_SYN_SENT: /* still trying */ case TCP_SYN_SENT: /* still trying */
err = -EINPROGRESS; err = -EINPROGRESS;
goto out; goto out_release;
case TCP_ESTABLISHED: /* connection established */ case TCP_ESTABLISHED: /* connection established */
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
goto out; goto out_release;
case TCP_CLOSE: /* connection refused */ case TCP_CLOSE: /* connection refused */
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
err = -ECONNREFUSED; err = -ECONNREFUSED;
goto out; goto out_release;
} }
} }
if (sk->sk_state == TCP_ESTABLISHED && sk->sk_type == SOCK_SEQPACKET) { if (sk->sk_state == TCP_ESTABLISHED && sk->sk_type == SOCK_SEQPACKET) {
err = -EISCONN; /* No reconnect on a seqpacket socket */ err = -EISCONN; /* No reconnect on a seqpacket socket */
goto out; goto out_release;
} }
sk->sk_state = TCP_CLOSE; sk->sk_state = TCP_CLOSE;
...@@ -1159,12 +1159,12 @@ static int __must_check ax25_connect(struct socket *sock, ...@@ -1159,12 +1159,12 @@ static int __must_check ax25_connect(struct socket *sock,
/* Valid number of digipeaters ? */ /* Valid number of digipeaters ? */
if (fsa->fsa_ax25.sax25_ndigis < 1 || fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS) { if (fsa->fsa_ax25.sax25_ndigis < 1 || fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS) {
err = -EINVAL; err = -EINVAL;
goto out; goto out_release;
} }
if ((digi = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) { if ((digi = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
err = -ENOBUFS; err = -ENOBUFS;
goto out; goto out_release;
} }
digi->ndigi = fsa->fsa_ax25.sax25_ndigis; digi->ndigi = fsa->fsa_ax25.sax25_ndigis;
...@@ -1194,7 +1194,7 @@ static int __must_check ax25_connect(struct socket *sock, ...@@ -1194,7 +1194,7 @@ static int __must_check ax25_connect(struct socket *sock,
current->comm); current->comm);
if ((err = ax25_rt_autobind(ax25, &fsa->fsa_ax25.sax25_call)) < 0) { if ((err = ax25_rt_autobind(ax25, &fsa->fsa_ax25.sax25_call)) < 0) {
kfree(digi); kfree(digi);
goto out; goto out_release;
} }
ax25_fillin_cb(ax25, ax25->ax25_dev); ax25_fillin_cb(ax25, ax25->ax25_dev);
...@@ -1203,7 +1203,7 @@ static int __must_check ax25_connect(struct socket *sock, ...@@ -1203,7 +1203,7 @@ static int __must_check ax25_connect(struct socket *sock,
if (ax25->ax25_dev == NULL) { if (ax25->ax25_dev == NULL) {
kfree(digi); kfree(digi);
err = -EHOSTUNREACH; err = -EHOSTUNREACH;
goto out; goto out_release;
} }
} }
...@@ -1213,7 +1213,7 @@ static int __must_check ax25_connect(struct socket *sock, ...@@ -1213,7 +1213,7 @@ static int __must_check ax25_connect(struct socket *sock,
kfree(digi); kfree(digi);
err = -EADDRINUSE; /* Already such a connection */ err = -EADDRINUSE; /* Already such a connection */
ax25_cb_put(ax25t); ax25_cb_put(ax25t);
goto out; goto out_release;
} }
ax25->dest_addr = fsa->fsa_ax25.sax25_call; ax25->dest_addr = fsa->fsa_ax25.sax25_call;
...@@ -1223,7 +1223,7 @@ static int __must_check ax25_connect(struct socket *sock, ...@@ -1223,7 +1223,7 @@ static int __must_check ax25_connect(struct socket *sock,
if (sk->sk_type != SOCK_SEQPACKET) { if (sk->sk_type != SOCK_SEQPACKET) {
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
sk->sk_state = TCP_ESTABLISHED; sk->sk_state = TCP_ESTABLISHED;
goto out; goto out_release;
} }
/* Move to connecting socket, ax.25 lapb WAIT_UA.. */ /* Move to connecting socket, ax.25 lapb WAIT_UA.. */
...@@ -1255,55 +1255,53 @@ static int __must_check ax25_connect(struct socket *sock, ...@@ -1255,55 +1255,53 @@ static int __must_check ax25_connect(struct socket *sock,
/* Now the loop */ /* Now the loop */
if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) { if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) {
err = -EINPROGRESS; err = -EINPROGRESS;
goto out; goto out_release;
} }
if (sk->sk_state == TCP_SYN_SENT) { if (sk->sk_state == TCP_SYN_SENT) {
struct task_struct *tsk = current; DEFINE_WAIT(wait);
DECLARE_WAITQUEUE(wait, tsk);
add_wait_queue(sk->sk_sleep, &wait);
for (;;) { for (;;) {
prepare_to_wait(sk->sk_sleep, &wait,
TASK_INTERRUPTIBLE);
if (sk->sk_state != TCP_SYN_SENT) if (sk->sk_state != TCP_SYN_SENT)
break; break;
set_current_state(TASK_INTERRUPTIBLE); if (!signal_pending(current)) {
release_sock(sk); release_sock(sk);
if (!signal_pending(tsk)) {
schedule(); schedule();
lock_sock(sk); lock_sock(sk);
continue; continue;
} }
current->state = TASK_RUNNING; err = -ERESTARTSYS;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -ERESTARTSYS;
} }
current->state = TASK_RUNNING; finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait);
if (err)
goto out_release;
} }
if (sk->sk_state != TCP_ESTABLISHED) { if (sk->sk_state != TCP_ESTABLISHED) {
/* Not in ABM, not in WAIT_UA -> failed */ /* Not in ABM, not in WAIT_UA -> failed */
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
err = sock_error(sk); /* Always set at this point */ err = sock_error(sk); /* Always set at this point */
goto out; goto out_release;
} }
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
err=0; err = 0;
out: out_release:
release_sock(sk); release_sock(sk);
return err; return err;
} }
static int ax25_accept(struct socket *sock, struct socket *newsock, int flags) static int ax25_accept(struct socket *sock, struct socket *newsock, int flags)
{ {
struct task_struct *tsk = current;
DECLARE_WAITQUEUE(wait, tsk);
struct sk_buff *skb; struct sk_buff *skb;
struct sock *newsk; struct sock *newsk;
DEFINE_WAIT(wait);
struct sock *sk; struct sock *sk;
int err = 0; int err = 0;
...@@ -1328,30 +1326,29 @@ static int ax25_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -1328,30 +1326,29 @@ static int ax25_accept(struct socket *sock, struct socket *newsock, int flags)
* The read queue this time is holding sockets ready to use * The read queue this time is holding sockets ready to use
* hooked into the SABM we saved * hooked into the SABM we saved
*/ */
add_wait_queue(sk->sk_sleep, &wait);
for (;;) { for (;;) {
prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
if (skb) if (skb)
break; break;
release_sock(sk);
current->state = TASK_INTERRUPTIBLE;
if (flags & O_NONBLOCK) { if (flags & O_NONBLOCK) {
current->state = TASK_RUNNING; err = -EWOULDBLOCK;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -EWOULDBLOCK;
} }
if (!signal_pending(tsk)) { if (!signal_pending(current)) {
release_sock(sk);
schedule(); schedule();
lock_sock(sk); lock_sock(sk);
continue; continue;
} }
current->state = TASK_RUNNING; err = -ERESTARTSYS;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -ERESTARTSYS;
} }
current->state = TASK_RUNNING; finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait);
if (err)
goto out;
newsk = skb->sk; newsk = skb->sk;
newsk->sk_socket = newsock; newsk->sk_socket = newsock;
......
...@@ -625,42 +625,42 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -625,42 +625,42 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
ax25_address *source = NULL; ax25_address *source = NULL;
ax25_uid_assoc *user; ax25_uid_assoc *user;
struct net_device *dev; struct net_device *dev;
int err = 0;
lock_sock(sk); lock_sock(sk);
if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) { if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
release_sock(sk); goto out_release; /* Connect completed during a ERESTARTSYS event */
return 0; /* Connect completed during a ERESTARTSYS event */
} }
if (sk->sk_state == TCP_CLOSE && sock->state == SS_CONNECTING) { if (sk->sk_state == TCP_CLOSE && sock->state == SS_CONNECTING) {
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
release_sock(sk); err = -ECONNREFUSED;
return -ECONNREFUSED; goto out_release;
} }
if (sk->sk_state == TCP_ESTABLISHED) { if (sk->sk_state == TCP_ESTABLISHED) {
release_sock(sk); err = -EISCONN; /* No reconnect on a seqpacket socket */
return -EISCONN; /* No reconnect on a seqpacket socket */ goto out_release;
} }
sk->sk_state = TCP_CLOSE; sk->sk_state = TCP_CLOSE;
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25)) { if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25)) {
release_sock(sk); err = -EINVAL;
return -EINVAL; goto out_release;
} }
if (addr->sax25_family != AF_NETROM) { if (addr->sax25_family != AF_NETROM) {
release_sock(sk); err = -EINVAL;
return -EINVAL; goto out_release;
} }
if (sock_flag(sk, SOCK_ZAPPED)) { /* Must bind first - autobinding in this may or may not work */ if (sock_flag(sk, SOCK_ZAPPED)) { /* Must bind first - autobinding in this may or may not work */
sock_reset_flag(sk, SOCK_ZAPPED); sock_reset_flag(sk, SOCK_ZAPPED);
if ((dev = nr_dev_first()) == NULL) { if ((dev = nr_dev_first()) == NULL) {
release_sock(sk); err = -ENETUNREACH;
return -ENETUNREACH; goto out_release;
} }
source = (ax25_address *)dev->dev_addr; source = (ax25_address *)dev->dev_addr;
...@@ -671,8 +671,8 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -671,8 +671,8 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
} else { } else {
if (ax25_uid_policy && !capable(CAP_NET_ADMIN)) { if (ax25_uid_policy && !capable(CAP_NET_ADMIN)) {
dev_put(dev); dev_put(dev);
release_sock(sk); err = -EPERM;
return -EPERM; goto out_release;
} }
nr->user_addr = *source; nr->user_addr = *source;
} }
...@@ -707,8 +707,8 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -707,8 +707,8 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
/* Now the loop */ /* Now the loop */
if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) { if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) {
release_sock(sk); err = -EINPROGRESS;
return -EINPROGRESS; goto out_release;
} }
/* /*
...@@ -716,46 +716,46 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -716,46 +716,46 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
* closed. * closed.
*/ */
if (sk->sk_state == TCP_SYN_SENT) { if (sk->sk_state == TCP_SYN_SENT) {
struct task_struct *tsk = current; DEFINE_WAIT(wait);
DECLARE_WAITQUEUE(wait, tsk);
add_wait_queue(sk->sk_sleep, &wait);
for (;;) { for (;;) {
set_current_state(TASK_INTERRUPTIBLE); prepare_to_wait(sk->sk_sleep, &wait,
TASK_INTERRUPTIBLE);
if (sk->sk_state != TCP_SYN_SENT) if (sk->sk_state != TCP_SYN_SENT)
break; break;
if (!signal_pending(current)) {
release_sock(sk); release_sock(sk);
if (!signal_pending(tsk)) {
schedule(); schedule();
lock_sock(sk); lock_sock(sk);
continue; continue;
} }
current->state = TASK_RUNNING; err = -ERESTARTSYS;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -ERESTARTSYS;
} }
current->state = TASK_RUNNING; finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait); if (err)
goto out_release;
} }
if (sk->sk_state != TCP_ESTABLISHED) { if (sk->sk_state != TCP_ESTABLISHED) {
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
release_sock(sk); err = sock_error(sk); /* Always set at this point */
return sock_error(sk); /* Always set at this point */ goto out_release;
} }
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
out_release:
release_sock(sk); release_sock(sk);
return 0; return err;
} }
static int nr_accept(struct socket *sock, struct socket *newsock, int flags) static int nr_accept(struct socket *sock, struct socket *newsock, int flags)
{ {
struct task_struct *tsk = current;
DECLARE_WAITQUEUE(wait, tsk);
struct sk_buff *skb; struct sk_buff *skb;
struct sock *newsk; struct sock *newsk;
DEFINE_WAIT(wait);
struct sock *sk; struct sock *sk;
int err = 0; int err = 0;
...@@ -765,42 +765,40 @@ static int nr_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -765,42 +765,40 @@ static int nr_accept(struct socket *sock, struct socket *newsock, int flags)
lock_sock(sk); lock_sock(sk);
if (sk->sk_type != SOCK_SEQPACKET) { if (sk->sk_type != SOCK_SEQPACKET) {
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto out; goto out_release;
} }
if (sk->sk_state != TCP_LISTEN) { if (sk->sk_state != TCP_LISTEN) {
err = -EINVAL; err = -EINVAL;
goto out; goto out_release;
} }
/* /*
* The write queue this time is holding sockets ready to use * The write queue this time is holding sockets ready to use
* hooked into the SABM we saved * hooked into the SABM we saved
*/ */
add_wait_queue(sk->sk_sleep, &wait);
for (;;) { for (;;) {
prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
if (skb) if (skb)
break; break;
current->state = TASK_INTERRUPTIBLE;
release_sock(sk);
if (flags & O_NONBLOCK) { if (flags & O_NONBLOCK) {
current->state = TASK_RUNNING; err = -EWOULDBLOCK;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -EWOULDBLOCK;
} }
if (!signal_pending(tsk)) { if (!signal_pending(current)) {
release_sock(sk);
schedule(); schedule();
lock_sock(sk); lock_sock(sk);
continue; continue;
} }
current->state = TASK_RUNNING; err = -ERESTARTSYS;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -ERESTARTSYS;
} }
current->state = TASK_RUNNING; finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait); if (err)
goto out_release;
newsk = skb->sk; newsk = skb->sk;
newsk->sk_socket = newsock; newsk->sk_socket = newsock;
...@@ -811,8 +809,9 @@ static int nr_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -811,8 +809,9 @@ static int nr_accept(struct socket *sock, struct socket *newsock, int flags)
sk_acceptq_removed(sk); sk_acceptq_removed(sk);
newsock->sk = newsk; newsock->sk = newsk;
out: out_release:
release_sock(sk); release_sock(sk);
return err; return err;
} }
......
...@@ -812,26 +812,26 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le ...@@ -812,26 +812,26 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le
* closed. * closed.
*/ */
if (sk->sk_state == TCP_SYN_SENT) { if (sk->sk_state == TCP_SYN_SENT) {
struct task_struct *tsk = current; DEFINE_WAIT(wait);
DECLARE_WAITQUEUE(wait, tsk);
add_wait_queue(sk->sk_sleep, &wait);
for (;;) { for (;;) {
set_current_state(TASK_INTERRUPTIBLE); prepare_to_wait(sk->sk_sleep, &wait,
TASK_INTERRUPTIBLE);
if (sk->sk_state != TCP_SYN_SENT) if (sk->sk_state != TCP_SYN_SENT)
break; break;
if (!signal_pending(current)) {
release_sock(sk); release_sock(sk);
if (!signal_pending(tsk)) {
schedule(); schedule();
lock_sock(sk); lock_sock(sk);
continue; continue;
} }
current->state = TASK_RUNNING; err = -ERESTARTSYS;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -ERESTARTSYS;
} }
current->state = TASK_RUNNING; finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait);
if (err)
goto out_release;
} }
if (sk->sk_state != TCP_ESTABLISHED) { if (sk->sk_state != TCP_ESTABLISHED) {
...@@ -856,10 +856,9 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le ...@@ -856,10 +856,9 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le
static int rose_accept(struct socket *sock, struct socket *newsock, int flags) static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
{ {
struct task_struct *tsk = current;
DECLARE_WAITQUEUE(wait, tsk);
struct sk_buff *skb; struct sk_buff *skb;
struct sock *newsk; struct sock *newsk;
DEFINE_WAIT(wait);
struct sock *sk; struct sock *sk;
int err = 0; int err = 0;
...@@ -869,42 +868,41 @@ static int rose_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -869,42 +868,41 @@ static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
lock_sock(sk); lock_sock(sk);
if (sk->sk_type != SOCK_SEQPACKET) { if (sk->sk_type != SOCK_SEQPACKET) {
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto out; goto out_release;
} }
if (sk->sk_state != TCP_LISTEN) { if (sk->sk_state != TCP_LISTEN) {
err = -EINVAL; err = -EINVAL;
goto out; goto out_release;
} }
/* /*
* The write queue this time is holding sockets ready to use * The write queue this time is holding sockets ready to use
* hooked into the SABM we saved * hooked into the SABM we saved
*/ */
add_wait_queue(sk->sk_sleep, &wait);
for (;;) { for (;;) {
prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
if (skb) if (skb)
break; break;
current->state = TASK_INTERRUPTIBLE;
release_sock(sk);
if (flags & O_NONBLOCK) { if (flags & O_NONBLOCK) {
current->state = TASK_RUNNING; err = -EWOULDBLOCK;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -EWOULDBLOCK;
} }
if (!signal_pending(tsk)) { if (!signal_pending(current)) {
release_sock(sk);
schedule(); schedule();
lock_sock(sk); lock_sock(sk);
continue; continue;
} }
current->state = TASK_RUNNING; err = -ERESTARTSYS;
remove_wait_queue(sk->sk_sleep, &wait); break;
return -ERESTARTSYS;
} }
current->state = TASK_RUNNING; finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait); if (err)
goto out_release;
newsk = skb->sk; newsk = skb->sk;
newsk->sk_socket = newsock; newsk->sk_socket = newsock;
...@@ -916,7 +914,7 @@ static int rose_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -916,7 +914,7 @@ static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
sk->sk_ack_backlog--; sk->sk_ack_backlog--;
newsock->sk = newsk; newsock->sk = newsk;
out: out_release:
release_sock(sk); release_sock(sk);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment