Skip to content

Commit 0e13e7b

Browse files
hadessbentiss
authored andcommitted
HID: logitech-hidpp: Guard FF init code against non-USB devices
The Force Feedback code assumes that all the devices passed to it will be USB devices, but that might not be the case for emulated devices. Guard against a crash by checking the device type before poking at USB properties. Cc: [email protected] # v5.16+ Reported-by: Benjamin Tissoires <[email protected]> Signed-off-by: Bastien Nocera <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2043f9a commit 0e13e7b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/hid/hid-logitech-hidpp.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,12 +2548,17 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
25482548
struct hid_device *hid = hidpp->hid_dev;
25492549
struct hid_input *hidinput;
25502550
struct input_dev *dev;
2551-
const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
2552-
const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
2551+
struct usb_device_descriptor *udesc;
2552+
u16 bcdDevice;
25532553
struct ff_device *ff;
25542554
int error, j, num_slots = data->num_effects;
25552555
u8 version;
25562556

2557+
if (!hid_is_usb(hid)) {
2558+
hid_err(hid, "device is not USB\n");
2559+
return -ENODEV;
2560+
}
2561+
25572562
if (list_empty(&hid->inputs)) {
25582563
hid_err(hid, "no inputs found\n");
25592564
return -ENODEV;
@@ -2567,6 +2572,8 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
25672572
}
25682573

25692574
/* Get firmware release */
2575+
udesc = &(hid_to_usb_dev(hid)->descriptor);
2576+
bcdDevice = le16_to_cpu(udesc->bcdDevice);
25702577
version = bcdDevice & 255;
25712578

25722579
/* Set supported force feedback capabilities */

0 commit comments

Comments
 (0)