Re: [PATCH 2/3] tools/mm/page-types: Fix ternary operator precedence in sigbus handler
From: David Hildenbrand (Arm)
Date: Wed May 13 2026 - 06:25:15 EST
On 5/13/26 04:21, Ye Liu wrote:
> From: Ye Liu <liuye@xxxxxxxxxx>
>
> 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.
>
> Signed-off-by: Ye Liu <liuye@xxxxxxxxxx>
> ---
> tools/mm/page-types.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/mm/page-types.c b/tools/mm/page-types.c
> index 6594245217a8..66f429f2b698 100644
> --- a/tools/mm/page-types.c
> +++ b/tools/mm/page-types.c
> @@ -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.
--
Cheers,
David