Commit 0e13e7b4 authored by Bastien Nocera's avatar Bastien Nocera Committed by Benjamin Tissoires

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: stable@vger.kernel.org # v5.16+
Reported-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarBastien Nocera <hadess@hadess.net>
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20221215154416.111704-1-hadess@hadess.net
parent 2043f9a3
...@@ -2548,12 +2548,17 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, ...@@ -2548,12 +2548,17 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
struct hid_device *hid = hidpp->hid_dev; struct hid_device *hid = hidpp->hid_dev;
struct hid_input *hidinput; struct hid_input *hidinput;
struct input_dev *dev; struct input_dev *dev;
const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor); struct usb_device_descriptor *udesc;
const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice); u16 bcdDevice;
struct ff_device *ff; struct ff_device *ff;
int error, j, num_slots = data->num_effects; int error, j, num_slots = data->num_effects;
u8 version; u8 version;
if (!hid_is_usb(hid)) {
hid_err(hid, "device is not USB\n");
return -ENODEV;
}
if (list_empty(&hid->inputs)) { if (list_empty(&hid->inputs)) {
hid_err(hid, "no inputs found\n"); hid_err(hid, "no inputs found\n");
return -ENODEV; return -ENODEV;
...@@ -2567,6 +2572,8 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, ...@@ -2567,6 +2572,8 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
} }
/* Get firmware release */ /* Get firmware release */
udesc = &(hid_to_usb_dev(hid)->descriptor);
bcdDevice = le16_to_cpu(udesc->bcdDevice);
version = bcdDevice & 255; version = bcdDevice & 255;
/* Set supported force feedback capabilities */ /* Set supported force feedback capabilities */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment