Skip to content

Commit c9d967b

Browse files
gregkhrafaeljw
authored andcommitted
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 <[email protected]> Reviewed-by: Lee Jones <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e783362 commit c9d967b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

kernel/power/wakelock.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,20 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active)
3939
{
4040
struct rb_node *node;
4141
struct wakelock *wl;
42-
char *str = buf;
43-
char *end = buf + PAGE_SIZE;
42+
int len = 0;
4443

4544
mutex_lock(&wakelocks_lock);
4645

4746
for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) {
4847
wl = rb_entry(node, struct wakelock, node);
4948
if (wl->ws->active == show_active)
50-
str += scnprintf(str, end - str, "%s ", wl->name);
49+
len += sysfs_emit_at(buf, len, "%s ", wl->name);
5150
}
52-
if (str > buf)
53-
str--;
5451

55-
str += scnprintf(str, end - str, "\n");
52+
len += sysfs_emit_at(buf, len, "\n");
5653

5754
mutex_unlock(&wakelocks_lock);
58-
return (str - buf);
55+
return len;
5956
}
6057

6158
#if CONFIG_PM_WAKELOCKS_LIMIT > 0

0 commit comments

Comments
 (0)