public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kobject: hide illegible sysfs warning of kobject_del()
@ 2022-11-11  6:58 Liu Shixin
  2022-11-11  6:26 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Shixin @ 2022-11-11  6:58 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki; +Cc: linux-kernel, Liu Shixin

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.

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 lib/kobject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index a0b2dbfcfa23..f6163a3a41c2 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-11  9:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-11  6:58 [PATCH] kobject: hide illegible sysfs warning of kobject_del() Liu Shixin
2022-11-11  6:26 ` Greg Kroah-Hartman
2022-11-11  8:27   ` Liu Shixin
2022-11-11  9:11     ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox