[PATCH v2 9/9] HID: haptic: Remove stubs in favor of inlined dead code elimination
From: Rong Zhang
Date: Mon Nov 09 2026 - 14:56:38 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 | 83 +++++++++++++++++++-----------------------------
1 file changed, 32 insertions(+), 51 deletions(-)
diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
index a71ccee569f3..070b56189ccb 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 ERR_PTR(-EOPNOTSUPP);
+
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