aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/industrialio-buffer.c
diff options
context:
space:
mode:
authorOctavian Purdila <octavian.purdila@intel.com>2015-01-30 19:00:00 -0500
committerJonathan Cameron <jic23@kernel.org>2015-02-04 13:46:29 -0500
commit6da9b382bd2b6e1b910d7e3512a8a115c8c5f113 (patch)
treef8b17ed267b92119f8cbdbcdaeaac66d5b791690 /drivers/iio/industrialio-buffer.c
parentee3ac290e8aaa8396e697a11470703e616ab335f (diff)
iio: buffer: refactor buffer attributes setup
Move all core (non-custom) buffer attributes to a vector to make it easier to add more of them in the future. Signed-off-by: Octavian Purdila <octavian.purdila@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/industrialio-buffer.c')
-rw-r--r--drivers/iio/industrialio-buffer.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 71333140d42c..c2d5440aa226 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -761,6 +761,11 @@ static struct device_attribute dev_attr_length_ro = __ATTR(length,
761static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, 761static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR,
762 iio_buffer_show_enable, iio_buffer_store_enable); 762 iio_buffer_show_enable, iio_buffer_store_enable);
763 763
764static struct attribute *iio_buffer_attrs[] = {
765 &dev_attr_length.attr,
766 &dev_attr_enable.attr,
767};
768
764int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) 769int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
765{ 770{
766 struct iio_dev_attr *p; 771 struct iio_dev_attr *p;
@@ -778,21 +783,23 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
778 attrcount++; 783 attrcount++;
779 } 784 }
780 785
781 buffer->buffer_group.name = "buffer"; 786 attr = kcalloc(attrcount + ARRAY_SIZE(iio_buffer_attrs) + 1,
782 buffer->buffer_group.attrs = kcalloc(attrcount + 3, 787 sizeof(struct attribute *), GFP_KERNEL);
783 sizeof(*buffer->buffer_group.attrs), GFP_KERNEL); 788 if (!attr)
784 if (!buffer->buffer_group.attrs)
785 return -ENOMEM; 789 return -ENOMEM;
786 790
787 if (buffer->access->set_length) 791 memcpy(attr, iio_buffer_attrs, sizeof(iio_buffer_attrs));
788 buffer->buffer_group.attrs[0] = &dev_attr_length.attr; 792 if (!buffer->access->set_length)
789 else 793 attr[0] = &dev_attr_length_ro.attr;
790 buffer->buffer_group.attrs[0] = &dev_attr_length_ro.attr; 794
791 buffer->buffer_group.attrs[1] = &dev_attr_enable.attr;
792 if (buffer->attrs) 795 if (buffer->attrs)
793 memcpy(&buffer->buffer_group.attrs[2], buffer->attrs, 796 memcpy(&attr[ARRAY_SIZE(iio_buffer_attrs)], buffer->attrs,
794 sizeof(*&buffer->buffer_group.attrs) * attrcount); 797 sizeof(struct attribute *) * attrcount);
795 buffer->buffer_group.attrs[attrcount+2] = NULL; 798
799 attr[attrcount + ARRAY_SIZE(iio_buffer_attrs)] = NULL;
800
801 buffer->buffer_group.name = "buffer";
802 buffer->buffer_group.attrs = attr;
796 803
797 indio_dev->groups[indio_dev->groupcounter++] = &buffer->buffer_group; 804 indio_dev->groups[indio_dev->groupcounter++] = &buffer->buffer_group;
798 805