iio: pressure: st_pressure: use devm_iio_triggered_buffer_setup() for buffer
PATCH 1/4 iio: pressure: st_pressure: use devm_iio_triggered_buffer_setup() for buffer
The st_press_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_press_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_press_allocate_ring() as well.
--- drivers/iio/pressure/st_pressure.h | 5 ----- drivers/iio/pressure/st_pressure_buffer.c | 9 ++------- drivers/iio/pressure/st_pressure_core.c | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-)
drivers/iio/pressure/st_pressure.h +0 -5
@@ -43,7 +43,6 @@ static __maybe_unused const struct st_sensors_platform_data default_press_pdata#ifdef CONFIG_IIO_BUFFER int st_press_allocate_ring (struct iio_dev *indio_dev); -void st_press_deallocate_ring (struct iio_dev *indio_dev);int st_press_trig_set_state (struct iio_trigger *trig,bool state);#define ST_PRESS_TRIGGER_SET_STATE (&st_press_trig_set_state)#else /* CONFIG_IIO_BUFFER */
@@ -51,10 +50,6 @@ static inline int st_press_allocate_ring(struct iio_dev *indio_dev) {return 0 ; } - -static inline void st_press_deallocate_ring (struct iio_dev *indio_dev) -{ -}#define ST_PRESS_TRIGGER_SET_STATE NULL#endif /* CONFIG_IIO_BUFFER */
drivers/iio/pressure/st_pressure_buffer.c +2 -7
@@ -41,13 +41,8 @@ static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {int st_press_allocate_ring (struct iio_dev *indio_dev) { -return iio_triggered_buffer_setup (indio_dev,NULL , - &st_sensors_trigger_handler, &st_press_buffer_setup_ops); -} - -void st_press_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_press_buffer_setup_ops); }MODULE_AUTHOR ("Denis Ciocca <[email protected]>" );
drivers/iio/pressure/st_pressure_core.c +1 -5
@@ -718,7 +718,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) err =st_sensors_allocate_trigger (indio_dev,ST_PRESS_TRIGGER_OPS );if (err <0 ) - goto st_press_probe_trigger_error; +return err; } err =iio_device_register (indio_dev);
@@ -733,8 +733,6 @@ int st_press_common_probe(struct iio_dev *indio_dev) st_press_device_register_error:if (press_data->irq >0 )st_sensors_deallocate_trigger (indio_dev); -st_press_probe_trigger_error: -st_press_deallocate_ring (indio_dev);return err; }EXPORT_SYMBOL (st_press_common_probe);
@@ -746,8 +744,6 @@ void st_press_common_remove(struct iio_dev *indio_dev)iio_device_unregister (indio_dev);if (press_data->irq >0 )st_sensors_deallocate_trigger (indio_dev); - -st_press_deallocate_ring (indio_dev); }EXPORT_SYMBOL (st_press_common_remove);
Signature · 1 line
2.31.1
PATCH 2/4 iio: accel: st_accel: use devm_iio_triggered_buffer_setup() for buffer
The st_accel_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_accel_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_accel_allocate_ring() as well.
--- drivers/iio/accel/st_accel.h | 4 ---- drivers/iio/accel/st_accel_buffer.c | 9 ++------- drivers/iio/accel/st_accel_core.c | 6 +----- 3 files changed, 3 insertions(+), 16 deletions(-)
drivers/iio/accel/st_accel.h +0 -4
@@ -64,7 +64,6 @@ enum st_accel_type {#ifdef CONFIG_IIO_BUFFER int st_accel_allocate_ring (struct iio_dev *indio_dev); -void st_accel_deallocate_ring (struct iio_dev *indio_dev);int st_accel_trig_set_state (struct iio_trigger *trig,bool state);#define ST_ACCEL_TRIGGER_SET_STATE (&st_accel_trig_set_state)#else /* CONFIG_IIO_BUFFER */
@@ -72,9 +71,6 @@ static inline int st_accel_allocate_ring(struct iio_dev *indio_dev) {return 0 ; } -static inline void st_accel_deallocate_ring (struct iio_dev *indio_dev) -{ -}#define ST_ACCEL_TRIGGER_SET_STATE NULL#endif /* CONFIG_IIO_BUFFER */
drivers/iio/accel/st_accel_buffer.c +2 -7
@@ -62,13 +62,8 @@ static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {int st_accel_allocate_ring (struct iio_dev *indio_dev) { -return iio_triggered_buffer_setup (indio_dev,NULL , - &st_sensors_trigger_handler, &st_accel_buffer_setup_ops); -} - -void st_accel_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_accel_buffer_setup_ops); }MODULE_AUTHOR ("Denis Ciocca <[email protected]>" );
drivers/iio/accel/st_accel_core.c +1 -5
@@ -1377,7 +1377,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) err =st_sensors_allocate_trigger (indio_dev,ST_ACCEL_TRIGGER_OPS );if (err <0 ) - goto st_accel_probe_trigger_error; +return err; } err =iio_device_register (indio_dev);
@@ -1392,8 +1392,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev) st_accel_device_register_error:if (adata->irq >0 )st_sensors_deallocate_trigger (indio_dev); -st_accel_probe_trigger_error: -st_accel_deallocate_ring (indio_dev);return err; }EXPORT_SYMBOL (st_accel_common_probe);
@@ -1405,8 +1403,6 @@ void st_accel_common_remove(struct iio_dev *indio_dev)iio_device_unregister (indio_dev);if (adata->irq >0 )st_sensors_deallocate_trigger (indio_dev); - -st_accel_deallocate_ring (indio_dev); }EXPORT_SYMBOL (st_accel_common_remove);
Signature · 1 line
2.31.1
PATCH 3/4 iio: magn: st_magn: use devm_iio_triggered_buffer_setup() for buffer
In reply to Alexandru ArdeleanThe 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.
--- drivers/iio/magnetometer/st_magn.h | 12 ------------ drivers/iio/magnetometer/st_magn_buffer.c | 9 ++------- drivers/iio/magnetometer/st_magn_core.c | 6 +----- 3 files changed, 3 insertions(+), 24 deletions(-)
drivers/iio/magnetometer/st_magn.h +0 -12
@@ -25,25 +25,13 @@#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 */
drivers/iio/magnetometer/st_magn_buffer.c +2 -7
@@ -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 <[email protected]>" );
drivers/iio/magnetometer/st_magn_core.c +1 -5
@@ -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);
Signature · 1 line
2.31.1
PATCH 4/4 iio: gyro: st_gyro: use devm_iio_triggered_buffer_setup() for buffer
In reply to Alexandru ArdeleanThe st_gyro_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_gyro_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_gyro_allocate_ring() as well.
--- drivers/iio/gyro/st_gyro.h | 4 ---- drivers/iio/gyro/st_gyro_buffer.c | 9 ++------- drivers/iio/gyro/st_gyro_core.c | 6 +----- 3 files changed, 3 insertions(+), 16 deletions(-)
drivers/iio/gyro/st_gyro.h +0 -4
@@ -26,7 +26,6 @@#ifdef CONFIG_IIO_BUFFER int st_gyro_allocate_ring (struct iio_dev *indio_dev); -void st_gyro_deallocate_ring (struct iio_dev *indio_dev);int st_gyro_trig_set_state (struct iio_trigger *trig,bool state);#define ST_GYRO_TRIGGER_SET_STATE (&st_gyro_trig_set_state)#else /* CONFIG_IIO_BUFFER */
@@ -34,9 +33,6 @@ static inline int st_gyro_allocate_ring(struct iio_dev *indio_dev) {return 0 ; } -static inline void st_gyro_deallocate_ring (struct iio_dev *indio_dev) -{ -}#define ST_GYRO_TRIGGER_SET_STATE NULL#endif /* CONFIG_IIO_BUFFER */
drivers/iio/gyro/st_gyro_buffer.c +2 -7
@@ -61,13 +61,8 @@ static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {int st_gyro_allocate_ring (struct iio_dev *indio_dev) { -return iio_triggered_buffer_setup (indio_dev,NULL , - &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops); -} - -void st_gyro_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_gyro_buffer_setup_ops); }MODULE_AUTHOR ("Denis Ciocca <[email protected]>" );
drivers/iio/gyro/st_gyro_core.c +1 -5
@@ -512,7 +512,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) err =st_sensors_allocate_trigger (indio_dev,ST_GYRO_TRIGGER_OPS );if (err <0 ) - goto st_gyro_probe_trigger_error; +return err; } err =iio_device_register (indio_dev);
@@ -527,8 +527,6 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) st_gyro_device_register_error:if (gdata->irq >0 )st_sensors_deallocate_trigger (indio_dev); -st_gyro_probe_trigger_error: -st_gyro_deallocate_ring (indio_dev);return err; }EXPORT_SYMBOL (st_gyro_common_probe);
@@ -540,8 +538,6 @@ void st_gyro_common_remove(struct iio_dev *indio_dev)iio_device_unregister (indio_dev);if (gdata->irq >0 )st_sensors_deallocate_trigger (indio_dev); - -st_gyro_deallocate_ring (indio_dev); }EXPORT_SYMBOL (st_gyro_common_remove);
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerQuoted 9 lines · On Tue, 20 Jul 2021 10:46:39 +0300 Alexandru Ardelean <[email protected]>…
The
st_press_allocate_ring()function callsiio_triggered_buffer_setup()to allocate a triggered buffer.But the same can be done with
devm_iio_triggered_buffer_setup()and then thest_press_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_press_allocate_ring()as well.
This raises an interesting point. This driver mixes and matches between hanging devm off the parent and off the iio_dev->dev.
That's probably not a good thing to do as it could lead to an odd unwind order. I'm pretty sure the changes here are fine, but we should take a closer look...
Series applied to the togreg branch of iio.git and pushed out as testing.
You can do the same thing with the trigger with only slightly more complex patch, but I'd like to discuss whether there are races because of the current dev mix and match before that.
Thanks,
Jonathan
Quoted 82 lines
Signed-off-by Alexandru Ardelean <[email protected]>--- drivers/iio/pressure/st_pressure.h | 5 ----- drivers/iio/pressure/st_pressure_buffer.c | 9 ++------- drivers/iio/pressure/st_pressure_core.c | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-)drivers/iio/pressure/st_pressure.h +0
-5@@ -43,7 +43,6 @@ static __maybe_unused const struct st_sensors_platform_data default_press_pdata#ifdef CONFIG_IIO_BUFFER int st_press_allocate_ring (struct iio_dev *indio_dev); -void st_press_deallocate_ring (struct iio_dev *indio_dev);int st_press_trig_set_state (struct iio_trigger *trig,bool state);#define ST_PRESS_TRIGGER_SET_STATE (&st_press_trig_set_state)#else /* CONFIG_IIO_BUFFER */ @@ -51,10 +50,6 @@ static inline int st_press_allocate_ring(struct iio_dev *indio_dev) {return 0 ; } - -static inline void st_press_deallocate_ring (struct iio_dev *indio_dev) -{ -}#define ST_PRESS_TRIGGER_SET_STATE NULL#endif /* CONFIG_IIO_BUFFER */ drivers/iio/pressure/st_pressure_buffer.c +2
-7@@ -41,13 +41,8 @@ static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {int st_press_allocate_ring (struct iio_dev *indio_dev) { -return iio_triggered_buffer_setup (indio_dev,NULL , - &st_sensors_trigger_handler, &st_press_buffer_setup_ops); -} - -void st_press_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_press_buffer_setup_ops); }MODULE_AUTHOR ("Denis Ciocca <[email protected]>" );drivers/iio/pressure/st_pressure_core.c +1
-5@@ -718,7 +718,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) err =st_sensors_allocate_trigger (indio_dev,ST_PRESS_TRIGGER_OPS );if (err <0 ) - goto st_press_probe_trigger_error; +return err; } err =iio_device_register (indio_dev);@@ -733,8 +733,6 @@ int st_press_common_probe(struct iio_dev *indio_dev) st_press_device_register_error:if (press_data->irq >0 )st_sensors_deallocate_trigger (indio_dev); -st_press_probe_trigger_error: -st_press_deallocate_ring (indio_dev);return err; }EXPORT_SYMBOL (st_press_common_probe);@@ -746,8 +744,6 @@ void st_press_common_remove(struct iio_dev *indio_dev)iio_device_unregister (indio_dev);if (press_data->irq >0 )st_sensors_deallocate_trigger (indio_dev); - -st_press_deallocate_ring (indio_dev); }EXPORT_SYMBOL (st_press_common_remove);
Quoted 10 lines · Jonathan Cameron
Quoted 6 lines · On Tue, 20 Jul 2021 10:46:39 +0300 Alexandru Ardelean <[email protected]>…
The
st_press_allocate_ring()function callsiio_triggered_buffer_setup()to allocate a triggered buffer.But the same can be done with
devm_iio_triggered_buffer_setup()and then thest_press_common_remove()no longer needs to manually deallocate it.
Quoted 6 lines
Quoted 3 lines
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_press_allocate_ring()as well.This raises an interesting point. This driver mixes and matches between hanging devm off the parent and off the
iio_dev->dev.
iio_dev->dev.parent and the devm parent are the same reference but coming off from different pointers
Quoted 4 lines
That's probably not a good thing to do as it could lead to an odd unwind order. I'm pretty sure the changes here are fine, but we should take a closer look...
hmm, let me send a follow-up series
Quoted 3 lines
Series applied to the togreg branch of iio.git and pushed out as testing.
thank you :)
Quoted 3 lines
You can do the same thing with the trigger with only slightly more complex patch, but I'd like to discuss whether there are races because of the current dev mix and match before that.
will send follow-up series;
i was not sure whether to send everything in one go;
maybe it would have been a good idea; but i thought this one could be find on it's own;
Quoted 89 lines
Thanks,
Jonathan
Quoted 82 lines
Signed-off-by Alexandru Ardelean <[email protected]>--- drivers/iio/pressure/st_pressure.h | 5 ----- drivers/iio/pressure/st_pressure_buffer.c | 9 ++------- drivers/iio/pressure/st_pressure_core.c | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-)drivers/iio/pressure/st_pressure.h +0
-5@@ -43,7 +43,6 @@ static __maybe_unused const struct st_sensors_platform_data default_press_pdata#ifdef CONFIG_IIO_BUFFER int st_press_allocate_ring (struct iio_dev *indio_dev); -void st_press_deallocate_ring (struct iio_dev *indio_dev);int st_press_trig_set_state (struct iio_trigger *trig,bool state);#define ST_PRESS_TRIGGER_SET_STATE (&st_press_trig_set_state)#else /* CONFIG_IIO_BUFFER */ @@ -51,10 +50,6 @@ static inline int st_press_allocate_ring(struct iio_dev *indio_dev) {return 0 ; } - -static inline void st_press_deallocate_ring (struct iio_dev *indio_dev) -{ -}#define ST_PRESS_TRIGGER_SET_STATE NULL#endif /* CONFIG_IIO_BUFFER */ drivers/iio/pressure/st_pressure_buffer.c +2
-7@@ -41,13 +41,8 @@ static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {int st_press_allocate_ring (struct iio_dev *indio_dev) { -return iio_triggered_buffer_setup (indio_dev,NULL , - &st_sensors_trigger_handler, &st_press_buffer_setup_ops); -} - -void st_press_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_press_buffer_setup_ops); }MODULE_AUTHOR ("Denis Ciocca <[email protected]>" );drivers/iio/pressure/st_pressure_core.c +1
-5@@ -718,7 +718,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) err =st_sensors_allocate_trigger (indio_dev,ST_PRESS_TRIGGER_OPS );if (err <0 ) - goto st_press_probe_trigger_error; +return err; } err =iio_device_register (indio_dev);@@ -733,8 +733,6 @@ int st_press_common_probe(struct iio_dev *indio_dev) st_press_device_register_error:if (press_data->irq >0 )st_sensors_deallocate_trigger (indio_dev); -st_press_probe_trigger_error: -st_press_deallocate_ring (indio_dev);return err; }EXPORT_SYMBOL (st_press_common_probe);@@ -746,8 +744,6 @@ void st_press_common_remove(struct iio_dev *indio_dev)iio_device_unregister (indio_dev);if (press_data->irq >0 )st_sensors_deallocate_trigger (indio_dev); - -st_press_deallocate_ring (indio_dev); }EXPORT_SYMBOL (st_press_common_remove);