Blob Blame History Raw
From f83baa0cb6cfc92ebaf7f9d3a99d7e34f2e77a8a Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Wed, 1 Dec 2021 19:35:01 +0100
Subject: [PATCH] HID: add hid_is_usb() function to make it simpler for USB detection
Git-commit: f83baa0cb6cfc92ebaf7f9d3a99d7e34f2e77a8a
Patch-mainline: v5.16-rc5
References: CVE-2022-20132 bsc#1200619

A number of HID drivers already call hid_is_using_ll_driver() but only
for the detection of if this is a USB device or not.  Make this more
obvious by creating hid_is_usb() and calling the function that way.

Also converts the existing hid_is_using_ll_driver() functions to use the
new call.

Cc: Jiri Kosina <jikos@kernel.org>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org
Cc: stable@vger.kernel.org
Tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20211201183503.2373082-1-gregkh@linuxfoundation.org
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/hid/hid-logitech-dj.c |    3 +++
 include/linux/hid.h           |    5 +++++
 2 files changed, 8 insertions(+)

--- a/drivers/hid/hid-logitech-dj.c
+++ b/drivers/hid/hid-logitech-dj.c
@@ -996,6 +996,9 @@ static int logi_dj_probe(struct hid_devi
 	struct dj_receiver_dev *djrcv_dev;
 	int retval;
 
+	if (!hid_is_usb(hdev))
+		return -EINVAL;
+
 	dbg_hid("%s called for ifnum %d\n", __func__,
 		intf->cur_altsetting->desc.bInterfaceNumber);
 
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -776,6 +776,11 @@ static inline bool hid_is_using_ll_drive
 	return hdev->ll_driver == driver;
 }
 
+static inline bool hid_is_usb(struct hid_device *hdev)
+{
+	return hid_is_using_ll_driver(hdev, &usb_hid_driver);
+}
+
 #define	PM_HINT_FULLON	1<<5
 #define PM_HINT_NORMAL	1<<1