linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH] pm / wakeup: simplify the output logic of pm_show_wakelocks()
Date: Fri, 14 Jan 2022 10:10:02 +0000	[thread overview]
Message-ID: <YeFL+g64SL3m/mVW@google.com> (raw)
In-Reply-To: <20220113184420.2504545-1-gregkh@linuxfoundation.org>

On Thu, 13 Jan 2022, Greg Kroah-Hartman wrote:

> 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.
> 
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Len Brown <len.brown@intel.com>
> Cc: linux-pm@vger.kernel.org
> Cc: Lee Jones <lee.jones@linaro.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  kernel/power/wakelock.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)

Reviewed-by: Lee Jones <lee.jones@linaro.org>

> diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c
> index 105df4dfc783..52571dcad768 100644
> --- a/kernel/power/wakelock.c
> +++ b/kernel/power/wakelock.c
> @@ -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

-- 
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

  reply	other threads:[~2022-01-14 10:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 18:44 [PATCH] pm / wakeup: simplify the output logic of pm_show_wakelocks() Greg Kroah-Hartman
2022-01-14 10:10 ` Lee Jones [this message]
2022-01-25 17:28   ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YeFL+g64SL3m/mVW@google.com \
    --to=lee.jones@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).