From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from endrift.com (endrift.com [173.255.198.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0860D2F7F05 for ; Wed, 24 Jun 2026 02:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.255.198.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782268634; cv=none; b=cmkujprs/5aCYQexjtMX+QZ+bJURLmyKvTuf+ZfvvZ5gYC9fae3oJ8wcU75fF41k9ZC31m1HiWSmTwJaDDiaRuOv//bBCuV8A3k07DxhaY0oxYU3uefa5UAc6X7G8RANc21H+ArDpwZS9U4nMnLrXDA4xj6ARLD2bmDvj2s+Hz0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782268634; c=relaxed/simple; bh=7c207toMdYkt9wbodpL0rdJjYBApMyGurnRPp7jkwCM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XCbSKY8aufSt269qt0zOzqnvGS8FWvNTYvEn4amI1vNyJDhvhiYQa4fZ4jPQNPYCvai4/FH9jvdr5bZr5IuG//IQLv0jFT1EhwFIXS16utBS0JDLBcr8gzQkAxeHv91mfGctFo+ltaaBkNDZ4/ZMnKZ+CnqmY8ocVLTBDId+LIQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com; spf=pass smtp.mailfrom=endrift.com; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b=a6Q1MpX6; arc=none smtp.client-ip=173.255.198.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=endrift.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b="a6Q1MpX6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=endrift.com; s=2020; t=1782268626; bh=7c207toMdYkt9wbodpL0rdJjYBApMyGurnRPp7jkwCM=; h=From:To:Cc:Subject:Date:From; b=a6Q1MpX6atYmzGgKLmBIriRnXi7UHdP4awST261EDPOb/kOCxaIc5WMY+28ccxjbh QB4Rq1hw/ediGZPoDxJdkyqDMIAtDo2YJFN0KFBd4O0icpNwLUZRebs4Cf6Fl1K2T2 gzoMa5e+2XZYXJTKrV2htuK7JTphddV70TeeHmACt3YhLwycy2Y8nGZuepVTRhMe+1 iv/taoONv5EzEv94FZPBwCPgRGrmEHwu+n3Xh4PaKH7yYvsTVVle597BLYEmEpfT2M VtJzUO+mSXm8N7XWmNNr0MRuHQhch0HjPqVQctr1lqQX277xQ7LH6gty+uKxLmPdFX o1lqcNFYzFI5g== Received: from microtis.vulpes.eutheria.net (71-212-73-87.tukw.qwest.net [71.212.73.87]) by endrift.com (Postfix) with ESMTPSA id EF21EA018; Tue, 23 Jun 2026 19:37:05 -0700 (PDT) From: Vicki Pfau To: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Cc: Vicki Pfau Subject: [PATCH] HID: core: Expose id attributes in sysfs Date: Tue, 23 Jun 2026 19:36:01 -0700 Message-ID: <20260624023601.1197134-1-vi@endrift.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit udev rules for handling input devices generally match on idVendor and idProduct for USB hidraw or id/vendor and id/product for evdev nodes. However, hidraw nodes that aren't created by the USB subsystem will only expose this information to udev via the kernel path itself. This leads to doing substring matching, which can be error-prone or overzealous. Instead, since the HID subsystem already has this information, we can expose it directly in the same format that evdev exposes it. Signed-off-by: Vicki Pfau --- drivers/hid/hid-core.c | 45 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 41a79e43c82b..397de63297c6 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2900,6 +2900,45 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a, } static DEVICE_ATTR_RO(modalias); +/* + * Expose this as bustype instead of bus as + * that's the name the input subsystem uses + */ +static ssize_t bustype_show(struct device *dev, struct device_attribute *a, + char *buf) +{ + struct hid_device *hdev = to_hid_device(dev); + + return sysfs_emit(buf, "%04x\n", hdev->bus); +} +static DEVICE_ATTR_RO(bustype); + +#define HID_DEV_ID_ATTR(name) \ +static ssize_t name##_show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct hid_device *hdev = to_hid_device(dev); \ + \ + return sysfs_emit(buf, "%04x\n", hdev->name); \ +} \ +static DEVICE_ATTR_RO(name) + +HID_DEV_ID_ATTR(vendor); +HID_DEV_ID_ATTR(product); +HID_DEV_ID_ATTR(version); + +static struct attribute *hid_dev_id_attrs[] = { + &dev_attr_bustype.attr, + &dev_attr_vendor.attr, + &dev_attr_product.attr, + &dev_attr_version.attr, + NULL +}; +static const struct attribute_group hid_dev_id_attr_group = { + .name = "id", + .attrs = hid_dev_id_attrs, +}; static struct attribute *hid_dev_attrs[] = { &dev_attr_modalias.attr, NULL, @@ -2912,7 +2951,11 @@ static const struct attribute_group hid_dev_group = { .attrs = hid_dev_attrs, .bin_attrs = hid_dev_bin_attrs, }; -__ATTRIBUTE_GROUPS(hid_dev); +static const struct attribute_group *hid_dev_groups[] = { + &hid_dev_group, + &hid_dev_id_attr_group, + NULL +}; static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env) { -- 2.54.0