* [RFC] percpu: use nr_groups as check condition
@ 2019-02-20 13:32 Peng Fan
2019-02-23 22:46 ` Dennis Zhou
0 siblings, 1 reply; 2+ messages in thread
From: Peng Fan @ 2019-02-20 13:32 UTC (permalink / raw)
To: dennis, tj, cl; +Cc: linux-mm, linux-kernel, van.freenix, Peng Fan
group_cnt array is defined with NR_CPUS entries, but normally
nr_groups will not reach up to NR_CPUS. So there is no issue
to the current code.
Checking other parts of pcpu_build_alloc_info, use nr_groups as
check condition, so make it consistent to use 'group < nr_groups'
as for loop check. In case we do have nr_groups equals with NR_CPUS,
we could also avoid memory access out of bounds.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
mm/percpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/percpu.c b/mm/percpu.c
index db86282fd024..c5c750781628 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -2384,7 +2384,7 @@ static struct pcpu_alloc_info * __init pcpu_build_alloc_info(
ai->atom_size = atom_size;
ai->alloc_size = alloc_size;
- for (group = 0, unit = 0; group_cnt[group]; group++) {
+ for (group = 0, unit = 0; group < nr_groups; group++) {
struct pcpu_group_info *gi = &ai->groups[group];
/*
--
2.16.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC] percpu: use nr_groups as check condition
2019-02-20 13:32 [RFC] percpu: use nr_groups as check condition Peng Fan
@ 2019-02-23 22:46 ` Dennis Zhou
0 siblings, 0 replies; 2+ messages in thread
From: Dennis Zhou @ 2019-02-23 22:46 UTC (permalink / raw)
To: Peng Fan; +Cc: dennis, tj, cl, linux-mm, linux-kernel, van.freenix
Hi Peng,
On Wed, Feb 20, 2019 at 01:32:55PM +0000, Peng Fan wrote:
> group_cnt array is defined with NR_CPUS entries, but normally
> nr_groups will not reach up to NR_CPUS. So there is no issue
> to the current code.
>
> Checking other parts of pcpu_build_alloc_info, use nr_groups as
> check condition, so make it consistent to use 'group < nr_groups'
> as for loop check. In case we do have nr_groups equals with NR_CPUS,
> we could also avoid memory access out of bounds.
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
> mm/percpu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/percpu.c b/mm/percpu.c
> index db86282fd024..c5c750781628 100644
> --- a/mm/percpu.c
> +++ b/mm/percpu.c
> @@ -2384,7 +2384,7 @@ static struct pcpu_alloc_info * __init pcpu_build_alloc_info(
> ai->atom_size = atom_size;
> ai->alloc_size = alloc_size;
>
> - for (group = 0, unit = 0; group_cnt[group]; group++) {
> + for (group = 0, unit = 0; group < nr_groups; group++) {
> struct pcpu_group_info *gi = &ai->groups[group];
>
> /*
> --
> 2.16.4
>
This seems right to me. It is quite the edge case though. I've queued
this for 5.1.
Thanks,
Dennis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-23 22:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-20 13:32 [RFC] percpu: use nr_groups as check condition Peng Fan
2019-02-23 22:46 ` Dennis Zhou
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).