[PATCH v3 3/7] HID: sensor: custom: Disable sensor before hub close on removal

From: Srinivas Pandruvada

Date: Mon Nov 09 2026 - 15:06:03 EST


When removing an enabled sensor, set its power and reporting states to
off before closing the hub. Keep the field descriptors alive until the
state update has completed, and release the hub's open reference.

Fixes: 4a7de0519df5 ("HID: sensor: Custom and Generic sensor support")
Reported-by: Semyon Maryasin <simeon@xxxxxxxxxxxxx>
Closes: https://lore.kernel.org/all/CAM2dg7ewfVJSP4rFyhkCB1Rmd1+X56sAg=eUdbPthG2xrLqwQQ@xxxxxxxxxxxxxx/
Reviewed-by: Joshua Crofts <crofts@xxxxxxxxxx>
Tested-by: Semyon Maryasin <simeon@xxxxxxxxxxxxx>
Tested-by: Zhang Lixu <lixu.zhang@xxxxxxxxx>
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>
---
drivers/hid/hid-sensor-custom.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
index 3a65da64fd2a..ec7734e8e4a6 100644
--- a/drivers/hid/hid-sensor-custom.c
+++ b/drivers/hid/hid-sensor-custom.c
@@ -1052,6 +1052,13 @@ static void hid_sensor_custom_remove(struct platform_device *pdev)
/* Remove enable_sensor first as it uses fields via power_state/report_state. */
sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
&enable_sensor_attr_group);
+ mutex_lock(&sensor_inst->mutex);
+ if (sensor_inst->enable) {
+ set_power_report_state(sensor_inst, false);
+ sensor_hub_device_close(hsdev);
+ sensor_inst->enable = false;
+ }
+ mutex_unlock(&sensor_inst->mutex);
hid_sensor_custom_remove_attributes(sensor_inst);
sensor_hub_remove_callback(hsdev, hsdev->usage);
}
--
2.56.0