Skip to content

Commit

Permalink
can: isotp: isotp_ops: fix poll() to not report false EPOLLOUT events
Browse files Browse the repository at this point in the history
When using select()/poll()/epoll() with a non-blocking ISOTP socket to
wait for when non-blocking write is possible, a false EPOLLOUT event
is sometimes returned. This can happen at least after sending a
message which must be split to multiple CAN frames.

The reason is that isotp_sendmsg() returns -EAGAIN when tx.state is
not equal to ISOTP_IDLE and this behavior is not reflected in
datagram_poll(), which is used in isotp_ops.

This is fixed by introducing ISOTP-specific poll function, which
suppresses the EPOLLOUT events in that case.

v2: https://lore.kernel.org/all/[email protected]
v1: https://lore.kernel.org/all/[email protected]
    https://lore.kernel.org/all/[email protected]

Signed-off-by: Michal Sojka <[email protected]>
Reported-by: Jakub Jira <[email protected]>
Tested-by: Oliver Hartkopp <[email protected]>
Acked-by: Oliver Hartkopp <[email protected]>
Fixes: e057dd3 ("can: add ISO 15765-2:2016 transport protocol")
Link: https://lore.kernel.org/all/[email protected]
Cc: [email protected]
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
wentasah authored and marckleinebudde committed Apr 5, 2023
1 parent 0145462 commit 79e19fa
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion net/can/isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,21 @@ static int isotp_init(struct sock *sk)
return 0;
}

static __poll_t isotp_poll(struct file *file, struct socket *sock, poll_table *wait)
{
struct sock *sk = sock->sk;
struct isotp_sock *so = isotp_sk(sk);

__poll_t mask = datagram_poll(file, sock, wait);
poll_wait(file, &so->wait, wait);

/* Check for false positives due to TX state */
if ((mask & EPOLLWRNORM) && (so->tx.state != ISOTP_IDLE))
mask &= ~(EPOLLOUT | EPOLLWRNORM);

return mask;
}

static int isotp_sock_no_ioctlcmd(struct socket *sock, unsigned int cmd,
unsigned long arg)
{
Expand All @@ -1623,7 +1638,7 @@ static const struct proto_ops isotp_ops = {
.socketpair = sock_no_socketpair,
.accept = sock_no_accept,
.getname = isotp_getname,
.poll = datagram_poll,
.poll = isotp_poll,
.ioctl = isotp_sock_no_ioctlcmd,
.gettstamp = sock_gettstamp,
.listen = sock_no_listen,
Expand Down

0 comments on commit 79e19fa

Please sign in to comment.