Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH v6 00/13] HID: Add hid-plugin framework & convert hid-haptic into a generic plugin
@ 2026-12-02 18:33 Rong Zhang
  2026-12-02 18:33 ` [PATCH v6 01/13] HID: haptic: Get rid of input_ff_destroy() in error paths Rong Zhang
                   ` (12 more replies)
  0 siblings, 13 replies; 16+ messages in thread
From: Rong Zhang @ 2026-12-02 18:33 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Angela Czubak, Henrik Rydberg,
	Dmitry Torokhov
  Cc: Aaron Erhardt, linux-input, linux-kernel, Rong Zhang, stable

Several weeks ago, I bought a Logitech MX Master 4 with haptic feedback.
The hid-haptic already supports the Haptic usage page, but it only works
with hid-multitouch. I am also working on adding support for the
LampArray usage page recently [1].

The two drivers have a common characteristic, i.e., they targets
specific HID usage pages instead of specific devices. This leads to
additional linkage dependences because the device drivers need to call
functions provided by the usage page drivers.

Logically, the dependence should be reversed, i.e., a usage page driver
should be an optional component of the associated device driver and is
only loaded by the device driver when the device has the usage page.

Introduce hid-plugin framework for loadable plugin modules to achieve
the said logical dependence. Each plugin has a unique hid_plugin_id when
enabled, so that HID drivers can connect to it accordingly.

Plugins can be either builtin or modules. A plugin module is requested
asynchronously when a HID device tries to use it. If the module is not
available yet, the device is probed without the plugin and reprobed once
the plugin registers itself. The reprobe procedure is inspired by commit
c17a7476e4c4 ("HID: core: rewrite the hid-generic automatic unbind").

Once a plugin is fully loaded (or if the plugin is builtin), subsequent
plugin connection attempts only require RCU dereferences and module
refcount increments, without the need of requesting a module.

The plugin's private data is automatically initialized on connection
with its pointer stored into hid_device. Disconnection also frees it
automatically. When the HID device is about to finish probe, unbound
plugins are automatically disconnected, and HID driver removal
disconnects all plugins. When a plugin turns out to be unsuitable for
the associated HID device, it can also be disconnected early to prevent
further use of the plugin.

When a plugin is disabled, its ID maps to HID_PLUGIN_DISABLED, and calls
to the plugin helper functions are eliminated by the compiler.

With the framework, convert hid-haptic to the first plugin. After the
conversion, it connects to hid-input and becomes a generic plugin.

The first few patches fix pre-existing bugs in hid-haptic and
hid-multitouch. Then the later patches refactor hid-haptic, implement
the hid-plugin framework and finish the conversion. Finally, generalize
hid-haptic.

I volunteer to maintain the framework as well as its plugins, including
hid-haptic and future ones.

Thanks Benjamin Tissoires for the inspiration for the implementation.

[1]: I know Texudo folks are working on adding hid-lamparray to connect
it to hid-generic. I am not in favor of their design, so I decided to
write a new one. In my local tree, I've had an independent
implementation with HIDRAW sniff, autonomous mode as an LED trigger,
RGB/non-RGB LampArray support, per-key LED device support, etc. I will
submit it once this series settles.

Suggested-by: Benjamin Tissoires <bentiss@kernel.org>
Link: https://lore.kernel.org/linux-input/auypydfkhx2eg7vp764way4batdilzc35inqda3exwzs3tk3ff@oagat6g46zto/
Signed-off-by: Rong Zhang <i@rong.moe>
---
Changes in v6:
- Rebase on top of hid/for-next
- Name hid-haptic's workqueue with the input device's kobject name to
  fix name collision and WQ_NAME_LEN warning
- Fix inverted td->is_haptic_touchpad check (thanks Sashiko)
- Use request_module_nowait() instead of request_module(), as the latter
  can't be used within aysnc context where some i2c-hid drivers add
  devices
- Disconnect unbound plugins automatically by consulting the
  newly-introduced bound() callback
- Free plugins' private data in their disconnect() callback for correct
  semantics, i.e., release resources wherever they were allocated
- Check mandatory callbacks on registration
- Add device_lock_assert() annotations
- Constify struct hid_plugin
- Do not attach haptic FF to unpopulated input (thanks Sashiko)
- Prefer PIDFF over hid-haptic
- Update the Kconfig help string to reflect the fact that hid-haptic
  becomes generic
- Link to v5: https://patch.msgid.link/20261130-hid-haptic-kmod-v5-0-4903f73d8cac@rong.moe

Changes in v5:
- Manage HID plugins' private data in the framework
- Disconnect all connected HID plugins on HID driver removal
- Add debug printk()s to track (dis)connection and (un)registration
- Only use HID_PLUGIN to build Kconfig menuconfig, rather than having
  plugins depend on it
  - Enable HID_PLUGIN by default to ease Kconfig migration
  - Build the hid-plugin framework only if HID_PLUGIN_CORE is selected
  - HID_HAPTIC selects it, so that olddefconfig preserves HID_HAPTIC's
    old value
- Connect hid-haptic to hid-inpput
- Convert hid-haptic to a generic plugin
- Add a quirk flag for Logitech MX Master 4
- Link to v4: https://patch.msgid.link/20261125-hid-haptic-kmod-v4-0-03713a89f656@rong.moe

