Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] HID: hiddev: set report-init policy before device registration
@ 2026-06-30 21:18 Yousef Alhouseen
  0 siblings, 0 replies; only message in thread
From: Yousef Alhouseen @ 2026-06-30 21:18 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-usb, linux-input, linux-kernel, Yousef Alhouseen

usb_register_dev() publishes the hiddev character device before
hiddev_connect() initializes the report policy. A process that opens the
new node immediately can issue a usage ioctl while initialized is still
false and trigger usbhid_init_reports(), bypassing
HID_QUIRK_NO_INIT_REPORTS.

Set initialized before registering the character device so every opener
observes the quirk-selected policy.

Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
---
 drivers/hid/usbhid/hiddev.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 6378801b22c6..c822e7dee8b7 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -900,6 +900,8 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
 	hid->hiddev = hiddev;
 	hiddev->hid = hid;
 	hiddev->exist = 1;
+	/* Honor NO_INIT_REPORTS before the character device becomes visible. */
+	hiddev->initialized = hid->quirks & HID_QUIRK_NO_INIT_REPORTS;
 	retval = usb_register_dev(usbhid->intf, &hiddev_class);
 	if (retval) {
 		hid_err(hid, "Not able to get a minor for this device\n");
@@ -908,12 +910,6 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
 		return retval;
 	}
 
-	/*
-	 * If HID_QUIRK_NO_INIT_REPORTS is set, make sure we don't initialize
-	 * the reports.
-	 */
-	hiddev->initialized = hid->quirks & HID_QUIRK_NO_INIT_REPORTS;
-
 	hiddev->minor = usbhid->intf->minor;
 
 	return 0;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-30 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 21:18 [PATCH] HID: hiddev: set report-init policy before device registration Yousef Alhouseen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox