Skip to content

Commit fe73965

Browse files
t-8chBenjamin Tissoires
authored andcommitted
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 3593630 commit fe73965

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+68
-68
lines changed

drivers/hid/hid-apple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ static void apple_battery_timer_tick(struct timer_list *t)
620620
* MacBook JIS keyboard has wrong logical maximum
621621
* Magic Keyboard JIS has wrong logical maximum
622622
*/
623-
static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
623+
static const __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
624624
unsigned int *rsize)
625625
{
626626
struct apple_sc *asc = hid_get_drvdata(hdev);

drivers/hid/hid-asus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ static const __u8 asus_g752_fixed_rdesc[] = {
11191119
0x2A, 0xFF, 0x00, /* Usage Maximum (0xFF) */
11201120
};
11211121

1122-
static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
1122+
static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
11231123
unsigned int *rsize)
11241124
{
11251125
struct asus_drvdata *drvdata = hid_get_drvdata(hdev);

drivers/hid/hid-aureal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "hid-ids.h"
2020

21-
static __u8 *aureal_report_fixup(struct hid_device *hdev, __u8 *rdesc,
21+
static const __u8 *aureal_report_fixup(struct hid_device *hdev, __u8 *rdesc,
2222
unsigned int *rsize)
2323
{
2424
if (*rsize >= 54 && rdesc[52] == 0x25 && rdesc[53] == 0x01) {

drivers/hid/hid-bigbenff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static int bigben_probe(struct hid_device *hid,
464464
return error;
465465
}
466466

467-
static __u8 *bigben_report_fixup(struct hid_device *hid, __u8 *rdesc,
467+
static const __u8 *bigben_report_fixup(struct hid_device *hid, __u8 *rdesc,
468468
unsigned int *rsize)
469469
{
470470
if (*rsize == PID0902_RDESC_ORIG_SIZE) {

drivers/hid/hid-cherry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Cherry Cymotion keyboard have an invalid HID report descriptor,
2323
* that needs fixing before we can parse it.
2424
*/
25-
static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
25+
static const __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
2626
unsigned int *rsize)
2727
{
2828
if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {

drivers/hid/hid-chicony.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
8888
return 1;
8989
}
9090

91-
static __u8 *ch_switch12_report_fixup(struct hid_device *hdev, __u8 *rdesc,
92-
unsigned int *rsize)
91+
static const __u8 *ch_switch12_report_fixup(struct hid_device *hdev,
92+
__u8 *rdesc, unsigned int *rsize)
9393
{
9494
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
9595

drivers/hid/hid-cmedia.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static struct hid_driver cmhid_driver = {
199199
.input_mapping = cmhid_input_mapping,
200200
};
201201

202-
static __u8 *cmhid_hs100b_report_fixup(struct hid_device *hid, __u8 *rdesc,
202+
static const __u8 *cmhid_hs100b_report_fixup(struct hid_device *hid, __u8 *rdesc,
203203
unsigned int *rsize)
204204
{
205205
if (*rsize == HS100B_RDESC_ORIG_SIZE) {

drivers/hid/hid-corsair.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ static int corsair_input_mapping(struct hid_device *dev,
690690
* - USB ID 1b1c:1b3e, sold as Scimitar RGB Pro Gaming mouse
691691
*/
692692

693-
static __u8 *corsair_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
694-
unsigned int *rsize)
693+
static const __u8 *corsair_mouse_report_fixup(struct hid_device *hdev,
694+
__u8 *rdesc, unsigned int *rsize)
695695
{
696696
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
697697

drivers/hid/hid-cougar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ static void cougar_fix_g6_mapping(void)
103103
/*
104104
* Constant-friendly rdesc fixup for mouse interface
105105
*/
106-
static __u8 *cougar_report_fixup(struct hid_device *hdev, __u8 *rdesc,
107-
unsigned int *rsize)
106+
static const __u8 *cougar_report_fixup(struct hid_device *hdev, __u8 *rdesc,
107+
unsigned int *rsize)
108108
{
109109
if (*rsize >= 117 && rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
110110
(rdesc[115] | rdesc[116] << 8) >= HID_MAX_USAGES) {

drivers/hid/hid-cypress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static __u8 *va_logical_boundary_fixup(struct hid_device *hdev, __u8 *rdesc,
6767
return rdesc;
6868
}
6969

70-
static __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
70+
static const __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
7171
unsigned int *rsize)
7272
{
7373
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);

0 commit comments

Comments
 (0)