[RFC 2/8] HID: Add map_msc() to avoid boilerplate code

From: Tero Kristo
Date: Thu Nov 04 2021 - 09:37:28 EST


From: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>

Since we are going to have more MSC events too, add map_msc() that can
be used to fill in necessary fields and avoid boilerplate code.

Signed-off-by: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>
Signed-off-by: Tero Kristo <tero.kristo@xxxxxxxxxxxxxxx>
---
drivers/hid/hid-input.c | 6 ++----
include/linux/hid.h | 4 ++++
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 4b5ebeacd283..e1f7cef52afa 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -52,6 +52,7 @@ static const struct {
#define map_rel(c) hid_map_usage(hidinput, usage, &bit, &max, EV_REL, (c))
#define map_key(c) hid_map_usage(hidinput, usage, &bit, &max, EV_KEY, (c))
#define map_led(c) hid_map_usage(hidinput, usage, &bit, &max, EV_LED, (c))
+#define map_msc(c) hid_map_usage(hidinput, usage, &bit, &max, EV_MSC, (c))

#define map_abs_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \
&max, EV_ABS, (c))
@@ -871,10 +872,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
break;

case 0x5b: /* TransducerSerialNumber */
- usage->type = EV_MSC;
- usage->code = MSC_SERIAL;
- bit = input->mscbit;
- max = MSC_MAX;
+ map_msc(MSC_SERIAL);
break;

default: goto unknown;
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 9e067f937dbc..010c8bcbee90 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -1000,6 +1000,10 @@ static inline void hid_map_usage(struct hid_input *hidinput,
bmap = input->ledbit;
limit = LED_MAX;
break;
+ case EV_MSC:
+ bmap = input->mscbit;
+ limit = MSC_MAX;
+ break;
}

if (unlikely(c > limit || !bmap)) {
--
2.25.1