[PATCH 9/9] HID: haptic: Remove stubs in favor of inlined dead code elimination

From: Rong Zhang

Date: Sun Nov 01 2026 - 12:43:11 EST


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@xxxxxxxx>
---
drivers/hid/hid-haptic.h | 74 ++++++++++++++++++------------------------------
1 file changed, 28 insertions(+), 46 deletions(-)

diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
index d3e8fb9aa3b4..165427f878b0 100644
--- a/drivers/hid/hid-haptic.h
+++ b/drivers/hid/hid-haptic.h
@@ -66,12 +66,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, gfp_t gfp)
{
struct hid_haptic_device *haptic;

+ if (!hid_haptic_enabled())
+ return ERR_PTR(-EOPNOTSUPP);
+
haptic = kzalloc_obj(struct hid_haptic_device, gfp);
if (haptic)
haptic->hdev = hdev;
@@ -85,6 +91,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");
@@ -112,6 +121,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;

@@ -150,6 +162,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 */
@@ -164,6 +179,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);
@@ -179,6 +197,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;
@@ -190,56 +211,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, gfp_t gfp)
-{
- return ERR_PTR(-EOPNOTSUPP);
-}
+ 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