Re: [PATCH v2 1/3] tools/mm/page_owner_sort: fix --sort option being silently ignored
From: David Hildenbrand (Arm)
Date: Mon Aug 03 2026 - 04:18:02 EST
On 8/3/26 08:20, Ye Liu wrote:
> From: Ye Liu <liuye@xxxxxxxxxx>
>
> When --sort is used without any short option (-a, -m, -p, etc.),
> compare_flag remains COMP_NO_FLAG. The switch (compare_flag) then
> falls through to the COMP_NUM case and calls set_single_cmp(), which
> unconditionally overwrites the sort conditions that parse_sort_args()
> already configured. This makes --sort silently ineffective unless a
> short option is also supplied.
>
> Split COMP_NO_FLAG out of the COMP_NUM fallthrough so that --sort is
> respected when no short option is present.
>
> Reproduction:
> # Before fix: ascending order (ignored --sort=-pid)
> ./page_owner_sort --sort=-pid input.txt output.txt
> # After fix: descending order as expected
>
> Signed-off-by: Ye Liu <liuye@xxxxxxxxxx>
> ---
> tools/mm/page_owner_sort.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c
> index 35d3d254941c..3c86c8d0618c 100644
> --- a/tools/mm/page_owner_sort.c
> +++ b/tools/mm/page_owner_sort.c
> @@ -821,6 +821,10 @@ int main(int argc, char **argv)
> set_single_cmp(compare_stacktrace, SORT_ASC);
> break;
> case COMP_NO_FLAG:
> + if (sc.size > 0)
> + break;
> + set_single_cmp(compare_num, SORT_DESC);
> + break;
Why not a fallthrough; after the check?
--
Cheers,
David