diff options
Diffstat (limited to 'drivers/iio/buffer_cb.c')
-rw-r--r-- | drivers/iio/buffer_cb.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/drivers/iio/buffer_cb.c b/drivers/iio/buffer_cb.c index 9d19ba74f22..2d9c6f8c06d 100644 --- a/drivers/iio/buffer_cb.c +++ b/drivers/iio/buffer_cb.c @@ -7,26 +7,36 @@ struct iio_cb_buffer { struct iio_buffer buffer; - int (*cb)(u8 *data, void *private); + int (*cb)(const void *data, void *private); void *private; struct iio_channel *channels; }; -static int iio_buffer_cb_store_to(struct iio_buffer *buffer, u8 *data) +static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer) { - struct iio_cb_buffer *cb_buff = container_of(buffer, - struct iio_cb_buffer, - buffer); + return container_of(buffer, struct iio_cb_buffer, buffer); +} +static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data) +{ + struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer); return cb_buff->cb(data, cb_buff->private); } -static struct iio_buffer_access_funcs iio_cb_access = { +static void iio_buffer_cb_release(struct iio_buffer *buffer) +{ + struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer); + kfree(cb_buff->buffer.scan_mask); + kfree(cb_buff); +} + +static const struct iio_buffer_access_funcs iio_cb_access = { .store_to = &iio_buffer_cb_store_to, + .release = &iio_buffer_cb_release, }; struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, - int (*cb)(u8 *data, + int (*cb)(const void *data, void *private), void *private) { @@ -41,6 +51,8 @@ struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, goto error_ret; } + iio_buffer_init(&cb_buff->buffer); + cb_buff->private = private; cb_buff->cb = cb; cb_buff->buffer.access = &iio_cb_access; @@ -102,9 +114,8 @@ EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb); void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buff) { - kfree(cb_buff->buffer.scan_mask); iio_channel_release_all(cb_buff->channels); - kfree(cb_buff); + iio_buffer_put(&cb_buff->buffer); } EXPORT_SYMBOL_GPL(iio_channel_release_all_cb); |