fe73965d07
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>
64 lines
1.5 KiB
C
64 lines
1.5 KiB
C
/*
|
|
* HID driver for Redragon keyboards
|
|
*
|
|
* Copyright (c) 2017 Robert Munteanu
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
*/
|
|
|
|
/*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
* any later version.
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/hid.h>
|
|
#include <linux/module.h>
|
|
|
|
#include "hid-ids.h"
|
|
|
|
|
|
/*
|
|
* The Redragon Asura keyboard sends an incorrect HID descriptor.
|
|
* At byte 100 it contains
|
|
*
|
|
* 0x81, 0x00
|
|
*
|
|
* which is Input (Data, Arr, Abs), but it should be
|
|
*
|
|
* 0x81, 0x02
|
|
*
|
|
* which is Input (Data, Var, Abs), which is consistent with the way
|
|
* key codes are generated.
|
|
*/
|
|
|
|
static const __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
|
|
unsigned int *rsize)
|
|
{
|
|
if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
|
|
dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n");
|
|
rdesc[101] = 0x02;
|
|
}
|
|
|
|
return rdesc;
|
|
}
|
|
|
|
static const struct hid_device_id redragon_devices[] = {
|
|
{HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
|
|
{}
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(hid, redragon_devices);
|
|
|
|
static struct hid_driver redragon_driver = {
|
|
.name = "redragon",
|
|
.id_table = redragon_devices,
|
|
.report_fixup = redragon_report_fixup
|
|
};
|
|
|
|
module_hid_driver(redragon_driver);
|
|
|
|
MODULE_DESCRIPTION("HID driver for Redragon keyboards");
|
|
MODULE_LICENSE("GPL");
|