diff mbox series

mm/memblock.c: using judgment statement can reduce loop and enhance readability.

Message ID 20231102023710.13023-1-huanglllzu@gmail.com (mailing list archive)
State New
Headers show
Series mm/memblock.c: using judgment statement can reduce loop and enhance readability. | expand

Commit Message

黄亮亮 Nov. 2, 2023, 2:37 a.m. UTC
From: Liangliang Huang <huangll@lemote.com>

Signed-off-by: Liangliang Huang <huangll@lemote.com>
---
 mm/memblock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Mike Rapoport Nov. 2, 2023, 8:54 a.m. UTC | #1
Hi,

> Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop and enhance readability.

I disagree.

On Thu, Nov 02, 2023 at 10:37:10AM +0800, huanglllzu@gmail.com wrote:
> From: Liangliang Huang <huangll@lemote.com>
> 
> Signed-off-by: Liangliang Huang <huangll@lemote.com>
> ---
>  mm/memblock.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 913b2520a9a0..e48dea7144bb 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -655,7 +655,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
>  			}
>  		}
>  		/* area below @rend is dealt with, forget about it */
> -		base = min(rend, end);
> +		if (end < rend) {
> +			base = end;
> +			break;
> +		} else
> +			base = rend;

min() is perfectly clear and there no change in number of iterations of the
loop.

>  	}
>  
>  	/* insert the remaining portion */
> -- 
> 2.25.1
>
黄亮亮 Nov. 3, 2023, 3:19 a.m. UTC | #2
Hi, this patch can less loop once in this situation:
base more than rbase  and end less than rend.
                base          end
      rbase----|-------------| --------rend
         |          |               |              |
  --------------------------------------------------->

Mike Rapoport <rppt@kernel.org> 于2023年11月2日周四 16:54写道:

> Hi,
>
> > Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop
> and enhance readability.
>
> I disagree.
>
> On Thu, Nov 02, 2023 at 10:37:10AM +0800, huanglllzu@gmail.com wrote:
> > From: Liangliang Huang <huangll@lemote.com>
> >
> > Signed-off-by: Liangliang Huang <huangll@lemote.com>
> > ---
> >  mm/memblock.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/memblock.c b/mm/memblock.c
> > index 913b2520a9a0..e48dea7144bb 100644
> > --- a/mm/memblock.c
> > +++ b/mm/memblock.c
> > @@ -655,7 +655,11 @@ static int __init_memblock
> memblock_add_range(struct memblock_type *type,
> >                       }
> >               }
> >               /* area below @rend is dealt with, forget about it */
> > -             base = min(rend, end);
> > +             if (end < rend) {
> > +                     base = end;
> > +                     break;
> > +             } else
> > +                     base = rend;
>
> min() is perfectly clear and there no change in number of iterations of the
> loop.
>
> >       }
> >
> >       /* insert the remaining portion */
> > --
> > 2.25.1
> >
>
> --
> Sincerely yours,
> Mike.
>
黄亮亮 Nov. 3, 2023, 5:30 a.m. UTC | #3
Hi,this patch can less loop once in this situation:
base more than rbase and end less than rend.
                base           end
    rbase-----|--------------|-------rend
      |            |                 |           |
-------------------------------------------------------->

Mike Rapoport <rppt@kernel.org> 于2023年11月2日周四 16:54写道:

> Hi,
>
> > Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop
> and enhance readability.
>
> I disagree.
>
> On Thu, Nov 02, 2023 at 10:37:10AM +0800, huanglllzu@gmail.com wrote:
> > From: Liangliang Huang <huangll@lemote.com>
> >
> > Signed-off-by: Liangliang Huang <huangll@lemote.com>
> > ---
> >  mm/memblock.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/memblock.c b/mm/memblock.c
> > index 913b2520a9a0..e48dea7144bb 100644
> > --- a/mm/memblock.c
> > +++ b/mm/memblock.c
> > @@ -655,7 +655,11 @@ static int __init_memblock
> memblock_add_range(struct memblock_type *type,
> >                       }
> >               }
> >               /* area below @rend is dealt with, forget about it */
> > -             base = min(rend, end);
> > +             if (end < rend) {
> > +                     base = end;
> > +                     break;
> > +             } else
> > +                     base = rend;
>
> min() is perfectly clear and there no change in number of iterations of the
> loop.
>
> >       }
> >
> >       /* insert the remaining portion */
> > --
> > 2.25.1
> >
>
> --
> Sincerely yours,
> Mike.
>
黄亮亮 Nov. 3, 2023, 5:31 a.m. UTC | #4
Hi,this patch can less loop once in this situation:
base more than rbase and end less than rend.

Mike Rapoport <rppt@kernel.org> 于2023年11月2日周四 16:54写道:

> Hi,
>
> > Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop
> and enhance readability.
>
> I disagree.
>
> On Thu, Nov 02, 2023 at 10:37:10AM +0800, huanglllzu@gmail.com wrote:
> > From: Liangliang Huang <huangll@lemote.com>
> >
> > Signed-off-by: Liangliang Huang <huangll@lemote.com>
> > ---
> >  mm/memblock.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/memblock.c b/mm/memblock.c
> > index 913b2520a9a0..e48dea7144bb 100644
> > --- a/mm/memblock.c
> > +++ b/mm/memblock.c
> > @@ -655,7 +655,11 @@ static int __init_memblock
> memblock_add_range(struct memblock_type *type,
> >                       }
> >               }
> >               /* area below @rend is dealt with, forget about it */
> > -             base = min(rend, end);
> > +             if (end < rend) {
> > +                     base = end;
> > +                     break;
> > +             } else
> > +                     base = rend;
>
> min() is perfectly clear and there no change in number of iterations of the
> loop.
>
> >       }
> >
> >       /* insert the remaining portion */
> > --
> > 2.25.1
> >
>
> --
> Sincerely yours,
> Mike.
>
Mike Rapoport Nov. 3, 2023, 7:34 a.m. UTC | #5
On Fri, Nov 03, 2023 at 01:30:21PM +0800, 黄亮亮 wrote:
> Hi,this patch can less loop once in this situation:
> base more than rbase and end less than rend.
>                 base           end
>     rbase-----|--------------|-------rend
>       |            |                 |           |
> -------------------------------------------------------->

