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

huanglllzu@gmail.com posted 1 patch 2 years, 1 month ago
mm/memblock.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] mm/memblock.c: using judgment statement can reduce loop and enhance readability.
Posted by huanglllzu@gmail.com 2 years, 1 month ago
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;
 	}
 
 	/* insert the remaining portion */
-- 
2.25.1
Re: [PATCH] mm/memblock.c: using judgment statement can reduce loop and enhance readability.
Posted by Mike Rapoport 2 years, 1 month ago
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.