This change makes the use of devm_iio_kfifo_allocate() to attach the
life-cycle of the kfifo buffer to the parent (client->dev) object.

This removes the need to explicitly free 'indio_dev->buffer' via
iio_kfifo_free(), which is the main intent.

Signed-off-by: Alexandru Ardelean <[email protected]>
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index af0bcf95ee8a..633adf1a08c1 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -602,11 +602,12 @@ static const struct iio_buffer_setup_ops 
ad5933_ring_setup_ops = {
        .postdisable = ad5933_ring_postdisable,
 };
 
-static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
+static int ad5933_register_ring_funcs_and_init(struct device *dev,
+                                              struct iio_dev *indio_dev)
 {
        struct iio_buffer *buffer;
 
-       buffer = iio_kfifo_allocate();
+       buffer = devm_iio_kfifo_allocate(dev);
        if (!buffer)
                return -ENOMEM;
 
@@ -742,7 +743,7 @@ static int ad5933_probe(struct i2c_client *client,
        indio_dev->channels = ad5933_channels;
        indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
 
-       ret = ad5933_register_ring_funcs_and_init(indio_dev);
+       ret = ad5933_register_ring_funcs_and_init(&client->dev, indio_dev);
        if (ret)
                goto error_disable_mclk;
 
@@ -756,8 +757,6 @@ static int ad5933_probe(struct i2c_client *client,
 
        return 0;
 
-error_unreg_ring:
-       iio_kfifo_free(indio_dev->buffer);
 error_disable_mclk:
        clk_disable_unprepare(st->mclk);
 error_disable_reg:
@@ -772,7 +771,6 @@ static int ad5933_remove(struct i2c_client *client)
        struct ad5933_state *st = iio_priv(indio_dev);
 
        iio_device_unregister(indio_dev);
-       iio_kfifo_free(indio_dev->buffer);
        regulator_disable(st->reg);
        clk_disable_unprepare(st->mclk);
 
-- 
2.17.1

Reply via email to