iio: magn: st_magn: use devm_iio_triggered_buffer_setup() for buffer
authorAlexandru Ardelean <aardelean@deviqon.com>
Tue, 20 Jul 2021 07:46:41 +0000 (10:46 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 24 Jul 2021 15:35:05 +0000 (16:35 +0100)
The st_magn_allocate_ring() function calls iio_triggered_buffer_setup() to
allocate a triggered buffer.

But the same can be done with devm_iio_triggered_buffer_setup() and then
the st_magn_common_remove() no longer needs to manually deallocate it.

We know that the parent of the IIO device is used to manage other instances
of the devm unwind, so it can be used in the st_magn_allocate_ring() as
well.

This change also removes some omitted st_magn_{probe,remove}_trigger()
inline hooks.

Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210720074642.223293-3-aardelean@deviqon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/magnetometer/st_magn.h
drivers/iio/magnetometer/st_magn_buffer.c
drivers/iio/magnetometer/st_magn_core.c

index fb6c906..785b7f7 100644 (file)
 
 #ifdef CONFIG_IIO_BUFFER
 int st_magn_allocate_ring(struct iio_dev *indio_dev);
-void st_magn_deallocate_ring(struct iio_dev *indio_dev);
 int st_magn_trig_set_state(struct iio_trigger *trig, bool state);
 #define ST_MAGN_TRIGGER_SET_STATE (&st_magn_trig_set_state)
 #else /* CONFIG_IIO_BUFFER */
-static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq)
-{
-       return 0;
-}
-static inline void st_magn_remove_trigger(struct iio_dev *indio_dev, int irq)
-{
-       return;
-}
 static inline int st_magn_allocate_ring(struct iio_dev *indio_dev)
 {
        return 0;
 }
-static inline void st_magn_deallocate_ring(struct iio_dev *indio_dev)
-{
-}
 #define ST_MAGN_TRIGGER_SET_STATE NULL
 #endif /* CONFIG_IIO_BUFFER */
 
index 68f0171..cb43ccd 100644 (file)
@@ -41,13 +41,8 @@ static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
 
 int st_magn_allocate_ring(struct iio_dev *indio_dev)
 {
-       return iio_triggered_buffer_setup(indio_dev, NULL,
-               &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
-}
-
-void st_magn_deallocate_ring(struct iio_dev *indio_dev)
-{
-       iio_triggered_buffer_cleanup(indio_dev);
+       return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev,
+               NULL, &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
 }
 
 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
index 2c44a92..9ffd50d 100644 (file)
@@ -647,7 +647,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
                err = st_sensors_allocate_trigger(indio_dev,
                                                ST_MAGN_TRIGGER_OPS);
                if (err < 0)
-                       goto st_magn_probe_trigger_error;
+                       return err;
        }
 
        err = iio_device_register(indio_dev);
@@ -662,8 +662,6 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
 st_magn_device_register_error:
        if (mdata->irq > 0)
                st_sensors_deallocate_trigger(indio_dev);
-st_magn_probe_trigger_error:
-       st_magn_deallocate_ring(indio_dev);
        return err;
 }
 EXPORT_SYMBOL(st_magn_common_probe);
@@ -675,8 +673,6 @@ void st_magn_common_remove(struct iio_dev *indio_dev)
        iio_device_unregister(indio_dev);
        if (mdata->irq > 0)
                st_sensors_deallocate_trigger(indio_dev);
-
-       st_magn_deallocate_ring(indio_dev);
 }
 EXPORT_SYMBOL(st_magn_common_remove);