From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Sean Young <sean@mess.org>,
linux-media@vger.kernel.org,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Rik van Riel <riel@surriel.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 08/19] media: rc: Use binary search for adding or updating a scancode
Date: Fri, 11 Sep 2026 10:10:52 +0200 [thread overview]
Message-ID: <28ee58c0-f33d-42ea-bb9e-ad32734a8df1@kernel.org> (raw)
In-Reply-To: <afefeadfb3f69f8a77294f0194db4ec7f428d0f0.1788882189.git.sean@mess.org>
On 08/09/2026 17:51, Sean Young wrote:
> We can have up to 1024 scancodes entries which are always sorted, so make
> this a little faster.
>
> Signed-off-by: Sean Young <sean@mess.org>
> ---
> drivers/media/rc/rc-main.c | 20 +++++++++++++-------
> 1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
> index 924b13fff753..795ac0fe4858 100644
> --- a/drivers/media/rc/rc-main.c
> +++ b/drivers/media/rc/rc-main.c
> @@ -391,7 +391,7 @@ static unsigned int ir_establish_scancode(struct rc_dev *dev,
> struct rc_map *rc_map,
> u64 scancode, bool resize)
> {
> - unsigned int i;
> + unsigned int i, lo, hi;
>
> lockdep_assert_held(&rc_map->lock);
>
> @@ -406,15 +406,21 @@ static unsigned int ir_establish_scancode(struct rc_dev *dev,
> if (dev->scancode_mask)
> scancode &= dev->scancode_mask;
>
> - /* First check if we already have a mapping for this ir command */
> - for (i = 0; i < rc_map->len; i++) {
> + /*
> + * Binary search for an existing mapping for this ir command.
> + */
> + lo = 0;
> + hi = rc_map->len;
> + while (lo < hi) {
> + i = lo + (hi - lo) / 2;
> if (rc_map->scan[i].scancode == scancode)
> return i;
> -
> - /* Keytable is sorted from lowest to highest scancode */
> - if (rc_map->scan[i].scancode >= scancode)
> - break;
> + if (rc_map->scan[i].scancode < scancode)
> + lo = i + 1;
> + else
> + hi = i;
> }
> + i = lo;
Can you use bsearch() for this? (lib/bsearch.c)
Regards,
Hans
>
> /* No previous mapping found, we might need to grow the table */
> if (rc_map->size == rc_map->len) {
next prev parent reply other threads:[~2026-09-11 8:10 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1788882189.git.sean@mess.org>
2026-09-08 15:51 ` [PATCH v4 01/19] media: rc: Ensure registered is cleared in error path Sean Young
2026-09-11 7:53 ` Hans Verkuil
2026-09-11 8:45 ` Sean Young
2026-09-08 15:51 ` [PATCH v4 02/19] media: rc: Ensure that rc_unregister_device() does not free input device Sean Young
2026-09-08 15:51 ` [PATCH v4 03/19] media: rc: Fix ABBA deadlock by making locks more fine grained Sean Young
2026-09-08 15:51 ` [PATCH v4 04/19] media: rc: Add missing locking for keymap Sean Young
2026-09-11 8:08 ` Hans Verkuil
2026-09-11 8:47 ` Sean Young
2026-09-08 15:51 ` [PATCH v4 05/19] media: rc: Fix race between bpf(BPG_PROG_ATTACH) and device unregister Sean Young
2026-09-08 15:51 ` [PATCH v4 06/19] media: rc: mce_kbd: Fix inconsistent locking of keylock Sean Young
2026-09-08 15:51 ` [PATCH v4 07/19] media: ene_ir: Ensure teardown is done in the correct order Sean Young
2026-09-08 15:51 ` [PATCH v4 08/19] media: rc: Use binary search for adding or updating a scancode Sean Young
2026-09-11 8:10 ` Hans Verkuil [this message]
2026-09-11 8:42 ` Sean Young
2026-09-08 15:51 ` [PATCH v4 09/19] media: rc: imon: Bind both interfaces via usb_driver_claim_interface() Sean Young
2026-09-08 15:51 ` [PATCH v4 10/19] media: ir_toy: Remove unused struct field Sean Young
2026-09-08 15:51 ` [PATCH v4 11/19] media: nuvoton-cir: " Sean Young
2026-09-08 15:52 ` [PATCH v4 12/19] media: ite-cir: Removed " Sean Young
2026-09-08 15:52 ` [PATCH v4 13/19] media: fintek-cir: Remove unused fields Sean Young
2026-09-08 15:52 ` [PATCH v4 14/19] media: mceusb: Remove unused field Sean Young
2026-09-08 15:52 ` [PATCH v4 15/19] media: serial_ir: Fix race condition where timer can be re-armed Sean Young
2026-09-08 15:52 ` [PATCH v4 16/19] media: rc: After rc_unregister_device() timers " Sean Young
2026-09-08 15:52 ` [PATCH v4 17/19] media: rc: Validate carrier range in LIRC_SET_REC_CARRIER ioctl Sean Young
2026-09-08 15:52 ` [PATCH v4 18/19] media: ir_toy: Validate the maximum tx carrier Sean Young
2026-09-08 15:52 ` [PATCH v4 19/19] media: meson-ir-tx: Validate carrier and duty_cycle Sean Young
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28ee58c0-f33d-42ea-bb9e-ad32734a8df1@kernel.org \
--to=hverkuil+cisco@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=riel@surriel.com \
--cc=sean@mess.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®