[PATCH] lib: test_hmm: Use min() to improve dmirror_exclusive()

Thorsten Blum posted 1 patch 1 month, 1 week ago
lib/test_hmm.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
[PATCH] lib: test_hmm: Use min() to improve dmirror_exclusive()
Posted by Thorsten Blum 1 month, 1 week ago
Use min() to simplify the dmirror_exclusive() function and improve its
readability.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 lib/test_hmm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index ee20e1f9bae9..056f2e411d7b 100644
--- a/lib/test_hmm.c
+++ b/lib/test_hmm.c
@@ -799,10 +799,7 @@ static int dmirror_exclusive(struct dmirror *dmirror,
 		unsigned long mapped = 0;
 		int i;
 
-		if (end < addr + (ARRAY_SIZE(pages) << PAGE_SHIFT))
-			next = end;
-		else
-			next = addr + (ARRAY_SIZE(pages) << PAGE_SHIFT);
+		next = min(end, addr + (ARRAY_SIZE(pages) << PAGE_SHIFT));
 
 		ret = make_device_exclusive_range(mm, addr, next, pages, NULL);
 		/*
-- 
2.39.2
Re: [PATCH] lib: test_hmm: Use min() to improve dmirror_exclusive()
Posted by David Hildenbrand 1 month, 1 week ago
On 26.07.24 15:12, Thorsten Blum wrote:
> Use min() to simplify the dmirror_exclusive() function and improve its
> readability.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>   lib/test_hmm.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/lib/test_hmm.c b/lib/test_hmm.c
> index ee20e1f9bae9..056f2e411d7b 100644
> --- a/lib/test_hmm.c
> +++ b/lib/test_hmm.c
> @@ -799,10 +799,7 @@ static int dmirror_exclusive(struct dmirror *dmirror,
>   		unsigned long mapped = 0;
>   		int i;
>   
> -		if (end < addr + (ARRAY_SIZE(pages) << PAGE_SHIFT))
> -			next = end;
> -		else
> -			next = addr + (ARRAY_SIZE(pages) << PAGE_SHIFT);
> +		next = min(end, addr + (ARRAY_SIZE(pages) << PAGE_SHIFT));

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb