diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2014-11-26 12:55:14 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-12-12 07:28:32 -0500 |
commit | d967cb6bd4e79c0cd7b150f1382d3d04e00408a0 (patch) | |
tree | f136233f589a1784b8ee3b91c20ffd71862c1ee7 /drivers/iio/industrialio-buffer.c | |
parent | 616dde2a1ea3df9398b1fcc7d6d6516c5fab6183 (diff) |
iio: buffer: Move iio_buffer_alloc_sysfs and iio_buffer_free_sysfs
The next patch will introduce new dependencies in iio_buffer_alloc_sysfs()
to functions which are currently defined after iio_buffer_alloc_sysfs(). To
avoid forward declarations move both iio_buffer_alloc_sysfs() and
iio_buffer_free_sysfs() after those function.
This is split into two patches one moving the functions and one adding the
dependencies to make review of the actual changes easier.
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.c | 185 |
1 files changed, 91 insertions, 94 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 8bb3e64eaf2c..8cd89eb269c5 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c | |||
@@ -383,100 +383,6 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev, | |||
383 | return ret; | 383 | return ret; |
384 | } | 384 | } |
385 | 385 | ||
386 | static const char * const iio_scan_elements_group_name = "scan_elements"; | ||
387 | |||
388 | int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) | ||
389 | { | ||
390 | struct iio_dev_attr *p; | ||
391 | struct attribute **attr; | ||
392 | struct iio_buffer *buffer = indio_dev->buffer; | ||
393 | int ret, i, attrn, attrcount, attrcount_orig = 0; | ||
394 | const struct iio_chan_spec *channels; | ||
395 | |||
396 | if (!buffer) | ||
397 | return 0; | ||
398 | |||
399 | if (buffer->attrs) | ||
400 | indio_dev->groups[indio_dev->groupcounter++] = buffer->attrs; | ||
401 | |||
402 | if (buffer->scan_el_attrs != NULL) { | ||
403 | attr = buffer->scan_el_attrs->attrs; | ||
404 | while (*attr++ != NULL) | ||
405 | attrcount_orig++; | ||
406 | } | ||
407 | attrcount = attrcount_orig; | ||
408 | INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list); | ||
409 | channels = indio_dev->channels; | ||
410 | if (channels) { | ||
411 | /* new magic */ | ||
412 | for (i = 0; i < indio_dev->num_channels; i++) { | ||
413 | if (channels[i].scan_index < 0) | ||
414 | continue; | ||
415 | |||
416 | /* Establish necessary mask length */ | ||
417 | if (channels[i].scan_index > | ||
418 | (int)indio_dev->masklength - 1) | ||
419 | indio_dev->masklength | ||
420 | = channels[i].scan_index + 1; | ||
421 | |||
422 | ret = iio_buffer_add_channel_sysfs(indio_dev, | ||
423 | &channels[i]); | ||
424 | if (ret < 0) | ||
425 | goto error_cleanup_dynamic; | ||
426 | attrcount += ret; | ||
427 | if (channels[i].type == IIO_TIMESTAMP) | ||
428 | indio_dev->scan_index_timestamp = | ||
429 | channels[i].scan_index; | ||
430 | } | ||
431 | if (indio_dev->masklength && buffer->scan_mask == NULL) { | ||
432 | buffer->scan_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength), | ||
433 | sizeof(*buffer->scan_mask), | ||
434 | GFP_KERNEL); | ||
435 | if (buffer->scan_mask == NULL) { | ||
436 | ret = -ENOMEM; | ||
437 | goto error_cleanup_dynamic; | ||
438 | } | ||
439 | } | ||
440 | } | ||
441 | |||
442 | buffer->scan_el_group.name = iio_scan_elements_group_name; | ||
443 | |||
444 | buffer->scan_el_group.attrs = kcalloc(attrcount + 1, | ||
445 | sizeof(buffer->scan_el_group.attrs[0]), | ||
446 | GFP_KERNEL); | ||
447 | if (buffer->scan_el_group.attrs == NULL) { | ||
448 | ret = -ENOMEM; | ||
449 | goto error_free_scan_mask; | ||
450 | } | ||
451 | if (buffer->scan_el_attrs) | ||
452 | memcpy(buffer->scan_el_group.attrs, buffer->scan_el_attrs, | ||
453 | sizeof(buffer->scan_el_group.attrs[0])*attrcount_orig); | ||
454 | attrn = attrcount_orig; | ||
455 | |||
456 | list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l) | ||
457 | buffer->scan_el_group.attrs[attrn++] = &p->dev_attr.attr; | ||
458 | indio_dev->groups[indio_dev->groupcounter++] = &buffer->scan_el_group; | ||
459 | |||
460 | return 0; | ||
461 | |||
462 | error_free_scan_mask: | ||
463 | kfree(buffer->scan_mask); | ||
464 | error_cleanup_dynamic: | ||
465 | iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list); | ||
466 | |||
467 | return ret; | ||
468 | } | ||
469 | |||
470 | void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev) | ||
471 | { | ||
472 | if (!indio_dev->buffer) | ||
473 | return; | ||
474 | |||
475 | kfree(indio_dev->buffer->scan_mask); | ||
476 | kfree(indio_dev->buffer->scan_el_group.attrs); | ||
477 | iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list); | ||
478 | } | ||
479 | |||
480 | ssize_t iio_buffer_read_length(struct device *dev, | 386 | ssize_t iio_buffer_read_length(struct device *dev, |
481 | struct device_attribute *attr, | 387 | struct device_attribute *attr, |
482 | char *buf) | 388 | char *buf) |
@@ -855,6 +761,97 @@ done: | |||
855 | } | 761 | } |
856 | EXPORT_SYMBOL(iio_buffer_store_enable); | 762 | EXPORT_SYMBOL(iio_buffer_store_enable); |
857 | 763 | ||
764 | static const char * const iio_scan_elements_group_name = "scan_elements"; | ||
765 | |||
766 | int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) | ||
767 | { | ||
768 | struct iio_dev_attr *p; | ||
769 | struct attribute **attr; | ||
770 | struct iio_buffer *buffer = indio_dev->buffer; | ||
771 | int ret, i, attrn, attrcount, attrcount_orig = 0; | ||
772 | const struct iio_chan_spec *channels; | ||
773 | |||
774 | if (!buffer) | ||
775 | return 0; | ||
776 | |||
777 | if (buffer->scan_el_attrs != NULL) { | ||
778 | attr = buffer->scan_el_attrs->attrs; | ||
779 | while (*attr++ != NULL) | ||
780 | attrcount_orig++; | ||
781 | } | ||
782 | attrcount = attrcount_orig; | ||
783 | INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list); | ||
784 | channels = indio_dev->channels; | ||
785 | if (channels) { | ||
786 | /* new magic */ | ||
787 | for (i = 0; i < indio_dev->num_channels; i++) { | ||
788 | if (channels[i].scan_index < 0) | ||
789 | continue; | ||
790 | |||
791 | /* Establish necessary mask length */ | ||
792 | if (channels[i].scan_index > | ||
793 | (int)indio_dev->masklength - 1) | ||
794 | indio_dev->masklength | ||
795 | = channels[i].scan_index + 1; | ||
796 | |||
797 | ret = iio_buffer_add_channel_sysfs(indio_dev, | ||
798 | &channels[i]); | ||
799 | if (ret < 0) | ||
800 | goto error_cleanup_dynamic; | ||
801 | attrcount += ret; | ||
802 | if (channels[i].type == IIO_TIMESTAMP) | ||
803 | indio_dev->scan_index_timestamp = | ||
804 | channels[i].scan_index; | ||
805 | } | ||
806 | if (indio_dev->masklength && buffer->scan_mask == NULL) { | ||
807 | buffer->scan_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength), | ||
808 | sizeof(*buffer->scan_mask), | ||
809 | GFP_KERNEL); | ||
810 | if (buffer->scan_mask == NULL) { | ||
811 | ret = -ENOMEM; | ||
812 | goto error_cleanup_dynamic; | ||
813 | } | ||
814 | } | ||
815 | } | ||
816 | |||
817 | buffer->scan_el_group.name = iio_scan_elements_group_name; | ||
818 | |||
819 | buffer->scan_el_group.attrs = kcalloc(attrcount + 1, | ||
820 | sizeof(buffer->scan_el_group.attrs[0]), | ||
821 | GFP_KERNEL); | ||
822 | if (buffer->scan_el_group.attrs == NULL) { | ||
823 | ret = -ENOMEM; | ||
824 | goto error_free_scan_mask; | ||
825 | } | ||
826 | if (buffer->scan_el_attrs) | ||
827 | memcpy(buffer->scan_el_group.attrs, buffer->scan_el_attrs, | ||
828 | sizeof(buffer->scan_el_group.attrs[0])*attrcount_orig); | ||
829 | attrn = attrcount_orig; | ||
830 | |||
831 | list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l) | ||
832 | buffer->scan_el_group.attrs[attrn++] = &p->dev_attr.attr; | ||
833 | indio_dev->groups[indio_dev->groupcounter++] = &buffer->scan_el_group; | ||
834 | |||
835 | return 0; | ||
836 | |||
837 | error_free_scan_mask: | ||
838 | kfree(buffer->scan_mask); | ||
839 | error_cleanup_dynamic: | ||
840 | iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list); | ||
841 | |||
842 | return ret; | ||
843 | } | ||
844 | |||
845 | void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev) | ||
846 | { | ||
847 | if (!indio_dev->buffer) | ||
848 | return; | ||
849 | |||
850 | kfree(indio_dev->buffer->scan_mask); | ||
851 | kfree(indio_dev->buffer->scan_el_group.attrs); | ||
852 | iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list); | ||
853 | } | ||
854 | |||
858 | /** | 855 | /** |
859 | * iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected | 856 | * iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected |
860 | * @indio_dev: the iio device | 857 | * @indio_dev: the iio device |