util_macros.h: add find_closest() macro
authorBartosz Golaszewski <[email protected]>
Thu, 16 Apr 2015 19:43:28 +0000 (12:43 -0700)
committerLinus Torvalds <[email protected]>
Fri, 17 Apr 2015 13:03:54 +0000 (09:03 -0400)
commit95d119528b0b8440a63bc13904e9873fc3a70503
tree8e9ee1f06bb4843879ffc4ac542e2454f72b6430
parenta7a2c02a40151811609ad8cd3bf5c4fc516fece5
util_macros.h: add find_closest() macro

This series unduplicates the code used to find the member in an array
closest to 'x'.

The first patch adds a macro implementing the algorithm in two flavors -
for arrays sorted in ascending and descending order.  The second updates
Documentation/CodingStyle on the naming convention for local variables in
macros resembling functions.  Other three patches replace duplicated code
with calls to one of these macros in some hwmon drivers.

This patch (of 5):

Searching for the member of an array closest to 'x' is duplicated in
several places.

Add a new include - util_macros.h - and two macros that implement this
algorithm for arrays sorted both in ascending and descending order.

Uses linear search.

Signed-off-by: Bartosz Golaszewski <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Steven Rostedt <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/util_macros.h [new file with mode: 0644]