lkml.org 
[lkml]   [2022]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 07/16] mm/migration: use helper macro min_t in do_pages_stat
On Fri, 4 Mar 2022 17:34:00 +0800 Miaohe Lin <linmiaohe@huawei.com> 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().

--- 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,
_
\
 
 \ /
  Last update: 2022-03-07 02:15    [W:0.414 / U:3.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site