[media] media: rc: Use bsearch library function
Replace self coded binary search, by existing library version. Signed-off-by: Thomas Meyer <thomas@m3y3r.de> Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
This commit is contained in:
parent
eed008e605
commit
8ca01d4f95
|
@ -15,6 +15,7 @@
|
||||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||||
|
|
||||||
#include <media/rc-core.h>
|
#include <media/rc-core.h>
|
||||||
|
#include <linux/bsearch.h>
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
@ -460,6 +461,18 @@ static int ir_setkeytable(struct rc_dev *dev,
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int rc_map_cmp(const void *key, const void *elt)
|
||||||
|
{
|
||||||
|
const unsigned int *scancode = key;
|
||||||
|
const struct rc_map_table *e = elt;
|
||||||
|
|
||||||
|
if (*scancode < e->scancode)
|
||||||
|
return -1;
|
||||||
|
else if (*scancode > e->scancode)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ir_lookup_by_scancode() - locate mapping by scancode
|
* ir_lookup_by_scancode() - locate mapping by scancode
|
||||||
* @rc_map: the struct rc_map to search
|
* @rc_map: the struct rc_map to search
|
||||||
|
@ -472,21 +485,14 @@ static int ir_setkeytable(struct rc_dev *dev,
|
||||||
static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map,
|
static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map,
|
||||||
unsigned int scancode)
|
unsigned int scancode)
|
||||||
{
|
{
|
||||||
int start = 0;
|
struct rc_map_table *res;
|
||||||
int end = rc_map->len - 1;
|
|
||||||
int mid;
|
|
||||||
|
|
||||||
while (start <= end) {
|
res = bsearch(&scancode, rc_map->scan, rc_map->len,
|
||||||
mid = (start + end) / 2;
|
sizeof(struct rc_map_table), rc_map_cmp);
|
||||||
if (rc_map->scan[mid].scancode < scancode)
|
if (!res)
|
||||||
start = mid + 1;
|
return -1U;
|
||||||
else if (rc_map->scan[mid].scancode > scancode)
|
else
|
||||||
end = mid - 1;
|
return res - rc_map->scan;
|
||||||
else
|
|
||||||
return mid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1U;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue