From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Michael Zaidman <michael.zaidman@gmail.com>,
Rishi Gupta <gupt21@gmail.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
David Barksdale <dbarksdale@uplogix.com>,
Andrej Shadura <andrew@shadura.me>,
Johannes Roith <johannes@gnu-linux.rocks>,
linux-input@vger.kernel.org, linux-bluetooth@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] HID: Use hidraw_instance() in drivers
Date: Tue, 13 Oct 2026 22:13:23 -0700 [thread overview]
Message-ID: <20261014051326.3784498-4-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20261014051326.3784498-1-dmitry.torokhov@gmail.com>
Instead of directly dereferencing struct hidraw to inspect minor device
numbers, use hidraw_instance(). This removes the dependency of these
drivers on the internal struct hidraw layout.
For hid-cp2112, fall back to dev_name() when hidraw is not available.
For hid-led and hid-u2fzero, require CONFIG_HIDRAW and propagate errors
if hidraw is unavailable.
Assisted-by: LLM
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/hid/Kconfig | 3 +++
drivers/hid/hid-cp2112.c | 13 ++++++++-----
drivers/hid/hid-led.c | 8 ++++++--
drivers/hid/hid-u2fzero.c | 8 ++++++--
4 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index f9bcaeb66385..1d2657edab27 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -587,6 +587,7 @@ config HID_LCPOWER
config HID_LED
tristate "Simple RGB LED support"
+ depends on HIDRAW
depends on LEDS_CLASS
help
Support for simple RGB LED devices. Currently supported are:
@@ -1252,6 +1253,7 @@ config HID_TOPRE
config HID_THINGM
tristate "ThingM blink(1) USB RGB LED"
+ depends on HIDRAW
depends on LEDS_CLASS
select HID_LED
help
@@ -1285,6 +1287,7 @@ config HID_UDRAW_PS3
config HID_U2FZERO
tristate "U2F Zero LED and RNG support"
depends on USB_HID
+ depends on HIDRAW
depends on LEDS_CLASS
depends on HW_RANDOM
help
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 04379db93571..148946b04bff 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -1225,7 +1225,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
struct gpio_irq_chip *girq;
struct i2c_timings timings;
u32 addr;
- int ret;
+ int ret, instance;
dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
@@ -1330,9 +1330,13 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
dev->adap.algo = &smbus_algorithm;
dev->adap.algo_data = dev;
dev->adap.dev.parent = &hdev->dev;
- snprintf(dev->adap.name, sizeof(dev->adap.name),
- "CP2112 SMBus Bridge on hidraw%d",
- ((struct hidraw *)hdev->hidraw)->minor);
+ instance = hidraw_instance(hdev);
+ if (instance >= 0)
+ snprintf(dev->adap.name, sizeof(dev->adap.name),
+ "CP2112 SMBus Bridge on hidraw%d", instance);
+ else
+ snprintf(dev->adap.name, sizeof(dev->adap.name),
+ "CP2112 SMBus Bridge on %s", dev_name(&hdev->dev));
dev->hwversion = buf[2];
init_waitqueue_head(&dev->wait);
@@ -1494,4 +1498,3 @@ module_hid_driver(cp2112_driver);
MODULE_DESCRIPTION("Silicon Labs HID USB to SMBus master bridge");
MODULE_AUTHOR("David Barksdale <dbarksdale@uplogix.com>");
MODULE_LICENSE("GPL");
-
diff --git a/drivers/hid/hid-led.c b/drivers/hid/hid-led.c
index 7d82f8d426bb..63fd723d9e69 100644
--- a/drivers/hid/hid-led.c
+++ b/drivers/hid/hid-led.c
@@ -448,7 +448,7 @@ static int hidled_init_rgb(struct hidled_rgb *rgb, unsigned int minor)
static int hidled_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
struct hidled_device *ldev;
- unsigned int minor;
+ int minor;
int ret, i;
ldev = devm_kzalloc(&hdev->dev, sizeof(*ldev), GFP_KERNEL);
@@ -488,7 +488,11 @@ static int hidled_probe(struct hid_device *hdev, const struct hid_device_id *id)
if (ret)
return ret;
- minor = ((struct hidraw *) hdev->hidraw)->minor;
+ minor = hidraw_instance(hdev);
+ if (minor < 0) {
+ hid_hw_stop(hdev);
+ return minor;
+ }
for (i = 0; i < ldev->config->num_leds; i++) {
ldev->rgb[i].ldev = ldev;
diff --git a/drivers/hid/hid-u2fzero.c b/drivers/hid/hid-u2fzero.c
index 82404b6e2d25..83e223c12cd6 100644
--- a/drivers/hid/hid-u2fzero.c
+++ b/drivers/hid/hid-u2fzero.c
@@ -307,7 +307,7 @@ static int u2fzero_probe(struct hid_device *hdev,
const struct hid_device_id *id)
{
struct u2fzero_device *dev;
- unsigned int minor;
+ int minor;
int ret;
if (!hid_is_usb(hdev))
@@ -347,7 +347,11 @@ static int u2fzero_probe(struct hid_device *hdev,
dev->present = true;
- minor = ((struct hidraw *) hdev->hidraw)->minor;
+ minor = hidraw_instance(hdev);
+ if (minor < 0) {
+ ret = minor;
+ goto err_free_urb;
+ }
ret = u2fzero_init_led(dev, minor);
if (ret)
--
2.56.0.385.gd3acb90ef8-goog
next prev parent reply other threads:[~2026-10-14 5:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 5:13 [PATCH 0/5] HID: hidraw: Encapsulate struct hidraw and make hidraw.h private Dmitry Torokhov
2026-10-14 5:13 ` [PATCH 1/5] HID: core: Move internal declarations and drop unused exports Dmitry Torokhov
2026-10-14 6:35 ` HID: hidraw: Encapsulate struct hidraw and make hidraw.h private bluez.test.bot
2026-10-14 5:13 ` [PATCH 2/5] HID: hidraw: Introduce hidraw_instance() helper Dmitry Torokhov
2026-10-14 5:13 ` Dmitry Torokhov [this message]
2026-10-14 10:38 ` [PATCH] HID: cp2112: don't dereference hdev->hidraw unconditionally Jinmo Yang
2026-10-14 13:50 ` Benjamin Tissoires
2026-10-14 5:13 ` [PATCH 4/5] HID: Drop unused linux/hidraw.h includes Dmitry Torokhov
2026-10-14 5:13 ` [PATCH 5/5] HID: hidraw: Make hidraw.h private to HID subsystem Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261014051326.3784498-4-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=andrew@shadura.me \
--cc=bentiss@kernel.org \
--cc=dbarksdale@uplogix.com \
--cc=gupt21@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=jikos@kernel.org \
--cc=johannes@gnu-linux.rocks \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=michael.zaidman@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.