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 9/9] HID: haptic: Remove stubs in favor of inlined dead code elimination
Date: Fri, 13 Nov 2026 01:54:02 +0800 [thread overview]
Message-ID: <20261113-hid-haptic-kmod-v3-9-e7dfa8766c0d@rong.moe> (raw)
In-Reply-To: <20261113-hid-haptic-kmod-v3-0-e7dfa8766c0d@rong.moe>
All stubs in hid-haptic.h can be replaced by equivalent
!hid_plugin_enabled(HID_PLUGIN_HAPTIC) checks. The compiler will
eliminate calls to all methods when the plugin is disabled.
Signed-off-by: Rong Zhang <i@rong.moe>
---
Changes in v3:
- Fix the return value of hid_haptic_connected_to_input() when
hid-haptic is disabled (thanks Sashiko)
---
drivers/hid/hid-haptic.h | 83 +++++++++++++++++++-----------------------------
1 file changed, 32 insertions(+), 51 deletions(-)
diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
index a71ccee569f3..8b18b06afa10 100644
--- a/drivers/hid/hid-haptic.h
+++ b/drivers/hid/hid-haptic.h
@@ -65,11 +65,18 @@ struct hid_plugin_haptic {
struct input_dev *dev);
};
-#if IS_ENABLED(CONFIG_HID_HAPTIC)
+static inline bool hid_haptic_enabled(void)
+{
+ return hid_plugin_enabled(HID_PLUGIN_HAPTIC);
+}
+
static inline struct hid_haptic_device *hid_haptic_alloc(struct hid_device *hdev)
{
struct hid_haptic_device *haptic;
+ if (!hid_haptic_enabled())
+ return ERR_PTR(-EOPNOTSUPP);
+
haptic = kzalloc_obj(struct hid_haptic_device);
if (haptic)
haptic->hdev = hdev;
@@ -80,6 +87,9 @@ static inline struct hid_haptic_device *hid_haptic_alloc(struct hid_device *hdev
static inline bool hid_haptic_connected_to_input(struct hid_haptic_device *haptic,
struct input_dev *input)
{
+ if (!hid_haptic_enabled())
+ return false;
+
return haptic->input_dev == input;
}
@@ -89,6 +99,9 @@ static inline void hid_haptic_feature_mapping(struct hid_device *hdev,
{
u16 usage_hid;
+ if (!hid_haptic_enabled())
+ return;
+
if (usage->hid == HID_HP_AUTOTRIGGER) {
if (usage->usage_index >= field->report_count) {
dev_err(&hdev->dev, "HID_HP_AUTOTRIGGER out of range\n");
@@ -116,6 +129,9 @@ static inline void hid_haptic_feature_mapping(struct hid_device *hdev,
static inline void hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
struct hid_input *hi, struct hid_field *field)
{
+ if (!hid_haptic_enabled())
+ return;
+
if (hi->application != HID_DG_TOUCHPAD)
return;
@@ -155,6 +171,9 @@ static inline int hid_haptic_input_mapping(struct hid_device *hdev,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
{
+ if (!hid_haptic_enabled())
+ return 0;
+
if (usage->hid == HID_HP_MANUALTRIGGER) {
haptic->manual_trigger_report = field->report;
/* we don't really want to map these fields */
@@ -169,6 +188,9 @@ static inline int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_dev
struct hid_plugin_haptic *self_plugin;
struct hid_plugin *plugin;
+ if (!hid_haptic_enabled())
+ return 0;
+
plugin = hid_plugin_get(HID_PLUGIN_HAPTIC);
if (IS_ERR(plugin))
return PTR_ERR(plugin);
@@ -184,6 +206,9 @@ static inline bool hid_haptic_input_configured(struct hid_device *hdev,
struct hid_haptic_device *haptic,
struct hid_input *hi)
{
+ if (!hid_haptic_enabled())
+ return false;
+
if (IS_ERR_OR_NULL(haptic->input_dev) || haptic->input_dev != hi->input ||
!haptic->auto_trigger_report || !haptic->manual_trigger_report)
return false;
@@ -195,61 +220,17 @@ static inline bool hid_haptic_input_configured(struct hid_device *hdev,
static inline void hid_haptic_pressure_reset(struct hid_haptic_device *haptic)
{
+ if (!hid_haptic_enabled())
+ return;
+
haptic->pressure_sum = 0;
}
static inline void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
__s32 pressure)
{
- haptic->pressure_sum += pressure;
-}
-#else
-static inline struct hid_haptic_device *hid_haptic_alloc(struct hid_device *hdev)
-{
- return ERR_PTR(-EOPNOTSUPP);
-}
-
-static inline bool hid_haptic_connected_to_input(struct hid_haptic_device *haptic,
- struct input_dev *input)
-{
- return false;
-}
+ if (!hid_haptic_enabled())
+ return;
-static inline
-void hid_haptic_feature_mapping(struct hid_device *hdev,
- struct hid_haptic_device *haptic,
- struct hid_field *field, struct hid_usage
- *usage)
-{}
-static inline
-void hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
- struct hid_input *hi, struct hid_field *field)
-{}
-static inline
-int hid_haptic_input_mapping(struct hid_device *hdev,
- struct hid_haptic_device *haptic,
- struct hid_input *hi,
- struct hid_field *field, struct hid_usage *usage,
- unsigned long **bit, int *max)
-{
- return 0;
-}
-static inline
-bool hid_haptic_input_configured(struct hid_device *hdev,
- struct hid_haptic_device *haptic, struct hid_input *hi)
-{
- return false;
-}
-static inline
-int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
- struct input_dev *dev)
-{
- return 0;
+ haptic->pressure_sum += pressure;
}
-static inline
-void hid_haptic_pressure_reset(struct hid_haptic_device *haptic) {}
-static inline
-void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
- __s32 pressure)
-{}
-#endif
--
2.55.0
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 ` [PATCH v3 8/9] HID: haptic: Convert into a loadable plugin module Rong Zhang
2026-11-12 17:54 ` Rong Zhang [this message]
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-9-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®