Commit cc9fa74e authored by Andre Naujoks's avatar Andre Naujoks Committed by David S. Miller

slip/slcan: added locking in wakeup function

The locking is needed, since the the internal buffer for the CAN frames is
changed during the wakeup call. This could cause buffer inconsistencies
under high loads, especially for the outgoing short CAN packet skbuffs.

The needed locks led to deadlocks before commit
"5ede5253 tty: Remove extra wakeup from pty
write() path", which removed the direct callback to the wakeup function from the
tty layer.

As slcan.c is based on slip.c the issue in the original code is fixed, too.
Signed-off-by: default avatarAndre Naujoks <nautsch2@gmail.com>
Acked-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Acked-by: default avatarMarc Kleine-Budde  <mkl@pengutronix.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dcb30e65
...@@ -286,11 +286,13 @@ static void slcan_write_wakeup(struct tty_struct *tty) ...@@ -286,11 +286,13 @@ static void slcan_write_wakeup(struct tty_struct *tty)
if (!sl || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev)) if (!sl || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev))
return; return;
spin_lock(&sl->lock);
if (sl->xleft <= 0) { if (sl->xleft <= 0) {
/* Now serial buffer is almost free & we can start /* Now serial buffer is almost free & we can start
* transmission of another packet */ * transmission of another packet */
sl->dev->stats.tx_packets++; sl->dev->stats.tx_packets++;
clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
spin_unlock(&sl->lock);
netif_wake_queue(sl->dev); netif_wake_queue(sl->dev);
return; return;
} }
...@@ -298,6 +300,7 @@ static void slcan_write_wakeup(struct tty_struct *tty) ...@@ -298,6 +300,7 @@ static void slcan_write_wakeup(struct tty_struct *tty)
actual = tty->ops->write(tty, sl->xhead, sl->xleft); actual = tty->ops->write(tty, sl->xhead, sl->xleft);
sl->xleft -= actual; sl->xleft -= actual;
sl->xhead += actual; sl->xhead += actual;
spin_unlock(&sl->lock);
} }
/* Send a can_frame to a TTY queue. */ /* Send a can_frame to a TTY queue. */
......
...@@ -429,11 +429,13 @@ static void slip_write_wakeup(struct tty_struct *tty) ...@@ -429,11 +429,13 @@ static void slip_write_wakeup(struct tty_struct *tty)
if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev))
return; return;
spin_lock(&sl->lock);
if (sl->xleft <= 0) { if (sl->xleft <= 0) {
/* Now serial buffer is almost free & we can start /* Now serial buffer is almost free & we can start
* transmission of another packet */ * transmission of another packet */
sl->dev->stats.tx_packets++; sl->dev->stats.tx_packets++;
clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
spin_unlock(&sl->lock);
sl_unlock(sl); sl_unlock(sl);
return; return;
} }
...@@ -441,6 +443,7 @@ static void slip_write_wakeup(struct tty_struct *tty) ...@@ -441,6 +443,7 @@ static void slip_write_wakeup(struct tty_struct *tty)
actual = tty->ops->write(tty, sl->xhead, sl->xleft); actual = tty->ops->write(tty, sl->xhead, sl->xleft);
sl->xleft -= actual; sl->xleft -= actual;
sl->xhead += actual; sl->xhead += actual;
spin_unlock(&sl->lock);
} }
static void sl_tx_timeout(struct net_device *dev) static void sl_tx_timeout(struct net_device *dev)
......
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