[PATCH v5 11/13] iio: orientation: hid-sensor-rotation: convert probe and teardown to devm-managed resources
Sanjay Chitroda via B4 Relay <[email protected]> Thu, 06 Aug 2026 17:55:57 +0530
| Newsgroups | org.kernel.vger.linux-input,org.kernel.feeds.b4-sent,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <20260806-28-apr-iio-redundant-argument-v5-temp-v5-11-f1f92c1d830f@gmail.com> |
From: Sanjay Chitroda <[email protected]> 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 <[email protected]> --- drivers/iio/orientation/hid-sensor-rotation.c | 40 ++++++--------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c index 67ffa4f4075e..3ef89d66a88f 100644 --- a/drivers/iio/orientation/hid-sensor-rotation.c +++ b/drivers/iio/orientation/hid-sensor-rotation.c @@ -265,7 +265,8 @@ static int dev_rot_parse_report(struct platform_device *pdev, /* Function to initialize the processing for usage id */ static int hid_dev_rot_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; char *name; struct iio_dev *indio_dev; @@ -320,8 +321,8 @@ static int hid_dev_rot_probe(struct platform_device *pdev) atomic_set(&rot_state->common_attributes.data_ready, 0); - ret = hid_sensor_setup_trigger(indio_dev, name, - &rot_state->common_attributes); + ret = devm_hid_sensor_setup_trigger(dev, indio_dev, name, + &rot_state->common_attributes); if (ret) { dev_err(&pdev->dev, "trigger setup failed\n"); return ret; @@ -330,38 +331,14 @@ static int hid_dev_rot_probe(struct platform_device *pdev) rot_state->callbacks.send_event = dev_rot_proc_event; rot_state->callbacks.capture_sample = dev_rot_capture_sample; rot_state->callbacks.pdev = pdev; - ret = sensor_hub_register_callback(hsdev, hsdev->usage, - &rot_state->callbacks); + ret = devm_sensor_hub_register_callback(dev, hsdev, hsdev->usage, + &rot_state->callbacks); if (ret) { 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 0; - -error_remove_callback: - sensor_hub_remove_callback(hsdev, hsdev->usage); -error_remove_trigger: - hid_sensor_remove_trigger(&rot_state->common_attributes); - return ret; -} - -/* Function to deinitialize the processing for usage id */ -static void hid_dev_rot_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 dev_rot_state *rot_state = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - sensor_hub_remove_callback(hsdev, hsdev->usage); - hid_sensor_remove_trigger(&rot_state->common_attributes); + return devm_iio_device_register(dev, indio_dev); } static const struct platform_device_id hid_dev_rot_ids[] = { @@ -388,7 +365,6 @@ static struct platform_driver hid_dev_rot_platform_driver = { .pm = &hid_sensor_pm_ops, }, .probe = hid_dev_rot_probe, - .remove = hid_dev_rot_remove, }; module_platform_driver(hid_dev_rot_platform_driver); -- 2.34.1