diff options
author | Tom Rini <trini@konsulko.com> | 2023-03-31 10:04:23 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-03-31 10:04:23 -0400 |
commit | b8deed53fe6a55ef76b4f9038bb419a9c853a9fa (patch) | |
tree | 2f0cdb8f35d7c51611417bab680583a65bf21306 /include/linux/kernel.h | |
parent | f1617e99b933d2c3ecb381954148284d37bf922e (diff) | |
parent | f98b112f9e0516fc9333611d1228d0b634aa353e (diff) |
Merge branch '2023-03-30-assorted-general-upates' into next
- RTC cleanups / improvements, run_commandf() cleanups, fs bugfixes,
socrates config fix, PCI MPS support, GPIO improvements, other code
cleanups
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 3e71d61074b..5cd6c9dc821 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -284,4 +284,28 @@ offsetof(struct structure, member) == (offset), \ "`struct " #structure "` offset for `" #member "` is not " #offset) +#define __find_closest(x, a, as, op) \ +({ \ + typeof(as) __fc_i, __fc_as = (as) - 1; \ + typeof(x) __fc_x = (x); \ + typeof(*a) const *__fc_a = (a); \ + for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \ + if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] + \ + __fc_a[__fc_i + 1], 2)) \ + break; \ + } \ + (__fc_i); \ +}) + +/** + * find_closest - locate the closest element in a sorted array + * @x: The reference value. + * @a: The array in which to look for the closest element. Must be sorted + * in ascending order. + * @as: Size of 'a'. + * + * Returns the index of the element closest to 'x'. + */ +#define find_closest(x, a, as) __find_closest(x, a, as, <=) + #endif |