git: 5f99ae56c919 - main - evdev: Use bit_foreach helper macro
Vladimir Kondratyev
wulf at FreeBSD.org
Mon Aug 16 21:31:22 UTC 2021
The branch main has been updated by wulf:
URL: https://cgit.FreeBSD.org/src/commit/?id=5f99ae56c9196753ae162ad464c2969ad1a131b6
commit 5f99ae56c9196753ae162ad464c2969ad1a131b6
Author: Vladimir Kondratyev <wulf at FreeBSD.org>
AuthorDate: 2021-08-16 21:28:37 +0000
Commit: Vladimir Kondratyev <wulf at FreeBSD.org>
CommitDate: 2021-08-16 21:29:47 +0000
evdev: Use bit_foreach helper macro
for traversing all bits set in the bitstring(9).
While here move bit_change() definition to common header.
MFC after: 1 week
---
sys/dev/evdev/evdev.c | 25 ++++++-------------------
sys/dev/evdev/evdev_private.h | 10 ++++++++++
2 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/sys/dev/evdev/evdev.c b/sys/dev/evdev/evdev.c
index bc28ae0734f9..597342a364af 100644
--- a/sys/dev/evdev/evdev.c
+++ b/sys/dev/evdev/evdev.c
@@ -93,15 +93,6 @@ static void evdev_start_repeat(struct evdev_dev *, uint16_t);
static void evdev_stop_repeat(struct evdev_dev *);
static int evdev_check_event(struct evdev_dev *, uint16_t, uint16_t, int32_t);
-static inline void
-bit_change(bitstr_t *bitstr, int bit, int value)
-{
- if (value)
- bit_set(bitstr, bit);
- else
- bit_clear(bitstr, bit);
-}
-
struct evdev_dev *
evdev_alloc(void)
{
@@ -908,20 +899,16 @@ evdev_restore_after_kdb(struct evdev_dev *evdev)
EVDEV_LOCK_ASSERT(evdev);
/* Report postponed leds */
- for (code = 0; code < LED_CNT; code++)
- if (bit_test(evdev->ev_kdb_led_states, code))
- evdev_send_event(evdev, EV_LED, code,
- !bit_test(evdev->ev_led_states, code));
+ bit_foreach(evdev->ev_kdb_led_states, LED_CNT, code)
+ evdev_send_event(evdev, EV_LED, code,
+ !bit_test(evdev->ev_led_states, code));
bit_nclear(evdev->ev_kdb_led_states, 0, LED_MAX);
/* Release stuck keys (CTRL + ALT + ESC) */
evdev_stop_repeat(evdev);
- for (code = 0; code < KEY_CNT; code++) {
- if (bit_test(evdev->ev_key_states, code)) {
- evdev_send_event(evdev, EV_KEY, code, KEY_EVENT_UP);
- evdev_send_event(evdev, EV_SYN, SYN_REPORT, 1);
- }
- }
+ bit_foreach(evdev->ev_key_states, KEY_CNT, code)
+ evdev_send_event(evdev, EV_KEY, code, KEY_EVENT_UP);
+ evdev_send_event(evdev, EV_SYN, SYN_REPORT, 1);
}
int
diff --git a/sys/dev/evdev/evdev_private.h b/sys/dev/evdev/evdev_private.h
index 19636823b804..463f93847295 100644
--- a/sys/dev/evdev/evdev_private.h
+++ b/sys/dev/evdev/evdev_private.h
@@ -247,6 +247,16 @@ struct evdev_client
(((client)->ec_buffer_ready + (client)->ec_buffer_size - \
(client)->ec_buffer_head) % (client)->ec_buffer_size)
+/* bitstring(3) helper */
+static inline void
+bit_change(bitstr_t *bitstr, int bit, int value)
+{
+ if (value)
+ bit_set(bitstr, bit);
+ else
+ bit_clear(bitstr, bit);
+}
+
/* Input device interface: */
void evdev_send_event(struct evdev_dev *, uint16_t, uint16_t, int32_t);
int evdev_inject_event(struct evdev_dev *, uint16_t, uint16_t, int32_t);
More information about the dev-commits-src-main
mailing list