summaryrefslogtreecommitdiffstats
path: root/drivers/iio/industrialio-buffer.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-10-07 07:50:00 -0400
committerJonathan Cameron <jic23@kernel.org>2013-10-12 07:17:34 -0400
commit84088ebd14aebf1b8499409a037094b9b88e2796 (patch)
treea239085ff20650319449d811f5e55207ea890df3 /drivers/iio/industrialio-buffer.c
parenta95194569f697a6cc10d00f9b9b3d21b0b820520 (diff)
iio: Add a helper to free a list of IIO device attributes
We have the same code to free a IIO device attribute list in multiple place. This patch adds a new helper function to take care of this and replaces the custom instances with a call to the helper function. Note that we do not need to call list_del() for each of the list items since we will never look at any of the list items nor the list itself again. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/industrialio-buffer.c')
-rw-r--r--drivers/iio/industrialio-buffer.c21
1 files changed, 2 insertions, 19 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index d6a5455ae51a..d12b384d94bf 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -274,23 +274,6 @@ error_ret:
274 return ret; 274 return ret;
275} 275}
276 276
277static void iio_buffer_remove_and_free_scan_dev_attr(struct iio_dev *indio_dev,
278 struct iio_dev_attr *p)
279{
280 kfree(p->dev_attr.attr.name);
281 kfree(p);
282}
283
284static void __iio_buffer_attr_cleanup(struct iio_dev *indio_dev)
285{
286 struct iio_dev_attr *p, *n;
287 struct iio_buffer *buffer = indio_dev->buffer;
288
289 list_for_each_entry_safe(p, n,
290 &buffer->scan_el_dev_attr_list, l)
291 iio_buffer_remove_and_free_scan_dev_attr(indio_dev, p);
292}
293
294static const char * const iio_scan_elements_group_name = "scan_elements"; 277static const char * const iio_scan_elements_group_name = "scan_elements";
295 278
296int iio_buffer_register(struct iio_dev *indio_dev, 279int iio_buffer_register(struct iio_dev *indio_dev,
@@ -367,7 +350,7 @@ int iio_buffer_register(struct iio_dev *indio_dev,
367error_free_scan_mask: 350error_free_scan_mask:
368 kfree(buffer->scan_mask); 351 kfree(buffer->scan_mask);
369error_cleanup_dynamic: 352error_cleanup_dynamic:
370 __iio_buffer_attr_cleanup(indio_dev); 353 iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
371 354
372 return ret; 355 return ret;
373} 356}
@@ -377,7 +360,7 @@ void iio_buffer_unregister(struct iio_dev *indio_dev)
377{ 360{
378 kfree(indio_dev->buffer->scan_mask); 361 kfree(indio_dev->buffer->scan_mask);
379 kfree(indio_dev->buffer->scan_el_group.attrs); 362 kfree(indio_dev->buffer->scan_el_group.attrs);
380 __iio_buffer_attr_cleanup(indio_dev); 363 iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list);
381} 364}
382EXPORT_SYMBOL(iio_buffer_unregister); 365EXPORT_SYMBOL(iio_buffer_unregister);
383 366