Skip to contentSkip to conversation

PM / wakeup: Skip wakeup_source_sysfs_remove if device is not added

PATCH In review Neeraj Upadhyay 2 participants 2 messages Mar 23, 2020 – Mar 25, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / wakeup: Skip wakeup_source_sysfs_remove if device is not added

Skip wakeup_source_sysfs_remove(), to fix null pinter access of ws->dev, if wakeup source is unregistered before wakeup class is registered from device_add().

Fixes 2ca3d1ecb8c4 ("PM / wakeup: Register wakeup class kobj after device is added")
---
 drivers/base/power/wakeup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/power/wakeup.c +2 -1
index 27f3e60..f8f8c0a 100644
@@ -241,7 +241,8 @@ void wakeup_source_unregister(struct wakeup_source *ws)
 {
 	if (ws) {
 		wakeup_source_remove(ws);
-		wakeup_source_sysfs_remove(ws);
+		if (ws->dev)
+			wakeup_source_sysfs_remove(ws);
 		wakeup_source_destroy(ws);
 	}
 }
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw
Quoted 16 lines · CET Neeraj Upadhyay

Skip wakeup_source_sysfs_remove(), to fix null pinter access of ws->dev, if wakeup source is unregistered before wakeup class is registered from device_add().

Fixes 2ca3d1ecb8c4 ("PM / wakeup: Register wakeup class kobj after device is added")
---
 drivers/base/power/wakeup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/power/wakeup.c +0 -0
index 27f3e60..f8f8c0a 100644

drivers/base/power/wakeup.c void wakeup_source_unregister(struct wakeup_source *ws) · line 248

Quoted 9 lines
drivers/base/power/wakeup.c +2 -1
@@ -241,7 +241,8 @@ void wakeup_source_unregister(struct wakeup_source *ws)
 {
 	if (ws) {
 		wakeup_source_remove(ws);
-		wakeup_source_sysfs_remove(ws);
+		if (ws->dev)
+			wakeup_source_sysfs_remove(ws);
 		wakeup_source_destroy(ws);
 	}
 }

Applied (with some minor changes) as 5.7 material, thanks!