In WRL 19 SPI controller registration may fail in case of a deferred probe. Some error paths leave the bus id allocated. As a result the IDR allocation will fail after a deferred probe. Fix by freeing the bus id always on error. Proposed 5.6 upstream patch: [https://marc.info/?l=linux-spi&m=158332069108240&w=2] Sample console output: Wind River Linux 10.19.45.2 [ 6.752109] ------------[ cut here ]------------ [ 6.756721] couldn't get idr [ 6.756790] WARNING: CPU: 0 PID: 34 at drivers/spi/spi.c:2307 spi_register_controller+0x5c8/0x768 [ 6.768483] Modules linked in: [ 6.771530] CPU: 0 PID: 34 Comm: kworker/0:1 Not tainted 5.2.21-nokia-r8 #1 [ 6.778459] Hardware name: SoCFPGA Stratix 10 ABIL (DT) [ 6.783668] Workqueue: events deferred_probe_work_func [ 6.788785] pstate: 60000005 (nZCv daif -PAN -UAO) [ 6.793555] pc : spi_register_controller+0x5c8/0x768 [ 6.798497] lr : spi_register_controller+0x5c8/0x768 [ 6.803438] sp : ffff00001120ba20 [ 6.806737] x29: ffff00001120ba20 x28: ffff000010f46000 [ 6.812026] x27: ffff80007c753410 x26: ffff80007c6bcfb8 [ 6.817315] x25: 0000000000000006 x24: 0000000000000000 [ 6.822604] x23: ffff000011001438 x22: ffff80007c708000 [ 6.827894] x21: 00000000ffffffe4 x20: ffff0000110012f8 [ 6.833183] x19: ffff800014592800 x18: 0000000000000010 [ 6.838471] x17: 0000000000000000 x16: 0000000000000000 [ 6.843761] x15: ffff80007c708448 x14: ffffffffffffffff [ 6.849050] x13: ffff00009120b6e7 x12: ffff00001120b6ef [ 6.854339] x11: ffff000010f66000 x10: ffff0000110922b0 [ 6.859628] x9 : ffff00001120ba20 x8 : 7264692074656720 [ 6.864917] x7 : 74276e646c756f63 x6 : ffff000011092300 [ 6.870206] x5 : 0000000000000000 x4 : 0000000000000000 [ 6.875495] x3 : 00000000ffffffff x2 : 000080006dd6c000 [ 6.880784] x1 : 9750f486ee299400 x0 : 0000000000000000 [ 6.886073] Call trace: [ 6.888510] spi_register_controller+0x5c8/0x768 [ 6.893106] devm_spi_register_controller+0x48/0x98 [ 6.897965] dw_spi_add_host+0x168/0x280 [ 6.901871] dw_spi_mmio_probe+0x1cc/0x250 [ 6.905952] platform_drv_probe+0x58/0xa8 [ 6.909944] really_probe+0xe0/0x3f0 [ 6.913504] driver_probe_device+0x6c/0x138 [ 6.917668] __device_attach_driver+0xa0/0x118 [ 6.922092] bus_for_each_drv+0x88/0xd8 [ 6.925912] __device_attach+0xe4/0x168 [ 6.929731] device_initial_probe+0x24/0x30 [ 6.933895] bus_probe_device+0x9c/0xa8 [ 6.937714] deferred_probe_work_func+0x94/0xe0 [ 6.942228] process_one_work+0x1bc/0x440 [ 6.946219] worker_thread+0x218/0x408 [ 6.949953] kthread+0x104/0x130 [ 6.953169] ret_from_fork+0x10/0x1c [ 6.956728] ---[ end trace b3a061bbf47c4847 ]--- [ 6.961396] spi_master (null): problem registering spi master [ 6.967208] dw_spi_mmio: probe of ffda5000.spi failed with error -16