Skip to content

Commit e1c4350

Browse files
visitorckwtehcaster
authored andcommitted
mm/slub: Fix cmp_loc_by_count() to return 0 when counts are equal
The comparison function cmp_loc_by_count() used for sorting stack trace locations in debugfs currently returns -1 if a->count > b->count and 1 otherwise. This breaks the antisymmetry property required by sort(), because when two counts are equal, both cmp(a, b) and cmp(b, a) return 1. This can lead to undefined or incorrect ordering results. Fix it by updating the comparison logic to explicitly handle the case when counts are equal, and use cmp_int() to ensure the comparison function adheres to the required mathematical properties of antisymmetry. Fixes: 553c036 ("mm/slub: sort debugfs output by frequency of stack traces") Reviewed-by: Joshua Hahn <[email protected]> Signed-off-by: Kuan-Wei Chiu <[email protected]> Reviewed-by: Harry Yoo <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 850470a commit e1c4350

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

mm/slub.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7731,10 +7731,7 @@ static int cmp_loc_by_count(const void *a, const void *b, const void *data)
77317731
struct location *loc1 = (struct location *)a;
77327732
struct location *loc2 = (struct location *)b;
77337733

7734-
if (loc1->count > loc2->count)
7735-
return -1;
7736-
else
7737-
return 1;
7734+
return cmp_int(loc2->count, loc1->count);
77387735
}
77397736

77407737
static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos)

0 commit comments

Comments
 (0)