Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sort.h: hoist cmp_int() into generic header file

Deduplicate the same functionality implemented in several places by
moving the cmp_int() helper macro into linux/sort.h.

The macro performs a three-way comparison of the arguments mostly useful
in different sorting strategies and algorithms.

Link: https://lkml.kernel.org/r/20250427201451.900730-1-pchelkin@ispras.ru
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Suggested-by: Darrick J. Wong <djwong@kernel.org>
Acked-by: Kent Overstreet <kent.overstreet@linux.dev>
Acked-by: Coly Li <colyli@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Carlos Maiolino <cem@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Coly Li <colyli@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Fedor Pchelkin and committed by
Andrew Morton
f3def827 1785c67e

+13 -8
+1 -2
drivers/md/bcache/btree.c
··· 36 36 #include <linux/sched/clock.h> 37 37 #include <linux/rculist.h> 38 38 #include <linux/delay.h> 39 + #include <linux/sort.h> 39 40 #include <trace/events/bcache.h> 40 41 41 42 /* ··· 559 558 list_move(&b->list, &b->c->btree_cache_freed); 560 559 } 561 560 } 562 - 563 - #define cmp_int(l, r) ((l > r) - (l < r)) 564 561 565 562 #ifdef CONFIG_PROVE_LOCKING 566 563 static int btree_lock_cmp_fn(const struct lockdep_map *_a,
+1 -2
fs/bcachefs/util.h
··· 16 16 #include <linux/preempt.h> 17 17 #include <linux/ratelimit.h> 18 18 #include <linux/slab.h> 19 + #include <linux/sort.h> 19 20 #include <linux/vmalloc.h> 20 21 #include <linux/workqueue.h> 21 22 ··· 669 668 } 670 669 671 670 u64 *bch2_acc_percpu_u64s(u64 __percpu *, unsigned); 672 - 673 - #define cmp_int(l, r) ((l > r) - (l < r)) 674 671 675 672 static inline int u8_cmp(u8 l, u8 r) 676 673 {
+1 -2
fs/pipe.c
··· 26 26 #include <linux/memcontrol.h> 27 27 #include <linux/watch_queue.h> 28 28 #include <linux/sysctl.h> 29 + #include <linux/sort.h> 29 30 30 31 #include <linux/uaccess.h> 31 32 #include <asm/ioctls.h> ··· 76 75 * pipe_read & write cleanup 77 76 * -- Manfred Spraul <manfred@colorfullife.com> 2002-05-09 78 77 */ 79 - 80 - #define cmp_int(l, r) ((l > r) - (l < r)) 81 78 82 79 #ifdef CONFIG_PROVE_LOCKING 83 80 static int pipe_lock_cmp_fn(const struct lockdep_map *a,
-2
fs/xfs/xfs_zone_gc.c
··· 290 290 return 0; 291 291 } 292 292 293 - #define cmp_int(l, r) ((l > r) - (l < r)) 294 - 295 293 static int 296 294 xfs_zone_gc_rmap_rec_cmp( 297 295 const void *a,
+10
include/linux/sort.h
··· 4 4 5 5 #include <linux/types.h> 6 6 7 + /** 8 + * cmp_int - perform a three-way comparison of the arguments 9 + * @l: the left argument 10 + * @r: the right argument 11 + * 12 + * Return: 1 if the left argument is greater than the right one; 0 if the 13 + * arguments are equal; -1 if the left argument is less than the right one. 14 + */ 15 + #define cmp_int(l, r) (((l) > (r)) - ((l) < (r))) 16 + 7 17 void sort_r(void *base, size_t num, size_t size, 8 18 cmp_r_func_t cmp_func, 9 19 swap_r_func_t swap_func,