Skip to content

Commit 2434aea

Browse files
vo4rafaeljw
authored andcommitted
PM / wakeup: Use wakeup_source_register() in wakelock.c
kernel/power/wakelock.c duplicates wakeup source creation and registration code from drivers/base/power/wakeup.c. Change struct wakelock's wakeup source to a pointer and use wakeup_source_register() function to create and register said wakeup source. Use wakeup_source_unregister() on cleanup path. Signed-off-by: Tri Vo <trong@android.com> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 0d105d0 commit 2434aea

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

‎kernel/power/wakelock.c‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static DEFINE_MUTEX(wakelocks_lock);
2727
struct wakelock {
2828
char *name;
2929
struct rb_node node;
30-
struct wakeup_source ws;
30+
struct wakeup_source *ws;
3131
#ifdef CONFIG_PM_WAKELOCKS_GC
3232
struct list_head lru;
3333
#endif
@@ -46,7 +46,7 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active)
4646

4747
for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) {
4848
wl = rb_entry(node, struct wakelock, node);
49-
if (wl->ws.active == show_active)
49+
if (wl->ws->active == show_active)
5050
str += scnprintf(str, end - str, "%s ", wl->name);
5151
}
5252
if (str > buf)
@@ -112,16 +112,16 @@ static void __wakelocks_gc(struct work_struct *work)
112112
u64 idle_time_ns;
113113
bool active;
114114

115-
spin_lock_irq(&wl->ws.lock);
116-
idle_time_ns = ktime_to_ns(ktime_sub(now, wl->ws.last_time));
117-
active = wl->ws.active;
118-
spin_unlock_irq(&wl->ws.lock);
115+
spin_lock_irq(&wl->ws->lock);
116+
idle_time_ns = ktime_to_ns(ktime_sub(now, wl->ws->last_time));
117+
active = wl->ws->active;
118+
spin_unlock_irq(&wl->ws->lock);
119119

120120
if (idle_time_ns < ((u64)WL_GC_TIME_SEC * NSEC_PER_SEC))
121121
break;
122122

123123
if (!active) {
124-
wakeup_source_remove(&wl->ws);
124+
wakeup_source_unregister(wl->ws);
125125
rb_erase(&wl->node, &wakelocks_tree);
126126
list_del(&wl->lru);
127127
kfree(wl->name);
@@ -187,9 +187,15 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
187187
kfree(wl);
188188
return ERR_PTR(-ENOMEM);
189189
}
190-
wl->ws.name = wl->name;
191-
wl->ws.last_time = ktime_get();
192-
wakeup_source_add(&wl->ws);
190+
191+
wl->ws = wakeup_source_register(wl->name);
192+
if (!wl->ws) {
193+
kfree(wl->name);
194+
kfree(wl);
195+
return ERR_PTR(-ENOMEM);
196+
}
197+
wl->ws->last_time = ktime_get();
198+
193199
rb_link_node(&wl->node, parent, node);
194200
rb_insert_color(&wl->node, &wakelocks_tree);
195201
wakelocks_lru_add(wl);
@@ -233,9 +239,9 @@ int pm_wake_lock(const char *buf)
233239
u64 timeout_ms = timeout_ns + NSEC_PER_MSEC - 1;
234240

235241
do_div(timeout_ms, NSEC_PER_MSEC);
236-
__pm_wakeup_event(&wl->ws, timeout_ms);
242+
__pm_wakeup_event(wl->ws, timeout_ms);
237243
} else {
238-
__pm_stay_awake(&wl->ws);
244+
__pm_stay_awake(wl->ws);
239245
}
240246

241247
wakelocks_lru_most_recent(wl);
@@ -271,7 +277,7 @@ int pm_wake_unlock(const char *buf)
271277
ret = PTR_ERR(wl);
272278
goto out;
273279
}
274-
__pm_relax(&wl->ws);
280+
__pm_relax(wl->ws);
275281

276282
wakelocks_lru_most_recent(wl);
277283
wakelocks_gc();

0 commit comments

Comments
 (0)