Skip to content

Commit e63fbd5

Browse files
visitorckwrostedt
authored andcommitted
tracing: Fix cmp_entries_dup() to respect sort() comparison rules
The cmp_entries_dup() function used as the comparator for sort() violated the symmetry and transitivity properties required by the sorting algorithm. Specifically, it returned 1 whenever memcmp() was non-zero, which broke the following expectations: * Symmetry: If x < y, then y > x. * Transitivity: If x < y and y < z, then x < z. These violations could lead to incorrect sorting and failure to correctly identify duplicate elements. Fix the issue by directly returning the result of memcmp(), which adheres to the required comparison properties. Cc: [email protected] Fixes: 08d43a5 ("tracing: Add lock-free tracing_map") Link: https://lore.kernel.org/[email protected] Signed-off-by: Kuan-Wei Chiu <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 40384c8 commit e63fbd5

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

kernel/trace/tracing_map.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,11 @@ int tracing_map_init(struct tracing_map *map)
845845
static int cmp_entries_dup(const void *A, const void *B)
846846
{
847847
const struct tracing_map_sort_entry *a, *b;
848-
int ret = 0;
849848

850849
a = *(const struct tracing_map_sort_entry **)A;
851850
b = *(const struct tracing_map_sort_entry **)B;
852851

853-
if (memcmp(a->key, b->key, a->elt->map->key_size))
854-
ret = 1;
855-
856-
return ret;
852+
return memcmp(a->key, b->key, a->elt->map->key_size);
857853
}
858854

859855
static int cmp_entries_sum(const void *A, const void *B)

0 commit comments

Comments
 (0)