Skip to content

Commit 9629964

Browse files
jhnikulagregkh
authored andcommitted
spi: Fix unregistration of controller with fixed SPI bus number
commit 613bd1e upstream. Commit 9b61e30 (spi: Pick spi bus number from Linux idr or spi alias) ceased to unregister SPI buses with fixed bus numbers. Moreover this is visible only if CONFIG_SPI_DEBUG=y is set or when trying to re-register the same SPI controller. rmmod spi_pxa2xx_platform (with CONFIG_SPI_DEBUG=y): [ 26.788362] spi_master spi1: attempting to delete unregistered controller [spi1] modprobe spi_pxa2xx_platform: [ 37.883137] sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:19.0/pxa2xx-spi.12/spi_master/spi1' [ 37.894984] CPU: 1 PID: 1467 Comm: modprobe Not tainted 4.16.0-rc4+ #21 [ 37.902384] Call Trace: ... [ 38.122680] kobject_add_internal failed for spi1 with -EEXIST, don't try to register things with the same name in the same directory. [ 38.136154] WARNING: CPU: 1 PID: 1467 at lib/kobject.c:238 kobject_add_internal+0x2a5/0x2f0 ... [ 38.513817] pxa2xx-spi pxa2xx-spi.12: problem registering spi master [ 38.521036] pxa2xx-spi: probe of pxa2xx-spi.12 failed with error -17 Fix this by not returning immediately from spi_unregister_controller() if idr_find() doesn't find controller with given ID/bus number. It finds only those controllers that were registered with dynamic SPI bus numbers. Only conditional cleanup between dynamic and fixed bus numbers is to remove allocated IDR. Fixes: 9b61e30 (spi: Pick spi bus number from Linux idr or spi alias) Cc: [email protected] Signed-off-by: Jarkko Nikula <[email protected]> Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e4ff723 commit 9629964

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

drivers/spi/spi.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,12 +2258,6 @@ void spi_unregister_controller(struct spi_controller *ctlr)
22582258
mutex_lock(&board_lock);
22592259
found = idr_find(&spi_master_idr, id);
22602260
mutex_unlock(&board_lock);
2261-
if (found != ctlr) {
2262-
dev_dbg(&ctlr->dev,
2263-
"attempting to delete unregistered controller [%s]\n",
2264-
dev_name(&ctlr->dev));
2265-
return;
2266-
}
22672261
if (ctlr->queued) {
22682262
if (spi_destroy_queue(ctlr))
22692263
dev_err(&ctlr->dev, "queue remove failed\n");
@@ -2276,7 +2270,8 @@ void spi_unregister_controller(struct spi_controller *ctlr)
22762270
device_unregister(&ctlr->dev);
22772271
/* free bus id */
22782272
mutex_lock(&board_lock);
2279-
idr_remove(&spi_master_idr, id);
2273+
if (found == ctlr)
2274+
idr_remove(&spi_master_idr, id);
22802275
mutex_unlock(&board_lock);
22812276
}
22822277
EXPORT_SYMBOL_GPL(spi_unregister_controller);

0 commit comments

Comments
 (0)