Skip to content

Commit 16a8e2f

Browse files
Uwe Kleine-Königbroonie
authored andcommitted
spi-mux: Fix false-positive lockdep splats
io_mutex is taken by spi_setup() and spi-mux's .setup() callback calls spi_setup() which results in a nested lock of io_mutex. add_lock is taken by spi_add_device(). The device_add() call in there can result in calling spi-mux's .probe() callback which registers its own spi controller which in turn results in spi_add_device() being called again. To fix this initialize the controller's locks already in spi_alloc_controller() to give spi_mux_probe() a chance to set the lockdep subclass. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 6098475 commit 16a8e2f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

drivers/spi/spi-mux.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ static int spi_mux_probe(struct spi_device *spi)
137137
priv = spi_controller_get_devdata(ctlr);
138138
priv->spi = spi;
139139

140+
/*
141+
* Increase lockdep class as these lock are taken while the parent bus
142+
* already holds their instance's lock.
143+
*/
144+
lockdep_set_subclass(&ctlr->io_mutex, 1);
145+
lockdep_set_subclass(&ctlr->add_lock, 1);
146+
140147
priv->mux = devm_mux_control_get(&spi->dev, NULL);
141148
if (IS_ERR(priv->mux)) {
142149
ret = dev_err_probe(&spi->dev, PTR_ERR(priv->mux),

drivers/spi/spi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,12 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
25472547
return NULL;
25482548

25492549
device_initialize(&ctlr->dev);
2550+
INIT_LIST_HEAD(&ctlr->queue);
2551+
spin_lock_init(&ctlr->queue_lock);
2552+
spin_lock_init(&ctlr->bus_lock_spinlock);
2553+
mutex_init(&ctlr->bus_lock_mutex);
2554+
mutex_init(&ctlr->io_mutex);
2555+
mutex_init(&ctlr->add_lock);
25502556
ctlr->bus_num = -1;
25512557
ctlr->num_chipselect = 1;
25522558
ctlr->slave = slave;
@@ -2819,12 +2825,6 @@ int spi_register_controller(struct spi_controller *ctlr)
28192825
return id;
28202826
ctlr->bus_num = id;
28212827
}
2822-
INIT_LIST_HEAD(&ctlr->queue);
2823-
spin_lock_init(&ctlr->queue_lock);
2824-
spin_lock_init(&ctlr->bus_lock_spinlock);
2825-
mutex_init(&ctlr->bus_lock_mutex);
2826-
mutex_init(&ctlr->io_mutex);
2827-
mutex_init(&ctlr->add_lock);
28282828
ctlr->bus_lock_flag = 0;
28292829
init_completion(&ctlr->xfer_completion);
28302830
if (!ctlr->max_dma_len)

0 commit comments

Comments
 (0)