tools/mm/page-types: Fix misc bugs
cover tools/mm/page-types: Fix misc bugs
From: Ye Liu <[email protected]>
This series fixes three issues in tools/mm/page-types.c:
1. Fix two typos in madvise() error messages ("madvice" -> "madvise")
2. Fix operator precedence bug in the sigbus handler where the ternary operator binds looser than addition, producing incorrect offset calculation when sigbus_addr is non-NULL
3. Fix --kpageflags option declaration in getopt_long: has_arg should be 1 (required_argument) since the option requires a file path
Ye Liu (3):
tools/mm/page-types: Fix typo in madvise() error message tools/mm/page-types: Fix ternary operator precedence in sigbus handler tools/mm/page-types: Fix kpageflags option argument in getopt_long
tools/mm/page-types.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 tools/mm/page-types: Fix typo in madvise() error message
From: Ye Liu <[email protected]>
Two error messages incorrectly spelled the madvise() function name as "madvice". Fix the typo in both occurrences.
--- tools/mm/page-types.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/mm/page-types.c +2 -2
@@ -997,7 +997,7 @@ static void walk_file_range(const char *name, int fd,/* turn off readahead */ if (madvise (ptr, len,MADV_RANDOM )) -fatal ("madvice failed: %s" , name); +fatal ("madvise failed: %s" , name);if (sigsetjmp (sigbus_jmp,1 )) { end = off + sigbus_addr ? sigbus_addr - ptr :0 ;
@@ -1015,7 +1015,7 @@ static void walk_file_range(const char *name, int fd,/* turn off harvesting reference bits */ if (madvise (ptr, len,MADV_SEQUENTIAL )) -fatal ("madvice failed: %s" , name); +fatal ("madvise failed: %s" , name);if (pagemap_read (buf, (unsigned long )ptr / page_size, nr_pages) != nr_pages)
Signature · 1 line
2.43.0
PATCH 2/3 tools/mm/page-types: Fix ternary operator precedence in sigbus handler
In reply to Ye LiuFrom: Ye Liu <[email protected]>
The ternary operator (?:) has lower precedence than addition (+), so the expression off + sigbus_addr ? sigbus_addr - ptr : 0 was parsed as (off + sigbus_addr) ? (sigbus_addr - ptr) : 0 rather than the intended off + (sigbus_addr ? sigbus_addr - ptr : 0). Add explicit parentheses to ensure the correct evaluation order.
--- tools/mm/page-types.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/mm/page-types.c +1 -1
@@ -1000,7 +1000,7 @@ static void walk_file_range(const char *name, int fd,fatal ("madvise failed: %s" , name);if (sigsetjmp (sigbus_jmp,1 )) { - end = off + sigbus_addr ? sigbus_addr - ptr :0 ; + end = off + (sigbus_addr ? sigbus_addr - ptr :0 );fprintf (stderr,"got sigbus at offset %lld: %s\n" , (long long )end, name); goto got_sigbus;
Signature · 1 line
2.43.0
PATCH 3/3 tools/mm/page-types: Fix kpageflags option argument in getopt_long
In reply to Ye LiuFrom: Ye Liu <[email protected]>
The --kpageflags option requires an argument to specify the kpageflags file path, but has_arg was set to 0 (no_argument) in the long options table. Change it to 1 (required_argument) so getopt_long correctly parses the argument.
--- tools/mm/page-types.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/mm/page-types.c +1 -1
@@ -1261,7 +1261,7 @@ static const struct option opts[] = { { "no-summary", 0, NULL, 'N' }, { "hwpoison" , 0, NULL, 'X' }, { "unpoison" , 0, NULL, 'x' }, - { "kpageflags", 0, NULL, 'F' }, + { "kpageflags", 1, NULL, 'F' }, { "help" , 0, NULL, 'h' }, { NULL , 0, NULL, 0 } };
Signature · 1 line
2.43.0
Re: [PATCH 1/3] tools/mm/page-types: Fix typo in madvise() error message
In reply to Ye LiuQuoted 7 lines · Ye Liu
From: Ye Liu <[email protected]>
Two error messages incorrectly spelled the
madvise()function name as "madvice". Fix the typo in both occurrences.Signed-off-by Ye Liu <[email protected]>---
Signature · 3 lines
Cheers, David
Re: [PATCH 2/3] tools/mm/page-types: Fix ternary operator precedence in sigbus handler
In reply to Ye LiuQuoted 18 lines · Ye Liu
From: Ye Liu <[email protected]>
The ternary operator (?:) has lower precedence than addition (+), so the expression
off + sigbus_addr ? sigbus_addr - ptr : 0was parsed as(off + sigbus_addr) ? (sigbus_addr - ptr) : 0rather than the intendedoff + (sigbus_addr ? sigbus_addr - ptr : 0). Add explicit parentheses to ensure the correct evaluation order.Signed-off-by Ye Liu <[email protected]>--- tools/mm/page-types.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/mm/page-types.c +0
-0
tools/mm/page-types.c static void walk_file_range(const char *name, int fd, · line 1006
Quoted 8 lines
tools/mm/page-types.c +1
-1@@ -1000,7 +1000,7 @@ static void walk_file_range(const char *name, int fd,fatal ("madvise failed: %s" , name);if (sigsetjmp (sigbus_jmp,1 )) { - end = off + sigbus_addr ? sigbus_addr - ptr :0 ; + end = off + (sigbus_addr ? sigbus_addr - ptr :0 );fprintf (stderr,"got sigbus at offset %lld: %s\n" , (long long )end, name); goto got_sigbus;
"sigbus_addr - ptr" will give us the offset into the mmap(). Adding that to off will give us the offset into the file.
No idea what happens if we don't have sigbus_addr ...
Anyhow, your change looks good, I just have no idea whether updating "end" here is the right thing to do.
Signature · 3 lines
Cheers, David
Re: [PATCH 3/3] tools/mm/page-types: Fix kpageflags option argument in getopt_long
In reply to Ye LiuQuoted 17 lines · Ye Liu
From: Ye Liu <[email protected]>
The --kpageflags option requires an argument to specify the kpageflags file path, but
has_argwas set to 0 (no_argument) in the long options table. Change it to 1 (required_argument) sogetopt_longcorrectly parses the argument.Signed-off-by Ye Liu <[email protected]>--- tools/mm/page-types.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/mm/page-types.c +0
-0
tools/mm/page-types.c static const struct option opts[] = { · line 1267
Quoted 8 lines
tools/mm/page-types.c +1
-1@@ -1261,7 +1261,7 @@ static const struct option opts[] = { { "no-summary", 0, NULL, 'N' }, { "hwpoison" , 0, NULL, 'X' }, { "unpoison" , 0, NULL, 'x' }, - { "kpageflags", 0, NULL, 'F' }, + { "kpageflags", 1, NULL, 'F' }, { "help" , 0, NULL, 'h' }, { NULL , 0, NULL, 0 } };
Signature · 3 lines
Cheers, David
Re: [PATCH 1/3] tools/mm/page-types: Fix typo in madvise() error message
In reply to Ye LiuQuoted 6 lines · On Wed, 13 May 2026 10:21:16 +0800 Ye Liu <[email protected]> wrote:
From: Ye Liu <[email protected]>
Two error messages incorrectly spelled the
madvise()function name as "madvice". Fix the typo in both occurrences.Signed-off-by Ye Liu <[email protected]>
Thanks,
SJ
[...]
Re: [PATCH 2/3] tools/mm/page-types: Fix ternary operator precedence in sigbus handler
In reply to Ye LiuQuoted 9 lines · On Wed, 13 May 2026 10:21:17 +0800 Ye Liu <[email protected]> wrote:
From: Ye Liu <[email protected]>
The ternary operator (?:) has lower precedence than addition (+), so the expression
off + sigbus_addr ? sigbus_addr - ptr : 0was parsed as(off + sigbus_addr) ? (sigbus_addr - ptr) : 0rather than the intendedoff + (sigbus_addr ? sigbus_addr - ptr : 0). Add explicit parentheses to ensure the correct evaluation order.Signed-off-by Ye Liu <[email protected]>
Thanks,
SJ
[...]
Re: [PATCH 3/3] tools/mm/page-types: Fix kpageflags option argument in getopt_long
In reply to Ye LiuQuoted 8 lines · On Wed, 13 May 2026 10:21:18 +0800 Ye Liu <[email protected]> wrote:
From: Ye Liu <[email protected]>
The --kpageflags option requires an argument to specify the kpageflags file path, but
has_argwas set to 0 (no_argument) in the long options table. Change it to 1 (required_argument) sogetopt_longcorrectly parses the argument.Signed-off-by Ye Liu <[email protected]>
Thanks,
SJ
[...]