Skip to content

Commit 9d85428

Browse files
pelwellZhengzengkai
authored andcommitted
sc16is7xx: Fix for incorrect data being transmitted
stable inclusion from stable-v5.10.103 commit 18701d8afaa1c609b3cbf7c63ef5423ab2c8d252 bugzilla: https://gitee.com/openeuler/kernel/issues/I56NE7 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=18701d8afaa1c609b3cbf7c63ef5423ab2c8d252 -------------------------------- commit eebb0f4 upstream. UART drivers are meant to use the port spinlock within certain methods, to protect against reentrancy. The sc16is7xx driver does very little locking, presumably because when added it triggers "scheduling while atomic" errors. This is due to the use of mutexes within the regmap abstraction layer, and the mutex implementation's habit of sleeping the current thread while waiting for access. Unfortunately this lack of interlocking can lead to corruption of outbound data, which occurs when the buffer used for I2C transmission is used simultaneously by two threads - a work queue thread running sc16is7xx_tx_proc, and an IRQ thread in sc16is7xx_port_irq, both of which can call sc16is7xx_handle_tx. An earlier patch added efr_lock, a mutex that controls access to the EFR register. This mutex is already claimed in the IRQ handler, and all that is required is to claim the same mutex in sc16is7xx_tx_proc. See: raspberrypi/linux#4885 Fixes: 6393ff1 ("sc16is7xx: Use threaded IRQ") Cc: stable <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Yu Liao <[email protected]> Reviewed-by: Wei Li <[email protected]> Signed-off-by: Zheng Zengkai <[email protected]>
1 parent 831c8e2 commit 9d85428

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/tty/serial/sc16is7xx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,15 @@ static irqreturn_t sc16is7xx_irq(int irq, void *dev_id)
734734
static void sc16is7xx_tx_proc(struct kthread_work *ws)
735735
{
736736
struct uart_port *port = &(to_sc16is7xx_one(ws, tx_work)->port);
737+
struct sc16is7xx_port *s = dev_get_drvdata(port->dev);
737738

738739
if ((port->rs485.flags & SER_RS485_ENABLED) &&
739740
(port->rs485.delay_rts_before_send > 0))
740741
msleep(port->rs485.delay_rts_before_send);
741742

743+
mutex_lock(&s->efr_lock);
742744
sc16is7xx_handle_tx(port);
745+
mutex_unlock(&s->efr_lock);
743746
}
744747

745748
static void sc16is7xx_reconf_rs485(struct uart_port *port)

0 commit comments

Comments
 (0)