Skip to content

Commit f3765ab

Browse files
kkapranovgregkh
authored andcommitted
spi: fix IDR collision on systems with both fixed and dynamic SPI bus numbers
commit 1a4327f upstream. 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] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5ca87a3 commit f3765ab

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
@@ -2135,6 +2135,15 @@ int spi_register_controller(struct spi_controller *ctlr)
21352135
if (WARN(id < 0, "couldn't get idr"))
21362136
return id;
21372137
ctlr->bus_num = id;
2138+
} else {
2139+
/* devices with a fixed bus num must check-in with the num */
2140+
mutex_lock(&board_lock);
2141+
id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num,
2142+
ctlr->bus_num + 1, GFP_KERNEL);
2143+
mutex_unlock(&board_lock);
2144+
if (WARN(id < 0, "couldn't get idr"))
2145+
return id == -ENOSPC ? -EBUSY : id;
2146+
ctlr->bus_num = id;
21382147
}
21392148
INIT_LIST_HEAD(&ctlr->queue);
21402149
spin_lock_init(&ctlr->queue_lock);

0 commit comments

Comments
 (0)