pm / wakeup: simplify the output logic of pm_show_wakelocks()
Subsystems (2)
PATCH 1/1 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.
--- kernel/power/wakelock.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
kernel/power/wakelock.c +4 -7
@@ -39,23 +39,20 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active) {struct rb_node *node;struct wakelock *wl; -char *str = buf; -char *end = buf +PAGE_SIZE ; +int len =0 ;mutex_lock (&wakelocks_lock);for (node =rb_first (&wakelocks_tree); node; node =rb_next (node)) { wl = rb_entry(node, struct wakelock, node);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); -return (str - buf); +return len; }#if CONFIG_PM_WAKELOCKS_LIMIT >0
Signature · 1 line
2.34.1
Quoted 11 lines · Greg Kroah-Hartman
The buffer handling in
pm_show_wakelocks()is tricky, and hopefully correct. Ensure it really is correct by usingsysfs_emit_at()which handles all of the tricky string handling logic in aPAGE_SIZEbuffer for us automatically as this is a sysfs file being read from.Cc "Rafael J. Wysocki" <[email protected]>Cc Pavel Machek <[email protected]>Cc Len Brown <[email protected]>Cc Lee Jones <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 3 lines
--- kernel/power/wakelock.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Quoted 32 lines
kernel/power/wakelock.c +4
-7@@ -39,23 +39,20 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active) {struct rb_node *node;struct wakelock *wl; -char *str = buf; -char *end = buf +PAGE_SIZE ; +int len =0 ;mutex_lock (&wakelocks_lock);for (node =rb_first (&wakelocks_tree); node; node =rb_next (node)) { wl = rb_entry(node, struct wakelock, node);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); -return (str - buf); +return len; }#if CONFIG_PM_WAKELOCKS_LIMIT >0
Signature · 4 lines
Lee Jones [李琼斯] Principal Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 18 lines · Lee Jones
Quoted 11 lines · Greg Kroah-Hartman
The buffer handling in
pm_show_wakelocks()is tricky, and hopefully correct. Ensure it really is correct by usingsysfs_emit_at()which handles all of the tricky string handling logic in aPAGE_SIZEbuffer for us automatically as this is a sysfs file being read from.Cc "Rafael J. Wysocki" <[email protected]>Cc Pavel Machek <[email protected]>Cc Len Brown <[email protected]>Cc Lee Jones <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Quoted 3 lines
--- kernel/power/wakelock.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Quoted 1 line
Reviewed-by Lee Jones <[email protected]>
Applied as 5.18 material, thanks!
Quoted 39 lines
Quoted 23 lines
kernel/power/wakelock.c +2
-5@@ -39,23 +39,20 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active) {struct rb_node *node;struct wakelock *wl; -char *str = buf; -char *end = buf +PAGE_SIZE ; +int len =0 ;mutex_lock (&wakelocks_lock);for (node =rb_first (&wakelocks_tree); node; node =rb_next (node)) { wl = rb_entry(node, struct wakelock, node);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--;kernel/power/wakelock.c ssize_t pm_show_wakelocks(char *buf, bool show_active) · line 58
Quoted 10 lines
kernel/power/wakelock.c +2
-2- str +=scnprintf (str, end - str,"\n" ); + len +=sysfs_emit_at (buf, len,"\n" );mutex_unlock (&wakelocks_lock); -return (str - buf); +return len; }#if CONFIG_PM_WAKELOCKS_LIMIT >0 --
Lee Jones [李琼斯]
Principal Technical Lead - Developer ServicesLinaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog