2023-06-09 09:46:35

by Lu Hongfei

[permalink] [raw]
Subject: [PATCH v2] mm/vmalloc: Replace the ternary conditional operator with min()

It would be better to replace the traditional ternary conditional
operator with min() in zero_iter

Signed-off-by: Lu Hongfei <[email protected]>
Reviewed-by: Lorenzo Stoakes <[email protected]>
---
mm/vmalloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 29077d61ff81..6125ed506895
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3571,7 +3571,7 @@ static size_t zero_iter(struct iov_iter *iter, size_t count)
while (remains > 0) {
size_t num, copied;

- num = remains < PAGE_SIZE ? remains : PAGE_SIZE;
+ num = min_t(size_t, remains, PAGE_SIZE);
copied = copy_page_to_iter_nofault(ZERO_PAGE(0), 0, num, iter);
remains -= copied;

--
2.39.0



2023-06-09 10:54:38

by Uladzislau Rezki (Sony)

[permalink] [raw]
Subject: Re: [PATCH v2] mm/vmalloc: Replace the ternary conditional operator with min()

> It would be better to replace the traditional ternary conditional
> operator with min() in zero_iter
>
> Signed-off-by: Lu Hongfei <[email protected]>
> Reviewed-by: Lorenzo Stoakes <[email protected]>
> ---
> mm/vmalloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 29077d61ff81..6125ed506895
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3571,7 +3571,7 @@ static size_t zero_iter(struct iov_iter *iter, size_t count)
> while (remains > 0) {
> size_t num, copied;
>
> - num = remains < PAGE_SIZE ? remains : PAGE_SIZE;
> + num = min_t(size_t, remains, PAGE_SIZE);
> copied = copy_page_to_iter_nofault(ZERO_PAGE(0), 0, num, iter);
> remains -= copied;
>
> --
> 2.39.0
>
I saw a complain from the robot. Indeed the min_t() variant is better:

Reviewed-by: Uladzislau Rezki (Sony) <[email protected]>

2023-06-12 09:49:29

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH v2] mm/vmalloc: Replace the ternary conditional operator with min()

On 09.06.23 11:26, Lu Hongfei wrote:
> It would be better to replace the traditional ternary conditional
> operator with min() in zero_iter
>
> Signed-off-by: Lu Hongfei <[email protected]>
> Reviewed-by: Lorenzo Stoakes <[email protected]>
> ---
> mm/vmalloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 29077d61ff81..6125ed506895
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3571,7 +3571,7 @@ static size_t zero_iter(struct iov_iter *iter, size_t count)
> while (remains > 0) {
> size_t num, copied;
>
> - num = remains < PAGE_SIZE ? remains : PAGE_SIZE;
> + num = min_t(size_t, remains, PAGE_SIZE);
> copied = copy_page_to_iter_nofault(ZERO_PAGE(0), 0, num, iter);
> remains -= copied;
>

Reviewed-by: David Hildenbrand <[email protected]>

--
Cheers,

David / dhildenb