sc16is7xx: Fix for incorrect data being transmitted
authorPhil Elwell <phil@raspberrypi.com>
Wed, 16 Feb 2022 16:08:02 +0000 (16:08 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Feb 2022 18:51:39 +0000 (19:51 +0100)
commiteebb0f4e894f1e9577a56b337693d1051dd6ebfd
tree794c7893414da9114414749cf155926b52ee55dd
parenta2ab75b8e76e455af7867e3835fd9cdf386b508f
sc16is7xx: Fix for incorrect data being transmitted

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: https://github.com/raspberrypi/linux/issues/4885

Fixes: 6393ff1c4435 ("sc16is7xx: Use threaded IRQ")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Link: https://lore.kernel.org/r/20220216160802.1026013-1-phil@raspberrypi.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/sc16is7xx.c