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

lib/sort: Move swap, cmp and cmp_r function types for wider use

The function types for swap, cmp and cmp_r functions are already
being in use by modules.

Move them to types.h that everybody in kernel will be able to use
generic types instead of custom ones.

This adds more sense to the comment in bsearch() later on.

Link: http://lkml.kernel.org/r/20191007135656.37734-1-andriy.shevchenko@linux.intel.com

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Andy Shevchenko and committed by
Steven Rostedt (VMware)
52ae533b b43e78f6

+14 -14
+4 -4
include/linux/sort.h
··· 5 5 #include <linux/types.h> 6 6 7 7 void sort_r(void *base, size_t num, size_t size, 8 - int (*cmp)(const void *, const void *, const void *), 9 - void (*swap)(void *, void *, int), 8 + cmp_r_func_t cmp_func, 9 + swap_func_t swap_func, 10 10 const void *priv); 11 11 12 12 void sort(void *base, size_t num, size_t size, 13 - int (*cmp)(const void *, const void *), 14 - void (*swap)(void *, void *, int)); 13 + cmp_func_t cmp_func, 14 + swap_func_t swap_func); 15 15 16 16 #endif
+5
include/linux/types.h
··· 225 225 typedef void (*rcu_callback_t)(struct rcu_head *head); 226 226 typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func); 227 227 228 + typedef void (*swap_func_t)(void *a, void *b, int size); 229 + 230 + typedef int (*cmp_r_func_t)(const void *a, const void *b, const void *priv); 231 + typedef int (*cmp_func_t)(const void *a, const void *b); 232 + 228 233 #endif /* __ASSEMBLY__ */ 229 234 #endif /* _LINUX_TYPES_H */
+5 -10
lib/sort.c
··· 117 117 } while (n); 118 118 } 119 119 120 - typedef void (*swap_func_t)(void *a, void *b, int size); 121 - 122 120 /* 123 121 * The values are arbitrary as long as they can't be confused with 124 122 * a pointer, but small integers make for the smallest compare ··· 142 144 swap_func(a, b, (int)size); 143 145 } 144 146 145 - typedef int (*cmp_func_t)(const void *, const void *); 146 - typedef int (*cmp_r_func_t)(const void *, const void *, const void *); 147 147 #define _CMP_WRAPPER ((cmp_r_func_t)0L) 148 148 149 - static int do_cmp(const void *a, const void *b, 150 - cmp_r_func_t cmp, const void *priv) 149 + static int do_cmp(const void *a, const void *b, cmp_r_func_t cmp, const void *priv) 151 150 { 152 151 if (cmp == _CMP_WRAPPER) 153 152 return ((cmp_func_t)(priv))(a, b); ··· 197 202 * it less suitable for kernel use. 198 203 */ 199 204 void sort_r(void *base, size_t num, size_t size, 200 - int (*cmp_func)(const void *, const void *, const void *), 201 - void (*swap_func)(void *, void *, int size), 205 + cmp_r_func_t cmp_func, 206 + swap_func_t swap_func, 202 207 const void *priv) 203 208 { 204 209 /* pre-scale counters for performance */ ··· 264 269 EXPORT_SYMBOL(sort_r); 265 270 266 271 void sort(void *base, size_t num, size_t size, 267 - int (*cmp_func)(const void *, const void *), 268 - void (*swap_func)(void *, void *, int size)) 272 + cmp_func_t cmp_func, 273 + swap_func_t swap_func) 269 274 { 270 275 return sort_r(base, num, size, _CMP_WRAPPER, swap_func, cmp_func); 271 276 }