hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/lib/bsearch.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * A generic implementation of binary search for the Linux kernel
34 *
45 * Copyright (C) 2008-2009 Ksplice, Inc.
56 * Author: Tim Abbott <tabbott@ksplice.com>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License as
9
- * published by the Free Software Foundation; version 2.
107 */
118
129 #include <linux/export.h>
....@@ -31,27 +28,9 @@
3128 * the key and elements in the array are of the same type, you can use
3229 * the same comparison function for both sort() and bsearch().
3330 */
34
-void *bsearch(const void *key, const void *base, size_t num, size_t size,
35
- int (*cmp)(const void *key, const void *elt))
31
+void *bsearch(const void *key, const void *base, size_t num, size_t size, cmp_func_t cmp)
3632 {
37
- const char *pivot;
38
- int result;
39
-
40
- while (num > 0) {
41
- pivot = base + (num >> 1) * size;
42
- result = cmp(key, pivot);
43
-
44
- if (result == 0)
45
- return (void *)pivot;
46
-
47
- if (result > 0) {
48
- base = pivot + size;
49
- num--;
50
- }
51
- num >>= 1;
52
- }
53
-
54
- return NULL;
33
+ return __inline_bsearch(key, base, num, size, cmp);
5534 }
5635 EXPORT_SYMBOL(bsearch);
5736 NOKPROBE_SYMBOL(bsearch);