Calling devm_spi_register_controller() too early will cause problem.
When probe failed occurs after calling devm_spi_register_controller(),
the call of spi_controller_put() will trigger the following warning dump.
[2.092138] [ cut here ]
[2.096876] kernfs: can not remove 'uevent', no directory
[2.102440] WARNING: CPU: 0 PID: 181 at fs/kernfs/dir.c:1503
kernfs_remove_by_name_ns+0xa0/0xb0
[2.42] Modules linked in:
[2.114207] CPU: 0 PID: 181 Comm: kworker/0:7 Not tainted
5.4.24-05024-g775c6e8a738c-dirty #1314
[2.122991] Hardware name: Freescale i.MX8DXL EVK (DT)
[2.128141] Workqueue: events deferred_probe_work_func
[2.133281] pstate: 6005 (nZCv daif -PAN -UAO)
[2.138076] pc : kernfs_remove_by_name_ns+0xa0/0xb0
[2.142958] lr : kernfs_remove_by_name_ns+0xa0/0xb0
[2.147837] sp : 8000122bba70
[2.151145] x29: 8000122bba70 x28: 8000119d6000
[2.156462] x27: x26: 800011edbce8
[2.161779] x25: x24: 3ae4f700
[2.167096] x23: 10184c10 x22: 3a3d6200
[2.172412] x21: 800011a464a8 x20: 10126a68
[2.177729] x19: 3ae5c800 x18: 000e
[2.183046] x17: 0001 x16: 0019
[2.188362] x15: 0004 x14: 004c
[2.193679] x13: x12: 0001
[2.198996] x11: x10: 09c0
[2.204313] x9 : 8000122bb7a0 x8 : 3a3d6c20
[2.209630] x7 : 3a3d6380 x6 : 0001
[2.214946] x5 : 0001 x4 : 3a05eb18
[2.220263] x3 : 0005 x2 : 8000119f1c48
[2.225580] x1 : 2bcbda323bf5a800 x0 :
[2.230898] Call trace:
[2.233345] kernfs_remove_by_name_ns+0xa0/0xb0
[2.237879] sysfs_remove_file_ns+0x14/0x20
[2.242065] device_del+0x12c/0x348
[2.24] device_unregister+0x14/0x30
[2.249492] spi_unregister_controller+0xac/0x120
[2.254201] devm_spi_unregister+0x10/0x18
[2.258304] release_nodes+0x1a8/0x220
[2.262055] devres_release_all+0x34/0x58
[2.266069] really_probe+0x1b8/0x318
[2.269733] driver_probe_device+0x54/0xe8
[2.273833] __device_attach_driver+0x80/0xb8
[2.278194] bus_for_each_drv+0x74/0xc0
[2.282034] __device_attach+0xdc/0x138
[2.285876] device_initial_probe+0x10/0x18
[2.290063] bus_probe_device+0x90/0x98
[2.293901] deferred_probe_work_func+0x64/0x98
[2.298442] process_one_work+0x198/0x320
[2.302451] worker_thread+0x1f0/0x420
[2.306208] kthread+0xf0/0x120
[2.309352] ret_from_fork+0x10/0x18
[2.312927] ---[ end trace 58abcdfae01bd3c7 ]---
So put this function at the end of the probe sequence.
Signed-off-by: Clark Wang
---
Changes:
V2:
- redo the patch base on the new code.
---
drivers/spi/spi-fsl-lpspi.c | 12 ++--
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index a4a42e85e132..b0a1bb62f10a 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -850,12 +850,6 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
if (!fsl_lpspi->is_slave)
controller->use_gpio_descriptors = true;
- ret = devm_spi_register_controller(>dev, controller);
- if (ret < 0) {
- dev_err(>dev, "spi_register_controller error.\n");
- goto out_controller_put;
- }
-
init_completion(_lpspi->xfer_done);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -913,6 +907,12 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
if (ret < 0)
dev_err(>dev, "dma setup error %d, use pio\n", ret);
+ ret = devm_spi_register_controller(>dev, controller);
+ if (ret < 0) {
+ dev_err(>dev, "spi_register_controller error.\n");
+ goto out_pm_get;
+ }
+
pm_runtime_mark_last_busy(fsl_lpspi->dev);
pm_runtime_put_autosuspend(fsl_lpspi->dev);
--
2.17.1