Skip to content

Commit 79e19fa

Browse files
wentasahmarckleinebudde
authored andcommitted
can: isotp: isotp_ops: fix poll() to not report false EPOLLOUT events
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]>
1 parent 0145462 commit 79e19fa

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

net/can/isotp.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,21 @@ static int isotp_init(struct sock *sk)
16081608
return 0;
16091609
}
16101610

1611+
static __poll_t isotp_poll(struct file *file, struct socket *sock, poll_table *wait)
1612+
{
1613+
struct sock *sk = sock->sk;
1614+
struct isotp_sock *so = isotp_sk(sk);
1615+
1616+
__poll_t mask = datagram_poll(file, sock, wait);
1617+
poll_wait(file, &so->wait, wait);
1618+
1619+
/* Check for false positives due to TX state */
1620+
if ((mask & EPOLLWRNORM) && (so->tx.state != ISOTP_IDLE))
1621+
mask &= ~(EPOLLOUT | EPOLLWRNORM);
1622+
1623+
return mask;
1624+
}
1625+
16111626
static int isotp_sock_no_ioctlcmd(struct socket *sock, unsigned int cmd,
16121627
unsigned long arg)
16131628
{
@@ -1623,7 +1638,7 @@ static const struct proto_ops isotp_ops = {
16231638
.socketpair = sock_no_socketpair,
16241639
.accept = sock_no_accept,
16251640
.getname = isotp_getname,
1626-
.poll = datagram_poll,
1641+
.poll = isotp_poll,
16271642
.ioctl = isotp_sock_no_ioctlcmd,
16281643
.gettstamp = sock_gettstamp,
16291644
.listen = sock_no_listen,

0 commit comments

Comments
 (0)