public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers core: lookup sysfs power group before removal
@ 2023-11-01 17:36 José Pekkarinen
  2023-11-01 17:54 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: José Pekkarinen @ 2023-11-01 17:36 UTC (permalink / raw)
  To: rafael, len.brown, pavel, gregkh, skhan
  Cc: José Pekkarinen, linux-pm, linux-kernel,
	linux-kernel-mentees, syzbot+95f2e2439b97575ec3c0

Hinted by syzboot, there is a few cases where the sysfs power group may
not be there, like the failure while adding it, or adding its runtime
group, or when the sysfs firmware loader fallback fail to populate. In
the last case, the device_del function will be called leading to attempt
to remove the sysfs group. This patch will lookup for it in advance to
grant that it is effectively there before cleaning it up.

Reported-by: syzbot+95f2e2439b97575ec3c0@syzkaller.appspotmail.com

Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
---
 drivers/base/power/sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index a1474fb67db9..6601729c4698 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -834,5 +834,7 @@ void dpm_sysfs_remove(struct device *dev)
 	dev_pm_qos_constraints_destroy(dev);
 	rpm_sysfs_remove(dev);
 	sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
-	sysfs_remove_group(&dev->kobj, &pm_attr_group);
+
+	if (kernfs_find_and_get((&dev->kobj)->sd, pm_attr_group.name))
+		sysfs_remove_group(&dev->kobj, &pm_attr_group);
 }
-- 
2.39.2


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

end of thread, other threads:[~2023-11-07 19:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-01 17:36 [PATCH] drivers core: lookup sysfs power group before removal José Pekkarinen
2023-11-01 17:54 ` Greg KH
2023-11-03 17:49   ` José Pekkarinen
2023-11-03 18:36     ` Greg KH
2023-11-07  8:56       ` José Pekkarinen
2023-11-07  9:53         ` Greg KH
2023-11-07 17:20           ` José Pekkarinen

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