Skip to content

Commit

Permalink
NFC: llcp: Fix non blocking sockets connections
Browse files Browse the repository at this point in the history
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: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Samuel Ortiz committed Jun 14, 2013
1 parent 7cbe0ff commit b401123
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions net/nfc/llcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

enum llcp_state {
LLCP_CONNECTED = 1, /* wait_for_packet() wants that */
LLCP_CONNECTING,
LLCP_DISCONNECTING,
LLCP_CLOSED,
LLCP_BOUND,
Expand Down
8 changes: 5 additions & 3 deletions net/nfc/llcp_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static unsigned int llcp_sock_poll(struct file *file, struct socket *sock,
if (sk->sk_shutdown == SHUTDOWN_MASK)
mask |= POLLHUP;

if (sock_writeable(sk))
if (sock_writeable(sk) && sk->sk_state == LLCP_CONNECTED)
mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
else
set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
Expand Down Expand Up @@ -729,14 +729,16 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
if (ret)
goto sock_unlink;

sk->sk_state = LLCP_CONNECTING;

ret = sock_wait_state(sk, LLCP_CONNECTED,
sock_sndtimeo(sk, flags & O_NONBLOCK));
if (ret)
if (ret && ret != -EINPROGRESS)
goto sock_unlink;

release_sock(sk);

return 0;
return ret;

sock_unlink:
nfc_llcp_put_ssap(local, llcp_sock->ssap);
Expand Down

0 comments on commit b401123

Please sign in to comment.