diff options
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/iio_core.h | 1 | ||||
-rw-r--r-- | drivers/iio/industrialio-buffer.c | 21 | ||||
-rw-r--r-- | drivers/iio/industrialio-core.c | 34 | ||||
-rw-r--r-- | drivers/iio/industrialio-event.c | 15 |
4 files changed, 23 insertions, 48 deletions
diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h index 7512cf728ee6..9939917033ca 100644 --- a/drivers/iio/iio_core.h +++ b/drivers/iio/iio_core.h | |||
@@ -33,6 +33,7 @@ int __iio_add_chan_devattr(const char *postfix, | |||
33 | enum iio_shared_by shared_by, | 33 | enum iio_shared_by shared_by, |
34 | struct device *dev, | 34 | struct device *dev, |
35 | struct list_head *attr_list); | 35 | struct list_head *attr_list); |
36 | void iio_free_chan_devattr_list(struct list_head *attr_list); | ||
36 | 37 | ||
37 | /* Event interface flags */ | 38 | /* Event interface flags */ |
38 | #define IIO_BUSY_BIT_POS 1 | 39 | #define IIO_BUSY_BIT_POS 1 |
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 | ||
277 | static 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 | |||
284 | static 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 | |||
294 | static const char * const iio_scan_elements_group_name = "scan_elements"; | 277 | static const char * const iio_scan_elements_group_name = "scan_elements"; |
295 | 278 | ||
296 | int iio_buffer_register(struct iio_dev *indio_dev, | 279 | int iio_buffer_register(struct iio_dev *indio_dev, |
@@ -367,7 +350,7 @@ int iio_buffer_register(struct iio_dev *indio_dev, | |||
367 | error_free_scan_mask: | 350 | error_free_scan_mask: |
368 | kfree(buffer->scan_mask); | 351 | kfree(buffer->scan_mask); |
369 | error_cleanup_dynamic: | 352 | error_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 | } |
382 | EXPORT_SYMBOL(iio_buffer_unregister); | 365 | EXPORT_SYMBOL(iio_buffer_unregister); |
383 | 366 | ||
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index dc24a9b3d325..572982fe3155 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c | |||
@@ -794,11 +794,22 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, | |||
794 | return attrcount; | 794 | return attrcount; |
795 | } | 795 | } |
796 | 796 | ||
797 | static void iio_device_remove_and_free_read_attr(struct iio_dev *indio_dev, | 797 | /** |
798 | struct iio_dev_attr *p) | 798 | * iio_free_chan_devattr_list() - Free a list of IIO device attributes |
799 | * @attr_list: List of IIO device attributes | ||
800 | * | ||
801 | * This function frees the memory allocated for each of the IIO device | ||
802 | * attributes in the list. Note: if you want to reuse the list after calling | ||
803 | * this function you have to reinitialize it using INIT_LIST_HEAD(). | ||
804 | */ | ||
805 | void iio_free_chan_devattr_list(struct list_head *attr_list) | ||
799 | { | 806 | { |
800 | kfree(p->dev_attr.attr.name); | 807 | struct iio_dev_attr *p, *n; |
801 | kfree(p); | 808 | |
809 | list_for_each_entry_safe(p, n, attr_list, l) { | ||
810 | kfree(p->dev_attr.attr.name); | ||
811 | kfree(p); | ||
812 | } | ||
802 | } | 813 | } |
803 | 814 | ||
804 | static ssize_t iio_show_dev_name(struct device *dev, | 815 | static ssize_t iio_show_dev_name(struct device *dev, |
@@ -814,7 +825,7 @@ static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL); | |||
814 | static int iio_device_register_sysfs(struct iio_dev *indio_dev) | 825 | static int iio_device_register_sysfs(struct iio_dev *indio_dev) |
815 | { | 826 | { |
816 | int i, ret = 0, attrcount, attrn, attrcount_orig = 0; | 827 | int i, ret = 0, attrcount, attrn, attrcount_orig = 0; |
817 | struct iio_dev_attr *p, *n; | 828 | struct iio_dev_attr *p; |
818 | struct attribute **attr; | 829 | struct attribute **attr; |
819 | 830 | ||
820 | /* First count elements in any existing group */ | 831 | /* First count elements in any existing group */ |
@@ -867,11 +878,7 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev) | |||
867 | return 0; | 878 | return 0; |
868 | 879 | ||
869 | error_clear_attrs: | 880 | error_clear_attrs: |
870 | list_for_each_entry_safe(p, n, | 881 | iio_free_chan_devattr_list(&indio_dev->channel_attr_list); |
871 | &indio_dev->channel_attr_list, l) { | ||
872 | list_del(&p->l); | ||
873 | iio_device_remove_and_free_read_attr(indio_dev, p); | ||
874 | } | ||
875 | 882 | ||
876 | return ret; | 883 | return ret; |
877 | } | 884 | } |
@@ -879,12 +886,7 @@ error_clear_attrs: | |||
879 | static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) | 886 | static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) |
880 | { | 887 | { |
881 | 888 | ||
882 | struct iio_dev_attr *p, *n; | 889 | iio_free_chan_devattr_list(&indio_dev->channel_attr_list); |
883 | |||
884 | list_for_each_entry_safe(p, n, &indio_dev->channel_attr_list, l) { | ||
885 | list_del(&p->l); | ||
886 | iio_device_remove_and_free_read_attr(indio_dev, p); | ||
887 | } | ||
888 | kfree(indio_dev->chan_attr_group.attrs); | 890 | kfree(indio_dev->chan_attr_group.attrs); |
889 | } | 891 | } |
890 | 892 | ||
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c index d251f30fb739..4a3fd5acda94 100644 --- a/drivers/iio/industrialio-event.c +++ b/drivers/iio/industrialio-event.c | |||
@@ -350,17 +350,6 @@ error_ret: | |||
350 | return ret; | 350 | return ret; |
351 | } | 351 | } |
352 | 352 | ||
353 | static inline void __iio_remove_event_config_attrs(struct iio_dev *indio_dev) | ||
354 | { | ||
355 | struct iio_dev_attr *p, *n; | ||
356 | list_for_each_entry_safe(p, n, | ||
357 | &indio_dev->event_interface-> | ||
358 | dev_attr_list, l) { | ||
359 | kfree(p->dev_attr.attr.name); | ||
360 | kfree(p); | ||
361 | } | ||
362 | } | ||
363 | |||
364 | static inline int __iio_add_event_config_attrs(struct iio_dev *indio_dev) | 353 | static inline int __iio_add_event_config_attrs(struct iio_dev *indio_dev) |
365 | { | 354 | { |
366 | int j, ret, attrcount = 0; | 355 | int j, ret, attrcount = 0; |
@@ -452,7 +441,7 @@ int iio_device_register_eventset(struct iio_dev *indio_dev) | |||
452 | return 0; | 441 | return 0; |
453 | 442 | ||
454 | error_free_setup_event_lines: | 443 | error_free_setup_event_lines: |
455 | __iio_remove_event_config_attrs(indio_dev); | 444 | iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list); |
456 | kfree(indio_dev->event_interface); | 445 | kfree(indio_dev->event_interface); |
457 | error_ret: | 446 | error_ret: |
458 | 447 | ||
@@ -477,7 +466,7 @@ void iio_device_unregister_eventset(struct iio_dev *indio_dev) | |||
477 | { | 466 | { |
478 | if (indio_dev->event_interface == NULL) | 467 | if (indio_dev->event_interface == NULL) |
479 | return; | 468 | return; |
480 | __iio_remove_event_config_attrs(indio_dev); | 469 | iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list); |
481 | kfree(indio_dev->event_interface->group.attrs); | 470 | kfree(indio_dev->event_interface->group.attrs); |
482 | kfree(indio_dev->event_interface); | 471 | kfree(indio_dev->event_interface); |
483 | } | 472 | } |