aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/industrialio-buffer.c
diff options
context:
space:
mode:
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