| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * A generic implementation of binary search for the Linux kernel |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2008-2009 Ksplice, Inc. |
|---|
| 5 | 6 | * 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. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/export.h> |
|---|
| .. | .. |
|---|
| 31 | 28 | * the key and elements in the array are of the same type, you can use |
|---|
| 32 | 29 | * the same comparison function for both sort() and bsearch(). |
|---|
| 33 | 30 | */ |
|---|
| 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) |
|---|
| 36 | 32 | { |
|---|
| 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); |
|---|
| 55 | 34 | } |
|---|
| 56 | 35 | EXPORT_SYMBOL(bsearch); |
|---|
| 57 | 36 | NOKPROBE_SYMBOL(bsearch); |
|---|