Changes in v4:
- Drop get_device()/put_device() and try_module_get()/module_put()
  completely, as they are needless now (thanks Dmitry Torokhov)
- Drop synchronize_rcu() during registration as other drivers do, as
  there is nothing to protect
- Link to v3: https://patch.msgid.link/20261113-hid-haptic-kmod-v3-0-e7dfa8766c0d@rong.moe

Changes in v3:
- Correct the Fixes: tag of PATCH 4 (thanks Sashiko)
- Add missing Return: to hid_plugin_register()'s kernel-doc (ditto)
- Fix the return value of hid_haptic_connected_to_input() when
  hid-haptic is disabled (ditto)
- Link to v2: https://patch.msgid.link/20261110-hid-haptic-kmod-v2-0-b835a067cb62@rong.moe

Changes in v2:
- Reject touchpad applications with non-force units (thanks Sashiko)
- Only call runtime methods if the event source is the same input device
  as the stored one (ditto)
- Rebase on top of v7.4-rc2 due to the devm_kzalloc_obj() changes
- Link to v1: https://patch.msgid.link/20261102-hid-haptic-kmod-v1-0-a3de5626dade@rong.moe

---
Rong Zhang (13):
      HID: haptic: Get rid of input_ff_destroy() in error paths
      HID: haptic: Fix use-after-free when draining workqueue
      HID: haptic, multitouch: Check haptic prerequisite properly
      HID: haptic: Postpone GET_REPORT to init
      HID: Add hid-plugin framework for loadable plugin modules
      HID: haptic: Convert to a loadable plugin module
      HID: haptic: Adopt pr_fmt, dev_fmt and hid_*() printk helpers
      HID: Add Ordinal page defines
      HID: haptic: Handle list reports separately and make auto trigger optional
      HID: haptic: Decouple from hid-multitouch and support other devices
      HID: haptic: Add quirk table
      HID: haptic: Add HID_HAPTIC_QUIRK_NO_RETRIGGER to disable retriggering
      HID: haptic: Add quirk flag for Logitech MX Master 4

 MAINTAINERS                  |   7 +
 drivers/hid/Kconfig          |  34 +++-
 drivers/hid/Makefile         |   4 +-
 drivers/hid/hid-core.c       |   6 +
 drivers/hid/hid-haptic.c     | 458 +++++++++++++++++++++++++++++--------------
 drivers/hid/hid-haptic.h     | 181 +++++++++++------
 drivers/hid/hid-input.c      |  40 +++-
 drivers/hid/hid-multitouch.c |  41 +---
 drivers/hid/hid-plugin.c     | 304 ++++++++++++++++++++++++++++
 drivers/hid/hid-plugin.h     | 257 ++++++++++++++++++++++++
 include/linux/hid.h          |  25 +++
 11 files changed, 1105 insertions(+), 252 deletions(-)
---
base-commit: 47d0d5ce3cfca63a04eabcbeef7086d06240ff97
change-id: 9644469a-hid-haptic-kmod-4e8e420f8e5f

Thanks,
Rong


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-12-02 19:08 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:33 [PATCH v6 00/13] HID: Add hid-plugin framework & convert hid-haptic into a generic plugin Rong Zhang
2026-12-02 18:33 ` [PATCH v6 01/13] HID: haptic: Get rid of input_ff_destroy() in error paths Rong Zhang
2026-12-02 18:33 ` [PATCH v6 02/13] HID: haptic: Fix use-after-free when draining workqueue Rong Zhang
2026-12-02 18:33 ` [PATCH v6 03/13] HID: haptic, multitouch: Check haptic prerequisite properly Rong Zhang
2026-12-02 18:33 ` [PATCH v6 04/13] HID: haptic: Postpone GET_REPORT to init Rong Zhang
2026-12-02 18:33 ` [PATCH v6 05/13] HID: Add hid-plugin framework for loadable plugin modules Rong Zhang
2026-12-02 18:33 ` [PATCH v6 06/13] HID: haptic: Convert to a loadable plugin module Rong Zhang
2026-12-02 19:07   ` sashiko-bot
2026-12-02 18:33 ` [PATCH v6 07/13] HID: haptic: Adopt pr_fmt, dev_fmt and hid_*() printk helpers Rong Zhang
2026-12-02 18:33 ` [PATCH v6 08/13] HID: Add Ordinal page defines Rong Zhang
2026-12-02 18:33 ` [PATCH v6 09/13] HID: haptic: Handle list reports separately and make auto trigger optional Rong Zhang
2026-12-02 18:33 ` [PATCH v6 10/13] HID: haptic: Decouple from hid-multitouch and support other devices Rong Zhang
2026-12-02 19:08   ` sashiko-bot
2026-12-02 18:33 ` [PATCH v6 11/13] HID: haptic: Add quirk table Rong Zhang
2026-12-02 18:33 ` [PATCH v6 12/13] HID: haptic: Add HID_HAPTIC_QUIRK_NO_RETRIGGER to disable retriggering Rong Zhang
2026-12-02 18:33 ` [PATCH v6 13/13] HID: haptic: Add quirk flag for Logitech MX Master 4 Rong Zhang

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