Sometimes HID drivers want to know if the hid_device with which they are dealing is using the usb_hid_driver. For example this is often done to check if it is safe to cast hid_device->dev.parent to an usb_interface like this: struct usb_interface *intf = to_usb_interface(hdev->dev.parent); If drivers directly call hid_is_using_ll_driver(hdev, &usb_hid_driver)) for this, then this leads to a "missing symbol usb_hid_driver" compilation error when CONFIG_USB_HID is not enabled. Requiring the driver to have a depends on USB_HID in their Kconfig entry to work around this. Add a hid_is_usb_device() helper function which drivers can use to safely check if they are dealing with a usb_hid device without needing to worry about the CONFIG_USB_HID setting. Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx> --- drivers/hid/hid-core.c | 10 ++++++++++ include/linux/hid.h | 1 + 2 files changed, 11 insertions(+) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index b593dff411a6..294c3cf05d85 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2590,6 +2590,16 @@ int hid_check_keys_pressed(struct hid_device *hid) } EXPORT_SYMBOL_GPL(hid_check_keys_pressed); +bool hid_is_usb_device(struct hid_device *hid) +{ +#if IS_ENABLED(CONFIG_USB_HID) + return hid_is_using_ll_driver(hid, &usb_hid_driver); +#else + return false; +#endif +} +EXPORT_SYMBOL_GPL(hid_is_usb_device); + static int __init hid_init(void) { int ret; diff --git a/include/linux/hid.h b/include/linux/hid.h index ef702b3f56e3..6ceadc234132 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -901,6 +901,7 @@ struct hid_report *hid_validate_values(struct hid_device *hid, void hid_setup_resolution_multiplier(struct hid_device *hid); int hid_open_report(struct hid_device *device); int hid_check_keys_pressed(struct hid_device *hid); +bool hid_is_usb_device(struct hid_device *hid); int hid_connect(struct hid_device *hid, unsigned int connect_mask); void hid_disconnect(struct hid_device *hid); bool hid_match_one_id(const struct hid_device *hdev, -- 2.31.1