extcon: Fixed sysfs duplicate filename issue
PATCH v2 1/1 extcon: Fixed sysfs duplicate filename issue
With current extcon_dev_unregister() timing, ida_free is before device_unregister(), that may cause current id re-alloc to another device in extcon_dev_register() context but sysfs filename path not removal completed yet.
The right timing shows below:
on extcon_dev_register: ida_alloc() -> device_register() on extcon_dev_unregister: device_unregister() -> ida_free()
stack information when an error occurs:
sysfs: cannot create duplicate filename '/class/extcon/extcon1'
Call trace: dump_backtrace+0xe8/0x108 show_stack+0x18/0x28 dump_stack_lvl+0x50/0x6c dump_stack+0x18/0x24 sysfs_warn_dup+0x68/0x88 sysfs_do_create_link_sd+0x94/0xdc sysfs_create_link+0x30/0x48 device_add_class_symlinks+0xb4/0x12c device_add+0x1e0/0x48c device_register+0x20/0x34 extcon_dev_register+0x3b8/0x5c4 devm_extcon_dev_register+0x4c/0x94
---
ChangeLog:
V1 -> V2: Update commit msg, suggested by Markus Elfring
V1: https://lore.kernel.org/all/[email protected]/
---
--- drivers/extcon/extcon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/extcon/extcon.c +2 -2
@@ -1371,10 +1371,10 @@ void extcon_dev_unregister(struct extcon_dev *edev)return ; } -ida_free (&extcon_dev_ids, edev->id); -device_unregister (&edev->dev); +ida_free (&extcon_dev_ids, edev->id); +if (edev->mutually_exclusive && edev->max_supported) {for (index =0 ; edev->mutually_exclusive[index]; index++)
Signature · 1 line
2.29.0
On Wed, Oct 15, 2025 at 02:51:02PM +0800, Michael Wu wrote:
Thank you for a fix, my comments below.
Quoted 9 lines
With current
extcon_dev_unregister()timing,ida_freeis beforedevice_unregister(), that may cause current id re-alloc to another device inextcon_dev_register()context but sysfs filename path not removal completed yet.The right timing shows below:
onextcon_dev_register:ida_alloc()->device_register()onextcon_dev_unregister:device_unregister()->ida_free()
Quoted 8 lines
stack information when an error occurs:
sysfs: cannot create duplicate filename '/class/extcon/extcon1'Call trace: dump_backtrace+0xe8/0x108 show_stack+0x18/0x28 dump_stack_lvl+0x50/0x6c dump_stack+0x18/0x24
At least these four lines are noisy in the commit message. The Submitting Patches documentation recommends to leave ~3-5 important lines out of a trace back, so the below is okay in my opinion, except the last line also can be dropped (devm call).
Quoted 11 lines
sysfs_warn_dup+0x68/0x88 sysfs_do_create_link_sd+0x94/0xdc sysfs_create_link+0x30/0x48 device_add_class_symlinks+0xb4/0x12c device_add+0x1e0/0x48c device_register+0x20/0x34 extcon_dev_register+0x3b8/0x5c4 devm_extcon_dev_register+0x4c/0x94Fixes 7bba9e81a6fb ("extcon: Use unique number for the extcon device ID")Cc Andy Shevchenko <[email protected]>
Better to reduce a noise in the Git history by moving the Cc:s to the...
Quoted 3 lines
Acked-by MyungJoo Ham <[email protected]>Signed-off-by Michael Wu <[email protected]>---
...comment block here. It will have the same effect on the emails (tools will Cc people listed here).
Quoted 3 lines
ChangeLog:
V1 -> V2: Update commit msg, suggested by Markus Elfring
V1: https://lore.kernel.org/all/[email protected]/
Code wise LGTM, FWIW,
Signature · 2 lines
With Best Regards, Andy Shevchenko