]> git.baikalelectronics.ru Git - kernel.git/commit
util_macros.h: add find_closest() macro
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Thu, 16 Apr 2015 19:43:28 +0000 (12:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Apr 2015 13:03:54 +0000 (09:03 -0400)
commit7be184ade26d3177253bef87bd592d07249e46c0
tree8e9ee1f06bb4843879ffc4ac542e2454f72b6430
parenta2fe14aaa3c039331fdbe17e55402ede74b2db66
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 <bgolaszewski@baylibre.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/util_macros.h [new file with mode: 0644]