linux/drivers/hid/hid-topre.c
Thomas Weißschuh fe73965d07 HID: change return type of report_fixup() to const
By allowing the drivers to return a "const *" they can constify their
static report arrays.
This makes it clear to driver authors that the HID core will not modify
those reports and they can be reused for multiple devices.
Furthermore security is slightly improved as those reports are protected
against accidental or malicious modifications.

[bentiss: fixup hid-cougar.c and hid-multitouch.c for latest version of
the master branch]

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://patch.msgid.link/20240803-hid-const-fixup-v2-6-f53d7a7b29d8@weissschuh.net
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
2024-08-27 16:29:55 +02:00

52 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* HID driver for Topre REALFORCE Keyboards
*
* Copyright (c) 2022 Harry Stern <harry@harrystern.net>
*
* Based on the hid-macally driver
*/
#include <linux/hid.h>
#include <linux/module.h>
#include "hid-ids.h"
MODULE_AUTHOR("Harry Stern <harry@harrystern.net>");
MODULE_DESCRIPTION("REALFORCE R2 Keyboard driver");
MODULE_LICENSE("GPL");
/*
* Fix the REALFORCE R2's non-boot interface's report descriptor to match the
* events it's actually sending. It claims to send array events but is instead
* sending variable events.
*/
static const __u8 *topre_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize >= 119 && rdesc[69] == 0x29 && rdesc[70] == 0xe7 &&
rdesc[71] == 0x81 && rdesc[72] == 0x00) {
hid_info(hdev,
"fixing up Topre REALFORCE keyboard report descriptor\n");
rdesc[72] = 0x02;
}
return rdesc;
}
static const struct hid_device_id topre_id_table[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_TOPRE,
USB_DEVICE_ID_TOPRE_REALFORCE_R2_108) },
{ HID_USB_DEVICE(USB_VENDOR_ID_TOPRE,
USB_DEVICE_ID_TOPRE_REALFORCE_R2_87) },
{ }
};
MODULE_DEVICE_TABLE(hid, topre_id_table);
static struct hid_driver topre_driver = {
.name = "topre",
.id_table = topre_id_table,
.report_fixup = topre_report_fixup,
};
module_hid_driver(topre_driver);