misc: tifm: Remove the adapter ID after device_del()
Subsystems (2)
PATCH 1/1 misc: tifm: Remove the adapter ID after device_del()
tifm_remove_adapter() removes the adapter ID from tifm_adapter_idr before device_del() removes the "tifm<N>" device. An adapter added in between, for example by another TI FlashMedia controller being probed, can get the same ID, and its device_add() fails:
sysfs: cannot create duplicate filename '/class/tifm_adapter/tifm0'
Remove the ID after device_del(), as the error path of tifm_add_adapter() already does.
---
Found with a static analysis tool we are developing.
Reproduced in QEMU (x86_64) with a test module that runs two kthreads for 20 seconds. Each kthread allocates, adds, removes and frees an adapter in a loop, under its own platform device as the parent. Without this patch, tifm_add_adapter() failed with -EEXIST 125066 to 126356 times per run in three runs. With it, it never failed in three runs.
Not tested on TI FlashMedia hardware.
drivers/misc/tifm_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/tifm_core.c +1 -1
@@ -223,10 +223,10 @@ void tifm_remove_adapter(struct tifm_adapter *fm)device_unregister (&fm->sockets[cnt]->dev); } +device_del (&fm->dev);spin_lock (&tifm_adapter_lock);idr_remove (&tifm_adapter_idr, fm->id);spin_unlock (&tifm_adapter_lock); -device_del (&fm->dev); }EXPORT_SYMBOL (tifm_remove_adapter);
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
Signature · 1 line
2.43.0