linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
@ 2022-05-21  6:35 Yi Yang
  2022-05-24  7:10 ` Viresh Kumar
  0 siblings, 1 reply; 7+ messages in thread
From: Yi Yang @ 2022-05-21  6:35 UTC (permalink / raw)
  To: rafael, viresh.kumar; +Cc: linux-pm, linux-kernel, yiyang13

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");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2022-05-24  7:10 UTC (permalink / raw)
  To: Yi Yang; +Cc: rafael, linux-pm, linux-kernel

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>

-- 
viresh

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
  2022-05-24  7:10 ` Viresh Kumar
@ 2022-06-14 13:37   ` Rafael J. Wysocki
  2022-06-14 13:48     ` Rafael J. Wysocki
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2022-06-14 13:37 UTC (permalink / raw)
  To: Viresh Kumar, Yi Yang
  Cc: Rafael J. Wysocki, Linux PM, Linux Kernel Mailing List

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!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
  2022-06-14 13:37   ` Rafael J. Wysocki
@ 2022-06-14 13:48     ` Rafael J. Wysocki
  2022-06-15  4:56       ` Viresh Kumar
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2022-06-14 13:48 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Viresh Kumar, Yi Yang, Linux PM, Linux Kernel Mailing List

On Tue, Jun 14, 2022 at 3:37 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> 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!

And dropped, because it has been superseded by this one:

https://patchwork.kernel.org/project/linux-pm/patch/b9fa08171c09343ace94a7343553a4bee4695c90.1653565641.git.viresh.kumar@linaro.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
  2022-06-14 13:48     ` Rafael J. Wysocki
@ 2022-06-15  4:56       ` Viresh Kumar
  2022-06-18 10:32         ` yiyang (D)
  0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2022-06-15  4:56 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Yi Yang, Linux PM, Linux Kernel Mailing List

On 14-06-22, 15:48, Rafael J. Wysocki wrote:
> On Tue, Jun 14, 2022 at 3:37 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > 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!
> 
> And dropped, because it has been superseded by this one:
> 
> https://patchwork.kernel.org/project/linux-pm/patch/b9fa08171c09343ace94a7343553a4bee4695c90.1653565641.git.viresh.kumar@linaro.org/

The $Subject patch is still required AFAICT, it is fixing a different problem.
Though it needs to be rebased on top of your branch now.

-- 
viresh

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
  2022-06-15  4:56       ` Viresh Kumar
@ 2022-06-18 10:32         ` yiyang (D)
  2022-06-20  4:24           ` Viresh Kumar
  0 siblings, 1 reply; 7+ messages in thread
From: yiyang (D) @ 2022-06-18 10:32 UTC (permalink / raw)
  To: Viresh Kumar, Rafael J. Wysocki; +Cc: Linux PM, Linux Kernel Mailing List


On 2022/6/15 12:56, Viresh Kumar wrote:
> On 14-06-22, 15:48, Rafael J. Wysocki wrote:
>> On Tue, Jun 14, 2022 at 3:37 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>>>
>>> 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!
>>
>> And dropped, because it has been superseded by this one:
>>
>> https://patchwork.kernel.org/project/linux-pm/patch/b9fa08171c09343ace94a7343553a4bee4695c90.1653565641.git.viresh.kumar@linaro.org/
> 
> The $Subject patch is still required AFAICT, it is fixing a different problem.
> Though it needs to be rebased on top of your branch now.
> 

What can i do for this patch?

--
Yi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -next] cpufreq: Fix reserved space in cpufreq_show_cpus()
  2022-06-18 10:32         ` yiyang (D)
@ 2022-06-20  4:24           ` Viresh Kumar
  0 siblings, 0 replies; 7+ messages in thread
From: Viresh Kumar @ 2022-06-20  4:24 UTC (permalink / raw)
  To: yiyang (D); +Cc: Rafael J. Wysocki, Linux PM, Linux Kernel Mailing List

On 18-06-22, 18:32, yiyang (D) wrote:
> What can i do for this patch?

Resend it after rebasing on pm/linux-next.

-- 
viresh

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-20  4:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).