kobject: hide illegible sysfs warning of kobject_del()
Subsystems (2)
PATCH 1/1 kobject: hide illegible sysfs warning of kobject_del()
Some consumers do not care whether kobject_add() succeed or failed such as irqdesc. They call kobject_del() all the time even if kobject_add() failed. Then kernel will report some illegible sysfs warning like this:
kernfs: can not remove 'actions', no directory
WARNING: CPU: 0 PID: 277 at fs/kernfs/dir.c:1615 kernfs_remove_by_name_ns+0xd5/0xe0 [...] Call Trace: <TASK> remove_files.isra.0+0x3f/0xb0 sysfs_remove_group+0x68/0xe0 sysfs_remove_groups+0x41/0x70 __kobject_del+0x45/0xc0 kobject_del+0x2a/0x40 free_desc+0x44/0x70 irq_free_descs+0x5d/0x90
[...]
Check whether kobject is added successfully by using kobj->state_in_sysfs in kobject_del() and skip deleting it if not added at all.
--- lib/kobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
@@ -604,7 +604,7 @@ void kobject_del(struct kobject *kobj) {struct kobject *parent; -if (!kobj) +if (!kobj || !kobj->state_in_sysfs)return ; parent = kobj->parent;
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerQuoted 6 lines · Liu Shixin
Some consumers do not care whether
kobject_add()succeed or failed such as irqdesc. They callkobject_del()all the time even ifkobject_add()failed. Then kernel will report some illegible sysfs warning like this:kernfs: can not remove 'actions', no directory
WARNING: CPU: 0 PID: 277 at fs/kernfs/dir.c:1615 kernfs_remove_by_name_ns+0xd5/0xe0
Why not fix the caller here? Is that somehow not possible?
thanks,
greg k-h
Quoted 8 lines · Greg Kroah-Hartman
Quoted 6 lines · Liu Shixin
Some consumers do not care whether
kobject_add()succeed or failed such as irqdesc. They callkobject_del()all the time even ifkobject_add()failed. Then kernel will report some illegible sysfs warning like this:kernfs: can not remove 'actions', no directory
WARNING: CPU: 0 PID: 277 at fs/kernfs/dir.c:1615 kernfs_remove_by_name_ns+0xd5/0xe0Why not fix the caller here? Is that somehow not possible?
The caller should be freed by kobject_put() if kobject_add() failed. But in fact, the failure does not affect the function of the caller. So the caller do not call kobject_put() Immediately.
If want to fix the caller, we can check konj->state_in_sysfs before call kobject_del(). This way has no difference with check kobj->state_in_sysfs in kobject_del().
By the way, I'm not sure how many callers have this problem. So I think it's better to fix in kobject_del().
thanks,
Quoted 6 lines
thanks,
greg k-h
.
Greg Kroah-Hartman
maintainerQuoted 8 lines · Liu Shixin
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Liu Shixin
Some consumers do not care whether
kobject_add()succeed or failed such as irqdesc. They callkobject_del()all the time even ifkobject_add()failed. Then kernel will report some illegible sysfs warning like this:
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
kernfs: can not remove 'actions', no directory
WARNING: CPU: 0 PID: 277 at fs/kernfs/dir.c:1615 kernfs_remove_by_name_ns+0xd5/0xe0Why not fix the caller here? Is that somehow not possible?
The caller should be freed by
kobject_put()ifkobject_add()failed. But in fact, the failure does not affect the function of the caller. So the caller do not callkobject_put()Immediately.
If want to fix the caller, we can checkkonj->state_in_sysfsbefore callkobject_del(). This way has no difference with checkkobj->state_in_sysfsinkobject_del().
No, no code should ever be checking the state_in_sysfs flag before calling this function.
When a kobject is done with, by the creator of it, then it can call kobject_del(). It can NOT call that function multiple times, as that is just wrong and goes against the whole way the kobject should be used.
So there is something very wrong with the caller code here, THAT should be fixed.
Quoted 1 line
By the way, I'm not sure how many callers have this problem. So I think it's better to fix in
kobject_del().
As we have never had this report before, I don't know of many problem users.
Let's fix the root of the problem here please, do not paper over it by allowing this function to be called multiple times, as that is an indication that the reference counting logic of the caller is very wrong.
thanks,
greg k-h