diff options
author | Jarkko Nikula <jarkko.nikula@linux.intel.com> | 2018-03-20 04:27:50 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-03-20 05:00:19 -0400 |
commit | 613bd1ea387bb48b7c9a71a0bb451ac15cfbbc01 (patch) | |
tree | 34f8cbdb1a138e69c5b24e14167c5c79b3ce56f2 | |
parent | 7928b2cbe55b2a410a0f5c1f154610059c57b1b2 (diff) |
spi: Fix unregistration of controller with fixed SPI bus number
Commit 9b61e302210e (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: 9b61e302210e (spi: Pick spi bus number from Linux idr or spi alias)
Cc: stable@vger.kernel.org
Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/spi/spi.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index b33a727a0158..e90fd442b3f0 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -2254,12 +2254,6 @@ void spi_unregister_controller(struct spi_controller *ctlr) | |||
2254 | mutex_lock(&board_lock); | 2254 | mutex_lock(&board_lock); |
2255 | found = idr_find(&spi_master_idr, id); | 2255 | found = idr_find(&spi_master_idr, id); |
2256 | mutex_unlock(&board_lock); | 2256 | mutex_unlock(&board_lock); |
2257 | if (found != ctlr) { | ||
2258 | dev_dbg(&ctlr->dev, | ||
2259 | "attempting to delete unregistered controller [%s]\n", | ||
2260 | dev_name(&ctlr->dev)); | ||
2261 | return; | ||
2262 | } | ||
2263 | if (ctlr->queued) { | 2257 | if (ctlr->queued) { |
2264 | if (spi_destroy_queue(ctlr)) | 2258 | if (spi_destroy_queue(ctlr)) |
2265 | dev_err(&ctlr->dev, "queue remove failed\n"); | 2259 | dev_err(&ctlr->dev, "queue remove failed\n"); |
@@ -2272,7 +2266,8 @@ void spi_unregister_controller(struct spi_controller *ctlr) | |||
2272 | device_unregister(&ctlr->dev); | 2266 | device_unregister(&ctlr->dev); |
2273 | /* free bus id */ | 2267 | /* free bus id */ |
2274 | mutex_lock(&board_lock); | 2268 | mutex_lock(&board_lock); |
2275 | idr_remove(&spi_master_idr, id); | 2269 | if (found == ctlr) |
2270 | idr_remove(&spi_master_idr, id); | ||
2276 | mutex_unlock(&board_lock); | 2271 | mutex_unlock(&board_lock); |
2277 | } | 2272 | } |
2278 | EXPORT_SYMBOL_GPL(spi_unregister_controller); | 2273 | EXPORT_SYMBOL_GPL(spi_unregister_controller); |