Skip to content

Commit

Permalink
spi: take the SPI IO-mutex in the spi_set_cs_timing method
Browse files Browse the repository at this point in the history
[ Upstream commit dc5fa59 ]

this patch takes the io_mutex to prevent an unprotected HW
register modification in the set_cs_timing callback.

Fixes: 4cea6b8 ("spi: add power control when set_cs_timing")
Signed-off-by: Leilk Liu <leilk.liu@mediatek.com>
Link: https://lore.kernel.org/r/20210508060214.1485-1-leilk.liu@mediatek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
leilkliu authored and gregkh committed Jun 3, 2021
1 parent 29258f2 commit ecd6d94
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/spi/spi.c
Expand Up @@ -3463,9 +3463,12 @@ int spi_set_cs_timing(struct spi_device *spi, struct spi_delay *setup,

if (spi->controller->set_cs_timing &&
!(spi->cs_gpiod || gpio_is_valid(spi->cs_gpio))) {
mutex_lock(&spi->controller->io_mutex);

if (spi->controller->auto_runtime_pm) {
status = pm_runtime_get_sync(parent);
if (status < 0) {
mutex_unlock(&spi->controller->io_mutex);
pm_runtime_put_noidle(parent);
dev_err(&spi->controller->dev, "Failed to power device: %d\n",
status);
Expand All @@ -3476,11 +3479,13 @@ int spi_set_cs_timing(struct spi_device *spi, struct spi_delay *setup,
hold, inactive);
pm_runtime_mark_last_busy(parent);
pm_runtime_put_autosuspend(parent);
return status;
} else {
return spi->controller->set_cs_timing(spi, setup, hold,
status = spi->controller->set_cs_timing(spi, setup, hold,
inactive);
}

mutex_unlock(&spi->controller->io_mutex);
return status;
}

if ((setup && setup->unit == SPI_DELAY_UNIT_SCK) ||
Expand Down

0 comments on commit ecd6d94

Please sign in to comment.