1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-23 16:53:58 -05:00

PM: wakeup: simplify the output logic of pm_show_wakelocks()

The buffer handling in pm_show_wakelocks() is tricky, and hopefully
correct.  Ensure it really is correct by using sysfs_emit_at() which
handles all of the tricky string handling logic in a PAGE_SIZE buffer
for us automatically as this is a sysfs file being read from.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Greg Kroah-Hartman 2022-01-13 19:44:20 +01:00 committed by Rafael J. Wysocki
parent e783362eb5
commit c9d967b2ce

View file

@ -39,23 +39,20 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active)
{ {
struct rb_node *node; struct rb_node *node;
struct wakelock *wl; struct wakelock *wl;
char *str = buf; int len = 0;
char *end = buf + PAGE_SIZE;
mutex_lock(&wakelocks_lock); mutex_lock(&wakelocks_lock);
for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) { for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) {
wl = rb_entry(node, struct wakelock, node); wl = rb_entry(node, struct wakelock, node);
if (wl->ws->active == show_active) if (wl->ws->active == show_active)
str += scnprintf(str, end - str, "%s ", wl->name); len += sysfs_emit_at(buf, len, "%s ", wl->name);
} }
if (str > buf)
str--;
str += scnprintf(str, end - str, "\n"); len += sysfs_emit_at(buf, len, "\n");
mutex_unlock(&wakelocks_lock); mutex_unlock(&wakelocks_lock);
return (str - buf); return len;
} }
#if CONFIG_PM_WAKELOCKS_LIMIT > 0 #if CONFIG_PM_WAKELOCKS_LIMIT > 0