linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Viresh Kumar <viresh.kumar@linaro.org>, Yi Yang <yiyang13@huawei.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
Date: Tue, 14 Jun 2022 15:37:20 +0200	[thread overview]
Message-ID: <CAJZ5v0jCx0v-Q2=aW4nSSAHHajUnLdVtQMe3w1cX1w-o=mSesg@mail.gmail.com> (raw)
In-Reply-To: <20220524071041.4aw3cfo3x5wphziy@vireshk-i7>

On Tue, May 24, 2022 at 9:10 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 21-05-22, 14:35, Yi Yang wrote:
> > Function scnprintf() would reserve space for the trailing '\0' and return
> > value is the number of characters written into buf not including the
> > trailing '\0'. internally meaning the next scnprintf() would write begin
> > the trailing '\0'. The code specifying "PAGE_SIZE - i - 2" here is trying
> > to reserve space for "\n\0" which would cause scnprintf() to reserve an
> > additional byte making the tail of the buf looks like this: "\n\0\0".
> > Thus. we should reserve only the space for one '\0'. passing in
> > "PAGE_SIZE - i - 1".
> >
> > Additionally, each iteration would replace the trailing '\0' from the last
> > iteration with a space, and append 4 additional bytes to the string making
> > it a total of 5 additional bytes. That means we should stop printing into
> > the buffer if the remaining size is less than 7 bytes(1 for the ' ', 4 for
> > the %u and 2 for the tailing "\n\0")
> >
> > Signed-off-by: Yi Yang <yiyang13@huawei.com>
> > ---
> >  drivers/cpufreq/cpufreq.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index 1f6667ce43bd..60c005c9961e 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -844,9 +844,9 @@ ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf)
> >
> >       for_each_cpu(cpu, mask) {
> >               if (i)
> > -                     i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
> > -             i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
> > -             if (i >= (PAGE_SIZE - 5))
> > +                     i += scnprintf(&buf[i], (PAGE_SIZE - i - 1), " ");
> > +             i += scnprintf(&buf[i], (PAGE_SIZE - i - 1), "%u", cpu);
> > +             if (i >= (PAGE_SIZE - 6))
> >                       break;
> >       }
> >       i += sprintf(&buf[i], "\n");
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Applied as 5.20 material, thanks!

  reply	other threads:[~2022-06-14 13:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-21  6:35 [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus() Yi Yang
2022-05-24  7:10 ` Viresh Kumar
2022-06-14 13:37   ` Rafael J. Wysocki [this message]
2022-06-14 13:48     ` Rafael J. Wysocki
2022-06-15  4:56       ` Viresh Kumar
2022-06-18 10:32         ` yiyang (D)
2022-06-20  4:24           ` Viresh Kumar

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='CAJZ5v0jCx0v-Q2=aW4nSSAHHajUnLdVtQMe3w1cX1w-o=mSesg@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=yiyang13@huawei.com \
    /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).