All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>, linux-input@vger.kernel.org
Subject: [PATCH v2 2/6] HID: core: Add a hid_is_usb_device() helper function
Date: Wed,  5 May 2021 23:39:31 +0200	[thread overview]
Message-ID: <20210505213935.631351-3-hdegoede@redhat.com> (raw)
In-Reply-To: <20210505213935.631351-1-hdegoede@redhat.com>

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@redhat.com>
---
 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


  parent reply	other threads:[~2021-05-05 21:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 21:39 [PATCH v2 0/6] HID: Misc. fixes Hans de Goede
2021-05-05 21:39 ` [PATCH v2 1/6] HID: core: Remove extraneous empty line before EXPORT_SYMBOL_GPL(hid_check_keys_pressed) Hans de Goede
2021-05-05 21:39 ` Hans de Goede [this message]
2021-05-05 21:39 ` [PATCH v2 3/6] HID: multitouch: Disable event reporting on suspend on the Asus T101HA touchpad Hans de Goede
2021-05-05 21:39 ` [PATCH v2 4/6] HID: multitouch: Disable event reporting on suspend when our parent is not a wakeup-source Hans de Goede
2021-05-05 21:39 ` [PATCH v2 5/6] HID: asus: Cleanup Asus T101HA keyboard-dock handling Hans de Goede
2021-05-05 21:39 ` [PATCH v2 6/6] HID: asus: Switch to the new hid_is_usb_device() helper Hans de Goede
2021-05-26 10:38 ` [PATCH v2 0/6] HID: Misc. fixes Jiri Kosina
2021-05-26 10:46   ` Hans de Goede
2021-05-26 11:06     ` Jiri Kosina

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=20210505213935.631351-3-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    /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.