Skip to content

Commit 1a4327f

Browse files
kkapranovbroonie
authored andcommitted
spi: fix IDR collision on systems with both fixed and dynamic SPI bus numbers
On systems where some controllers get a dynamic ID assigned and some have a fixed number (e.g. from ACPI tables), the current implementation might run into an IDR collision: in case of a fixed bus number is gotten by a driver (but not marked busy in IDR tree) and a driver with dynamic bus number gets the same ID and predictably fails. Fix this by means of checking-in fixed IDsin IDR as far as dynamic ones at the moment of the controller registration. Fixes: 9b61e30 (spi: Pick spi bus number from Linux idr or spi alias) Signed-off-by: Kirill Kapranov <[email protected]> Signed-off-by: Mark Brown <[email protected]> Cc: [email protected]
1 parent 401c0d7 commit 1a4327f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/spi/spi.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,15 @@ int spi_register_controller(struct spi_controller *ctlr)
21702170
if (WARN(id < 0, "couldn't get idr"))
21712171
return id;
21722172
ctlr->bus_num = id;
2173+
} else {
2174+
/* devices with a fixed bus num must check-in with the num */
2175+
mutex_lock(&board_lock);
2176+
id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num,
2177+
ctlr->bus_num + 1, GFP_KERNEL);
2178+
mutex_unlock(&board_lock);
2179+
if (WARN(id < 0, "couldn't get idr"))
2180+
return id == -ENOSPC ? -EBUSY : id;
2181+
ctlr->bus_num = id;
21732182
}
21742183
INIT_LIST_HEAD(&ctlr->queue);
21752184
spin_lock_init(&ctlr->queue_lock);

0 commit comments

Comments
 (0)