Re: [PATCH v3 06/11] iio: core: merge buffer/ & scan_elements/ attributes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 1, 2021 at 5:28 PM Alexandru Ardelean
<alexandru.ardelean@xxxxxxxxxx> wrote:
>
> With this change, we create a new directory for the IIO device called
> buffer0, under which both the old buffer/ and scan_elements/ are stored.
>
> This is done to simplify the addition of multiple IIO buffers per IIO
> device. Otherwise we would need to add a bufferX/ and scan_elementsX/
> directory for each IIO buffer.
> With the current way of storing attribute groups, we can't have directories
> stored under each other (i.e. scan_elements/ under buffer/), so the best
> approach moving forward is to merge their attributes.
>
> The old/legacy buffer/ & scan_elements/ groups are not stored on the opaque
> IIO device object. This way the IIO buffer can have just a single
> attribute_group object, saving a bit of memory when adding multiple IIO
> buffers.

...

> +static int iio_buffer_register_legacy_sysfs_groups(struct iio_dev *indio_dev,
> +                                                  struct attribute **buffer_attrs,
> +                                                  int buffer_attrcount,
> +                                                  int scan_el_attrcount)
> +{
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +       struct attribute_group *group;
> +       int ret;
> +
> +       group = &iio_dev_opaque->legacy_buffer_group;

> +       group->attrs = kcalloc(buffer_attrcount + 1,
> +                              sizeof(struct attribute *), GFP_KERNEL);
> +       if (!group->attrs)
> +               return -ENOMEM;
> +
> +       memcpy(group->attrs, buffer_attrs,
> +              buffer_attrcount * sizeof(struct attribute *));

kmemdup() ?
Perhaps introduce kmemdup_array().

> +       group->name = "buffer";
> +
> +       ret = iio_device_register_sysfs_group(indio_dev, group);
> +       if (ret)
> +               goto error_free_buffer_attrs;
> +
> +       group = &iio_dev_opaque->legacy_scan_el_group;

> +       group->attrs = kcalloc(scan_el_attrcount + 1,
> +                              sizeof(struct attribute *), GFP_KERNEL);
> +       if (!group->attrs) {
> +               ret = -ENOMEM;
> +               goto error_free_buffer_attrs;
> +       }
> +
> +       memcpy(group->attrs, &buffer_attrs[buffer_attrcount],
> +              scan_el_attrcount * sizeof(struct attribute *));

Ditto.

> +       group->name = "scan_elements";
> +
> +       ret = iio_device_register_sysfs_group(indio_dev, group);
> +       if (ret)
> +               goto error_free_scan_el_attrs;
> +
> +       return 0;
> +
> +error_free_buffer_attrs:
> +       kfree(iio_dev_opaque->legacy_buffer_group.attrs);
> +error_free_scan_el_attrs:
> +       kfree(iio_dev_opaque->legacy_scan_el_group.attrs);
> +
> +       return ret;
> +}

-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux