Skip to content

Commit

Permalink
iio: pressure: st_pressure: use devm_iio_triggered_buffer_setup() for…
Browse files Browse the repository at this point in the history
… 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.

Signed-off-by: Alexandru Ardelean <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
commodo authored and jic23 committed Jul 24, 2021
1 parent 78a6af3 commit 674db1e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
5 changes: 0 additions & 5 deletions drivers/iio/pressure/st_pressure.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,13 @@ 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 */
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 */

Expand Down
9 changes: 2 additions & 7 deletions drivers/iio/pressure/st_pressure_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]>");
Expand Down
6 changes: 1 addition & 5 deletions drivers/iio/pressure/st_pressure_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand Down

0 comments on commit 674db1e

Please sign in to comment.