Re: [PATCH 07/16] mm/migration: use helper macro min_t in do_pages_stat
From: Miaohe Lin
Date: Mon Mar 07 2022 - 06:51:12 EST
On 2022/3/7 9:14, Andrew Morton wrote:
> On Fri, 4 Mar 2022 17:34:00 +0800 Miaohe Lin <linmiaohe@xxxxxxxxxx> wrote:
>
>> We could use helper macro min_t to help set the chunk_nr to simplify
>> the code.
>>
>> ...
>>
>> --- a/mm/migrate.c
>> +++ b/mm/migrate.c
>> @@ -1858,9 +1858,7 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
>> while (nr_pages) {
>> unsigned long chunk_nr;
>>
>> - chunk_nr = nr_pages;
>> - if (chunk_nr > DO_PAGES_STAT_CHUNK_NR)
>> - chunk_nr = DO_PAGES_STAT_CHUNK_NR;
>> + chunk_nr = min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR);
>>
>> if (in_compat_syscall()) {
>> if (get_compat_pages_array(chunk_pages, pages,
>
> Getting the types correct is better than using min_t().
>
Looks good. Many thanks for your suggestion. Will do it in v2.
Thanks.
> --- a/mm/migrate.c~mm-migration-use-helper-macro-min_t-in-do_pages_stat-fix
> +++ a/mm/migrate.c
> @@ -1844,14 +1844,12 @@ static int do_pages_stat(struct mm_struc
> const void __user * __user *pages,
> int __user *status)
> {
> -#define DO_PAGES_STAT_CHUNK_NR 16
> +#define DO_PAGES_STAT_CHUNK_NR 16UL
> const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR];
> int chunk_status[DO_PAGES_STAT_CHUNK_NR];
>
> while (nr_pages) {
> - unsigned long chunk_nr;
> -
> - chunk_nr = min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR);
> + unsigned long chunk_nr = min(nr_pages, DO_PAGES_STAT_CHUNK_NR);
>
> if (in_compat_syscall()) {
> if (get_compat_pages_array(chunk_pages, pages,
> _
>
> .
>