From: Rong Zhang <i@rong.moe>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Angela Czubak <aczubak@google.com>,
Henrik Rydberg <rydberg@bitmath.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Rong Zhang <i@rong.moe>
Subject: [PATCH v3 8/9] HID: haptic: Convert into a loadable plugin module
Date: Fri, 13 Nov 2026 01:54:01 +0800 [thread overview]
Message-ID: <20261113-hid-haptic-kmod-v3-8-e7dfa8766c0d@rong.moe> (raw)
In-Reply-To: <20261113-hid-haptic-kmod-v3-0-e7dfa8766c0d@rong.moe>
Commit 083a4f3f3cc7 ("HID: Kconfig: Fix build error from
CONFIG_HID_HAPTIC") built hid-haptic into vmlinux or hid.ko. This is not
optimal for generic kernel images, as a platform with no multitouch
device doesn't need it anyway. It's also a bit harsh for enabling it in
distribution kernels.
With the new hid-plugin framework, hid-haptic can be easily converted
into a loadable plugin module, so that hid-multitouch only requests it
on demand.
The redaundent `default n' statement is also removed for tidiness since
we are anyway touching its context.
Suggested-by: Benjamin Tissoires <bentiss@kernel.org>
Link: https://lore.kernel.org/linux-input/auypydfkhx2eg7vp764way4batdilzc35inqda3exwzs3tk3ff@oagat6g46zto/
Signed-off-by: Rong Zhang <i@rong.moe>
---
MAINTAINERS | 1 +
drivers/hid/Kconfig | 7 +++++--
drivers/hid/Makefile | 2 +-
drivers/hid/hid-haptic.c | 28 ++++++++++++++++++----------
drivers/hid/hid-haptic.h | 29 +++++++++++++++++++++++++++--
drivers/hid/hid-plugin.c | 3 +++
drivers/hid/hid-plugin.h | 6 ++++++
7 files changed, 61 insertions(+), 15 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 06c82b4a7614..b772148c031c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11909,6 +11909,7 @@ HID PLUGINS
M: Rong Zhang <i@rong.moe>
L: linux-input@vger.kernel.org
S: Maintained
+F: drivers/hid/hid-haptic.*
F: drivers/hid/hid-plugin.*
HID PULSAR DRIVER
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 604683b4a4a9..97cb4caf9d7e 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -106,9 +106,10 @@ menuconfig HID_PLUGIN
If unsure, say N.
+if HID_PLUGIN
+
config HID_HAPTIC
- bool "Haptic touchpad support"
- default n
+ tristate "Haptic touchpad support"
help
Support for touchpads with force sensors and haptic actuators instead of a
traditional button.
@@ -117,6 +118,8 @@ config HID_HAPTIC
If unsure, say N.
+endif # HID_PLUGIN
+
menu "Special HID drivers"
config HID_A4TECH
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index b41aa3f52a94..3360347c1cb8 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -6,7 +6,7 @@ hid-y := hid-core.o hid-input.o hid-quirks.o
hid-$(CONFIG_DEBUG_FS) += hid-debug.o
hid-$(CONFIG_HID_PLUGIN) += hid-plugin.o
-hid-$(CONFIG_HID_HAPTIC) += hid-haptic.o
+obj-$(CONFIG_HID_HAPTIC) += hid-haptic.o
obj-$(CONFIG_HID_BPF) += bpf/
diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
index a6f3ec514504..0e9708d1f3a9 100644
--- a/drivers/hid/hid-haptic.c
+++ b/drivers/hid/hid-haptic.c
@@ -315,12 +315,11 @@ static void hid_haptic_destroy(struct ff_device *ff)
if (hdev)
put_device(&hdev->dev);
- module_put(THIS_MODULE);
+ hid_plugin_put(HID_PLUGIN_HAPTIC, &haptic->self_plugin->hp);
}
-int hid_haptic_init(struct hid_device *hdev,
- struct hid_haptic_device *haptic,
- struct input_dev *dev)
+static int __hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct input_dev *dev)
{
struct ff_device *ff;
int ret = 0, r;
@@ -328,10 +327,6 @@ int hid_haptic_init(struct hid_device *hdev,
.hid_usage = HID_HP_WAVEFORMSTOP & HID_USAGE,
};
- if (!try_module_get(THIS_MODULE)) {
- dev_err(&hdev->dev, "Failed to increase module count.\n");
- return -ENXIO;
- }
if (!get_device(&hdev->dev)) {
dev_err(&hdev->dev, "Failed to get hdev device.\n");
ret = -ENXIO;
@@ -454,7 +449,20 @@ int hid_haptic_init(struct hid_device *hdev,
put_device(&hdev->dev);
exit:
dev_warn(&hdev->dev, "Cannot allocate haptic for %s: %d\n", hdev->name, ret);
- module_put(THIS_MODULE);
+ hid_plugin_put(HID_PLUGIN_HAPTIC, &haptic->self_plugin->hp);
return ret;
}
-EXPORT_SYMBOL_GPL(hid_haptic_init);
+
+static struct hid_plugin_haptic hid_plugin_haptic = {
+ .hp = {
+ .owner = THIS_MODULE,
+ },
+ .init = __hid_haptic_init,
+};
+module_hid_plugin(haptic, HID_PLUGIN_HAPTIC, &hid_plugin_haptic.hp);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Angela Czubak <aczubak@google.com>");
+MODULE_AUTHOR("Jonathan Denose <jdenose@google.com>");
+MODULE_AUTHOR("Rong Zhang <i@rong.moe>");
+MODULE_DESCRIPTION("HID helpers for Haptics Page");
diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
index 6196041eb4f8..a71ccee569f3 100644
--- a/drivers/hid/hid-haptic.h
+++ b/drivers/hid/hid-haptic.h
@@ -5,9 +5,12 @@
* Copyright (c) 2021 Angela Czubak <acz@semihalf.com>
*/
+#include <linux/container_of.h>
#include <linux/err.h>
#include <linux/hid.h>
+#include "hid-plugin.h"
+
#define HID_HAPTIC_ORDINAL_WAVEFORMNONE 1
#define HID_HAPTIC_ORDINAL_WAVEFORMSTOP 2
@@ -52,6 +55,14 @@ struct hid_haptic_device {
u16 release_ordinal;
struct hid_haptic_effect *effect;
struct hid_haptic_effect stop_effect;
+
+ struct hid_plugin_haptic *self_plugin;
+};
+
+struct hid_plugin_haptic {
+ struct hid_plugin hp;
+ int (*init)(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct input_dev *dev);
};
#if IS_ENABLED(CONFIG_HID_HAPTIC)
@@ -152,8 +163,22 @@ static inline int hid_haptic_input_mapping(struct hid_device *hdev,
return 0;
}
-int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
- struct input_dev *dev);
+static inline int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct input_dev *dev)
+{
+ struct hid_plugin_haptic *self_plugin;
+ struct hid_plugin *plugin;
+
+ plugin = hid_plugin_get(HID_PLUGIN_HAPTIC);
+ if (IS_ERR(plugin))
+ return PTR_ERR(plugin);
+
+ self_plugin = container_of(plugin, struct hid_plugin_haptic, hp);
+
+ haptic->self_plugin = self_plugin;
+
+ return self_plugin->init(hdev, haptic, dev);
+}
static inline bool hid_haptic_input_configured(struct hid_device *hdev,
struct hid_haptic_device *haptic,
diff --git a/drivers/hid/hid-plugin.c b/drivers/hid/hid-plugin.c
index a83275df038c..7357f81c3aac 100644
--- a/drivers/hid/hid-plugin.c
+++ b/drivers/hid/hid-plugin.c
@@ -18,6 +18,9 @@
#include "hid-plugin.h"
static const char * const hid_plugin_mod_names[NR_HID_PLUGINS] = {
+#if IS_MODULE(CONFIG_HID_HAPTIC)
+ [HID_PLUGIN_HAPTIC] = "hid-haptic",
+#endif
};
static struct hid_plugin __rcu *hid_plugins[NR_HID_PLUGINS];
diff --git a/drivers/hid/hid-plugin.h b/drivers/hid/hid-plugin.h
index e7bc98639d9f..e2e157b23b69 100644
--- a/drivers/hid/hid-plugin.h
+++ b/drivers/hid/hid-plugin.h
@@ -19,6 +19,12 @@
enum hid_plugin_id {
HID_PLUGIN_DISABLED = -1,
+#if IS_ENABLED(CONFIG_HID_HAPTIC)
+ HID_PLUGIN_HAPTIC,
+#else
+#define HID_PLUGIN_HAPTIC HID_PLUGIN_DISABLED
+#endif
+
NR_HID_PLUGINS,
};
--
2.55.0
next prev parent reply other threads:[~2026-11-12 17:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 17:53 [PATCH v3 0/9] HID: Add hid-plugin framework & convert haptic into a plugin Rong Zhang
2026-11-12 17:53 ` [PATCH v3 1/9] HID: haptic: Fix use-after-free when draining workqueue Rong Zhang
2026-11-12 17:53 ` [PATCH v3 2/9] HID: haptic: Get rid of input_ff_destroy() in error paths Rong Zhang
2026-11-13 5:50 ` Dmitry Torokhov
2026-11-12 17:53 ` [PATCH v3 3/9] HID: haptic, multitouch: Check haptic prerequisite properly Rong Zhang
2026-11-12 17:53 ` [PATCH v3 4/9] HID: haptic, multitouch: Fix haptic device double-free and unnecessary allocation Rong Zhang
2026-11-12 17:53 ` [PATCH v3 5/9] HID: haptic: Postpone GET_REPORT to init Rong Zhang
2026-11-12 17:53 ` [PATCH v3 6/9] HID: haptic: Convert simple methods into static inline ones Rong Zhang
2026-11-12 17:54 ` [PATCH v3 7/9] HID: Add hid-plugin framework for loadable plugin modules Rong Zhang
2026-11-12 17:54 ` Rong Zhang [this message]
2026-11-12 17:54 ` [PATCH v3 9/9] HID: haptic: Remove stubs in favor of inlined dead code elimination Rong Zhang
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=20261113-hid-haptic-kmod-v3-8-e7dfa8766c0d@rong.moe \
--to=i@rong.moe \
--cc=aczubak@google.com \
--cc=bentiss@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rydberg@bitmath.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®