[PATCH v5 13/13] iio: pressure: hid-sensor-press: convert probe and teardown to devm-managed resources
From: Sanjay Chitroda via B4 Relay
Date: Thu Aug 06 2026 - 08:32:34 EST
From: Sanjay Chitroda <sanjayembeddedse@xxxxxxxxx>
Convert HID IIO driver resource management to use devm-managed helpers,
tying the lifetime of all resources to the device.
HID trigger setup, IIO registration, and sensor hub callback resource
are now managed using devm APIs. Cleanup logic previously handled
explicitly in probe error and teardown paths.
This simplifies the probe path by removing goto-based error handling,
eliminates the remove callback entirely.
Signed-off-by: Sanjay Chitroda <sanjayembeddedse@xxxxxxxxx>
---
drivers/iio/pressure/hid-sensor-press.c | 41 ++++++++-------------------------
1 file changed, 9 insertions(+), 32 deletions(-)
diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index 4e0f42fefd6b..8ebb8f54a0cb 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -230,7 +230,8 @@ static int press_parse_report(struct platform_device *pdev,
/* Function to initialize the processing for usage id */
static int hid_press_probe(struct platform_device *pdev)
{
- struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
+ struct device *dev = &pdev->dev;
+ struct hid_sensor_hub_device *hsdev = dev_get_platdata(dev);
int ret = 0;
static const char *name = "press";
struct iio_dev *indio_dev;
@@ -278,8 +279,8 @@ static int hid_press_probe(struct platform_device *pdev)
atomic_set(&press_state->common_attributes.data_ready, 0);
- ret = hid_sensor_setup_trigger(indio_dev, name,
- &press_state->common_attributes);
+ ret = devm_hid_sensor_setup_trigger(dev, indio_dev, name,
+ &press_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "trigger setup failed\n");
return ret;
@@ -288,38 +289,15 @@ static int hid_press_probe(struct platform_device *pdev)
press_state->callbacks.send_event = press_proc_event;
press_state->callbacks.capture_sample = press_capture_sample;
press_state->callbacks.pdev = pdev;
- ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_PRESSURE,
- &press_state->callbacks);
+ ret = devm_sensor_hub_register_callback(dev, hsdev,
+ HID_USAGE_SENSOR_PRESSURE,
+ &press_state->callbacks);
if (ret < 0) {
dev_err(&pdev->dev, "callback reg failed\n");
- goto error_remove_trigger;
- }
-
- ret = iio_device_register(indio_dev);
- if (ret) {
- dev_err(&pdev->dev, "device register failed\n");
- goto error_remove_callback;
+ return ret;
}
- return ret;
-
-error_remove_callback:
- sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PRESSURE);
-error_remove_trigger:
- hid_sensor_remove_trigger(&press_state->common_attributes);
- return ret;
-}
-
-/* Function to deinitialize the processing for usage id */
-static void hid_press_remove(struct platform_device *pdev)
-{
- struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
- struct iio_dev *indio_dev = platform_get_drvdata(pdev);
- struct press_state *press_state = iio_priv(indio_dev);
-
- iio_device_unregister(indio_dev);
- sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PRESSURE);
- hid_sensor_remove_trigger(&press_state->common_attributes);
+ return devm_iio_device_register(dev, indio_dev);
}
static const struct platform_device_id hid_press_ids[] = {
@@ -338,7 +316,6 @@ static struct platform_driver hid_press_platform_driver = {
.pm = &hid_sensor_pm_ops,
},
.probe = hid_press_probe,
- .remove = hid_press_remove,
};
module_platform_driver(hid_press_platform_driver);
--
2.34.1