Skip to content

Commit

Permalink
Merge branch 'for-6.12/constify-rdesc' into for-linus
Browse files Browse the repository at this point in the history
- Constification of report descriptors so drivers can use read-only
  memory when declaring report descriptors fixups (Thomas Weißschuh)
  • Loading branch information
Benjamin Tissoires committed Sep 13, 2024
2 parents 37c25a5 + 9f5305e commit 054e0bd
Show file tree
Hide file tree
Showing 58 changed files with 167 additions and 171 deletions.
6 changes: 2 additions & 4 deletions drivers/hid/bpf/hid_bpf_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int dispatch_hid_bpf_output_report(struct hid_device *hdev,
}
EXPORT_SYMBOL_GPL(dispatch_hid_bpf_output_report);

u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev, u8 *rdesc, unsigned int *size)
u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev, const u8 *rdesc, unsigned int *size)
{
int ret;
struct hid_bpf_ctx_kern ctx_kern = {
Expand Down Expand Up @@ -179,9 +179,7 @@ u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev, u8 *rdesc, unsigned int *s
*size = ret;
}

rdesc = krealloc(ctx_kern.data, *size, GFP_KERNEL);

return rdesc;
return krealloc(ctx_kern.data, *size, GFP_KERNEL);

ignore_bpf:
kfree(ctx_kern.data);
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ static void apple_battery_timer_tick(struct timer_list *t)
* MacBook JIS keyboard has wrong logical maximum
* Magic Keyboard JIS has wrong logical maximum
*/
static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
struct apple_sc *asc = hid_get_drvdata(hdev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-asus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ static const __u8 asus_g752_fixed_rdesc[] = {
0x2A, 0xFF, 0x00, /* Usage Maximum (0xFF) */
};

static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-aureal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "hid-ids.h"

static __u8 *aureal_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *aureal_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize >= 54 && rdesc[52] == 0x25 && rdesc[53] == 0x01) {
Expand Down
6 changes: 3 additions & 3 deletions drivers/hid/hid-bigbenff.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
* - map previously unused analog trigger data to Z/RZ
* - simplify feature and output descriptor
*/
static __u8 pid0902_rdesc_fixed[] = {
static const __u8 pid0902_rdesc_fixed[] = {
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x09, 0x05, /* Usage (Game Pad) */
0xA1, 0x01, /* Collection (Application) */
Expand Down Expand Up @@ -464,12 +464,12 @@ static int bigben_probe(struct hid_device *hid,
return error;
}

static __u8 *bigben_report_fixup(struct hid_device *hid, __u8 *rdesc,
static const __u8 *bigben_report_fixup(struct hid_device *hid, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize == PID0902_RDESC_ORIG_SIZE) {
rdesc = pid0902_rdesc_fixed;
*rsize = sizeof(pid0902_rdesc_fixed);
return pid0902_rdesc_fixed;
} else
hid_warn(hid, "unexpected rdesc, please submit for review\n");
return rdesc;
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-cherry.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Cherry Cymotion keyboard have an invalid HID report descriptor,
* that needs fixing before we can parse it.
*/
static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/hid/hid-chicony.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
return 1;
}

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

Expand Down
6 changes: 3 additions & 3 deletions drivers/hid/hid-cmedia.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MODULE_LICENSE("GPL");
/* Fixed report descriptor of HS-100B audio chip
* Bit 4 is an abolute Microphone mute usage instead of being unassigned.
*/
static __u8 hs100b_rdesc_fixed[] = {
static const __u8 hs100b_rdesc_fixed[] = {
0x05, 0x0C, /* Usage Page (Consumer), */
0x09, 0x01, /* Usage (Consumer Control), */
0xA1, 0x01, /* Collection (Application), */
Expand Down Expand Up @@ -199,13 +199,13 @@ static struct hid_driver cmhid_driver = {
.input_mapping = cmhid_input_mapping,
};

static __u8 *cmhid_hs100b_report_fixup(struct hid_device *hid, __u8 *rdesc,
static const __u8 *cmhid_hs100b_report_fixup(struct hid_device *hid, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize == HS100B_RDESC_ORIG_SIZE) {
hid_info(hid, "Fixing CMedia HS-100B report descriptor\n");
rdesc = hs100b_rdesc_fixed;
*rsize = sizeof(hs100b_rdesc_fixed);
return hs100b_rdesc_fixed;
}
return rdesc;
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ static void hid_device_release(struct device *dev)
* items, though they are not used yet.
*/

static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
static const u8 *fetch_item(const __u8 *start, const __u8 *end, struct hid_item *item)
{
u8 b;

Expand Down Expand Up @@ -880,8 +880,8 @@ static int hid_scan_report(struct hid_device *hid)
{
struct hid_parser *parser;
struct hid_item item;
__u8 *start = hid->dev_rdesc;
__u8 *end = start + hid->dev_rsize;
const __u8 *start = hid->dev_rdesc;
const __u8 *end = start + hid->dev_rsize;
static int (*dispatch_type[])(struct hid_parser *parser,
struct hid_item *item) = {
hid_scan_main,
Expand Down Expand Up @@ -946,7 +946,7 @@ static int hid_scan_report(struct hid_device *hid)
* Allocate the device report as read by the bus driver. This function should
* only be called from parse() in ll drivers.
*/
int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
int hid_parse_report(struct hid_device *hid, const __u8 *start, unsigned size)
{
hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
if (!hid->dev_rdesc)
Expand Down Expand Up @@ -1204,10 +1204,10 @@ int hid_open_report(struct hid_device *device)
struct hid_parser *parser;
struct hid_item item;
unsigned int size;
__u8 *start;
const __u8 *start;
__u8 *buf;
__u8 *end;
__u8 *next;
const __u8 *end;
const __u8 *next;
int ret;
int i;
static int (*dispatch_type[])(struct hid_parser *parser,
Expand Down
4 changes: 2 additions & 2 deletions drivers/hid/hid-corsair.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ static int corsair_input_mapping(struct hid_device *dev,
* - USB ID 1b1c:1b3e, sold as Scimitar RGB Pro Gaming mouse
*/

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

Expand Down
4 changes: 2 additions & 2 deletions drivers/hid/hid-cougar.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ static void cougar_fix_g6_mapping(void)
/*
* Constant-friendly rdesc fixup for mouse interface
*/
static __u8 *cougar_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
static const __u8 *cougar_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize >= 117 && rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
(rdesc[115] | rdesc[116] << 8) >= HID_MAX_USAGES) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-cypress.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static __u8 *va_logical_boundary_fixup(struct hid_device *hdev, __u8 *rdesc,
return rdesc;
}

static __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
Expand Down
8 changes: 4 additions & 4 deletions drivers/hid/hid-dr.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static inline int drff_init(struct hid_device *hid)
#define PID0011_RDESC_ORIG_SIZE 101

/* Fixed report descriptor for PID 0x011 joystick */
static __u8 pid0011_rdesc_fixed[] = {
static const __u8 pid0011_rdesc_fixed[] = {
0x05, 0x01, /* Usage Page (Desktop), */
0x09, 0x04, /* Usage (Joystick), */
0xA1, 0x01, /* Collection (Application), */
Expand Down Expand Up @@ -228,14 +228,14 @@ static __u8 pid0011_rdesc_fixed[] = {
0xC0 /* End Collection */
};

static __u8 *dr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
static const __u8 *dr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
switch (hdev->product) {
case 0x0011:
if (*rsize == PID0011_RDESC_ORIG_SIZE) {
rdesc = pid0011_rdesc_fixed;
*rsize = sizeof(pid0011_rdesc_fixed);
return pid0011_rdesc_fixed;
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-elecom.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void mouse_button_fixup(struct hid_device *hdev,
rdesc[padding_bit + 1] = MOUSE_BUTTONS_MAX - nbuttons;
}

static __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
switch (hdev->product) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-gembird.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static const __u8 gembird_jpd_fixed_rdesc[] = {
0x81, 0x02, /* Input (Data,Var,Abs) */
};

static __u8 *gembird_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *gembird_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
__u8 *new_rdesc;
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-glorious.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MODULE_DESCRIPTION("HID driver for Glorious PC Gaming Race mice");
* keyboard HID report, causing keycodes to be misinterpreted.
* Fix this by setting Usage Minimum to 0 in that report.
*/
static __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize == 213 &&
Expand Down
6 changes: 3 additions & 3 deletions drivers/hid/hid-holtek-kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* to the boot interface.
*/

static __u8 holtek_kbd_rdesc_fixed[] = {
static const __u8 holtek_kbd_rdesc_fixed[] = {
/* Original report descriptor, with reduced number of consumer usages */
0x05, 0x01, /* Usage Page (Desktop), */
0x09, 0x80, /* Usage (Sys Control), */
Expand Down Expand Up @@ -102,14 +102,14 @@ static __u8 holtek_kbd_rdesc_fixed[] = {
0xC0, /* End Collection */
};

static __u8 *holtek_kbd_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *holtek_kbd_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);

if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
rdesc = holtek_kbd_rdesc_fixed;
*rsize = sizeof(holtek_kbd_rdesc_fixed);
return holtek_kbd_rdesc_fixed;
}
return rdesc;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/hid/hid-holtek-mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* - USB ID 04d9:a0c2, sold as ETEKCITY Scroll T-140 Gaming Mouse
*/

static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
static const __u8 *holtek_mouse_report_fixup(struct hid_device *hdev,
__u8 *rdesc, unsigned int *rsize)
{
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);

Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-ite.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define QUIRK_TOUCHPAD_ON_OFF_REPORT BIT(0)

static __u8 *ite_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize)
static const __u8 *ite_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize)
{
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);

Expand Down
8 changes: 3 additions & 5 deletions drivers/hid/hid-keytouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@

/* Replace the broken report descriptor of this device with rather
* a default one */
static __u8 keytouch_fixed_rdesc[] = {
static const __u8 keytouch_fixed_rdesc[] = {
0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x05, 0x07, 0x19, 0xe0, 0x29, 0xe7, 0x15,
0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x95, 0x01, 0x75, 0x08,
0x81, 0x01, 0x95, 0x03, 0x75, 0x01, 0x05, 0x08, 0x19, 0x01, 0x29, 0x03, 0x91,
0x02, 0x95, 0x05, 0x75, 0x01, 0x91, 0x01, 0x95, 0x06, 0x75, 0x08, 0x15, 0x00,
0x26, 0xff, 0x00, 0x05, 0x07, 0x19, 0x00, 0x2a, 0xff, 0x00, 0x81, 0x00, 0xc0
};

static __u8 *keytouch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *keytouch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
hid_info(hdev, "fixing up Keytouch IEC report descriptor\n");

rdesc = keytouch_fixed_rdesc;
*rsize = sizeof(keytouch_fixed_rdesc);

return rdesc;
return keytouch_fixed_rdesc;
}

static const struct hid_device_id keytouch_devices[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-kye.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static __u8 *kye_tablet_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int
return rdesc;
}

static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
switch (hdev->product) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-lenovo.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static const __u8 lenovo_tpIIbtkbd_need_fixup_collection[] = {
0x81, 0x01, /* Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) */
};

static __u8 *lenovo_report_fixup(struct hid_device *hdev, __u8 *rdesc,
static const __u8 *lenovo_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
switch (hdev->product) {
Expand Down
Loading

0 comments on commit 054e0bd

Please sign in to comment.