Commit b4011239 authored by Samuel Ortiz's avatar Samuel Ortiz

NFC: llcp: Fix non blocking sockets connections

Without the new LLCP_CONNECTING state, non blocking sockets will be
woken up with a POLLHUP right after calling connect() because their
state is stuck at LLCP_CLOSED.
That prevents userspace from implementing any proper non blocking
socket based NFC p2p client.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 7cbe0ff3
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
enum llcp_state { enum llcp_state {
LLCP_CONNECTED = 1, /* wait_for_packet() wants that */ LLCP_CONNECTED = 1, /* wait_for_packet() wants that */
LLCP_CONNECTING,
LLCP_DISCONNECTING, LLCP_DISCONNECTING,
LLCP_CLOSED, LLCP_CLOSED,
LLCP_BOUND, LLCP_BOUND,
......
...@@ -571,7 +571,7 @@ static unsigned int llcp_sock_poll(struct file *file, struct socket *sock, ...@@ -571,7 +571,7 @@ static unsigned int llcp_sock_poll(struct file *file, struct socket *sock,
if (sk->sk_shutdown == SHUTDOWN_MASK) if (sk->sk_shutdown == SHUTDOWN_MASK)
mask |= POLLHUP; mask |= POLLHUP;
if (sock_writeable(sk)) if (sock_writeable(sk) && sk->sk_state == LLCP_CONNECTED)
mask |= POLLOUT | POLLWRNORM | POLLWRBAND; mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
else else
set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
...@@ -729,14 +729,16 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, ...@@ -729,14 +729,16 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
if (ret) if (ret)
goto sock_unlink; goto sock_unlink;
sk->sk_state = LLCP_CONNECTING;
ret = sock_wait_state(sk, LLCP_CONNECTED, ret = sock_wait_state(sk, LLCP_CONNECTED,
sock_sndtimeo(sk, flags & O_NONBLOCK)); sock_sndtimeo(sk, flags & O_NONBLOCK));
if (ret) if (ret && ret != -EINPROGRESS)
goto sock_unlink; goto sock_unlink;
release_sock(sk); release_sock(sk);
return 0; return ret;
sock_unlink: sock_unlink:
nfc_llcp_put_ssap(local, llcp_sock->ssap); nfc_llcp_put_ssap(local, llcp_sock->ssap);
......
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