The loop won't be executed anyway because there's similar condition in the
beginning of the loop. 

Next time when you reply to the kernel mailing lists, please don't top post
and make sure your reply is text-only.

And there is no need to send 4 badly formatted replies.
 
> Mike Rapoport <rppt@kernel.org> 于2023年11月2日周四 16:54写道:
> 
>     Hi,
> 
>     > Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop
>     and enhance readability.
> 
>     I disagree.
> 
>     On Thu, Nov 02, 2023 at 10:37:10AM +0800, huanglllzu@gmail.com wrote:
>     > From: Liangliang Huang <huangll@lemote.com>
>     >
>     > Signed-off-by: Liangliang Huang <huangll@lemote.com>
>     > ---
>     >  mm/memblock.c | 6 +++++-
>     >  1 file changed, 5 insertions(+), 1 deletion(-)
>     >
>     > diff --git a/mm/memblock.c b/mm/memblock.c
>     > index 913b2520a9a0..e48dea7144bb 100644
>     > --- a/mm/memblock.c
>     > +++ b/mm/memblock.c
>     > @@ -655,7 +655,11 @@ static int __init_memblock memblock_add_range(struct
>     memblock_type *type,
>     >                       }
>     >               }
>     >               /* area below @rend is dealt with, forget about it */
>     > -             base = min(rend, end);
>     > +             if (end < rend) {
>     > +                     base = end;
>     > +                     break;
>     > +             } else
>     > +                     base = rend;
> 
>     min() is perfectly clear and there no change in number of iterations of the
>     loop.
> 
>     >       }
>     > 
>     >       /* insert the remaining portion */
>     > --
>     > 2.25.1
>     >
> 
>     --
>     Sincerely yours,
>     Mike.
>
黄亮亮 Nov. 3, 2023, 8:21 a.m. UTC | #6
Mike Rapoport <rppt@kernel.org> 于2023年11月3日周五 15:35写道:

> On Fri, Nov 03, 2023 at 01:30:21PM +0800, 黄亮亮 wrote:
> > Hi,this patch can less loop once in this situation:
> > base more than rbase and end less than rend.
> >                 base           end
> >     rbase-----|--------------|-------rend
> >       |            |                 |           |
> > -------------------------------------------------------->
>
> The loop won't be executed anyway because there's similar condition in the
> beginning of the loop.
>
> Next time when you reply to the kernel mailing lists, please don't top post
> and make sure your reply is text-only.
>
> And there is no need to send 4 badly formatted replies.
>
> > Mike Rapoport <rppt@kernel.org> 于2023年11月2日周四 16:54写道:
> >
> >     Hi,
> >
> >     > Subject: [PATCH] mm/memblock.c: using judgment statement can
> reduce loop
> >     and enhance readability.
> >
> >     I disagree.
> >
> >     On Thu, Nov 02, 2023 at 10:37:10AM +0800, huanglllzu@gmail.com
> wrote:
> >     > From: Liangliang Huang <huangll@lemote.com>
> >     >
> >     > Signed-off-by: Liangliang Huang <huangll@lemote.com>
> >     > ---
> >     >  mm/memblock.c | 6 +++++-
> >     >  1 file changed, 5 insertions(+), 1 deletion(-)
> >     >
> >     > diff --git a/mm/memblock.c b/mm/memblock.c
> >     > index 913b2520a9a0..e48dea7144bb 100644
> >     > --- a/mm/memblock.c
> >     > +++ b/mm/memblock.c
> >     > @@ -655,7 +655,11 @@ static int __init_memblock
> memblock_add_range(struct
> >     memblock_type *type,
> >     >                       }
> >     >               }
> >     >               /* area below @rend is dealt with, forget about it */
> >     > -             base = min(rend, end);
> >     > +             if (end < rend) {
> >     > +                     base = end;
> >     > +                     break;
> >     > +             } else
> >     > +                     base = rend;
> >
> >     min() is perfectly clear and there no change in number of iterations
> of the
> >     loop.
> >
> >     >       }
> >     >
> >     >       /* insert the remaining portion */
> >     > --
> >     > 2.25.1
> >     >
> >
> >     --
> >     Sincerely yours,
> >     Mike.
> >
>
> --
> Sincerely yours,
> Mike.
>

I get your meanings, thanks.
diff mbox series

Patch

diff --git a/mm/memblock.c b/mm/memblock.c
index 913b2520a9a0..e48dea7144bb 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -655,7 +655,11 @@  static int __init_memblock memblock_add_range(struct memblock_type *type,
 			}
 		}
 		/* area below @rend is dealt with, forget about it */
-		base = min(rend, end);
+		if (end < rend) {
+			base = end;
+			break;
+		} else
+			base = rend;
 	}
 
 	/* insert the remaining portion */