Skip to content

Commit

Permalink
HID: logitech-hidpp: Guard FF init code against non-USB devices
Browse files Browse the repository at this point in the history
commit 0e13e7b upstream.

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: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Bastien Nocera <hadess@hadess.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20221215154416.111704-1-hadess@hadess.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
hadess authored and gregkh committed Dec 31, 2022
1 parent d95d830 commit 5b7c306
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/hid/hid-logitech-hidpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2548,12 +2548,17 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
struct hid_device *hid = hidpp->hid_dev;
struct hid_input *hidinput;
struct input_dev *dev;
const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
struct usb_device_descriptor *udesc;
u16 bcdDevice;
struct ff_device *ff;
int error, j, num_slots = data->num_effects;
u8 version;

if (!hid_is_usb(hid)) {
hid_err(hid, "device is not USB\n");
return -ENODEV;
}

if (list_empty(&hid->inputs)) {
hid_err(hid, "no inputs found\n");
return -ENODEV;
Expand All @@ -2567,6 +2572,8 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
}

/* Get firmware release */
udesc = &(hid_to_usb_dev(hid)->descriptor);
bcdDevice = le16_to_cpu(udesc->bcdDevice);
version = bcdDevice & 255;

/* Set supported force feedback capabilities */
Expand Down

0 comments on commit 5b7c306

Please sign in to comment.