All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HID: logitech-hidpp: Guard FF init code against non-USB devices
@ 2022-12-15 15:44 Bastien Nocera
  2022-12-19 14:06 ` Benjamin Tissoires
  0 siblings, 1 reply; 2+ messages in thread
From: Bastien Nocera @ 2022-12-15 15:44 UTC (permalink / raw)
  To: linux-input
  Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

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.

Reported-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-logitech-hidpp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 7075c887ec50..08ad19097e9e 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2746,12 +2746,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;
@@ -2765,6 +2770,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 */
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] HID: logitech-hidpp: Guard FF init code against non-USB devices
  2022-12-15 15:44 [PATCH] HID: logitech-hidpp: Guard FF init code against non-USB devices Bastien Nocera
@ 2022-12-19 14:06 ` Benjamin Tissoires
  0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Tissoires @ 2022-12-19 14:06 UTC (permalink / raw)
  To: Bastien Nocera
  Cc: linux-input, linux-kernel, Jiri Kosina,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

On Thu, Dec 15, 2022 at 4:44 PM Bastien Nocera <hadess@hadess.net> wrote:
>
> 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.
>
> Reported-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> Signed-off-by: Bastien Nocera <hadess@hadess.net>
> ---

I have added cc: stable, and applied to for-6.2/upstream-fixes

Thanks,
Benjamin


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-19 14:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15 15:44 [PATCH] HID: logitech-hidpp: Guard FF init code against non-USB devices Bastien Nocera
2022-12-19 14:06 ` Benjamin Tissoires

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.