[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VcTk-Lv_Hr0VHnd-r2XoVeRHEocwVyg6kKdWYrkHnf0gg@mail.gmail.com>
Date: Wed, 3 Feb 2021 12:02:00 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Alexandru Ardelean <alexandru.ardelean@...log.com>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-iio <linux-iio@...r.kernel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Jonathan Cameron <jic23@...nel.org>,
Nuno Sá <nuno.sa@...log.com>,
"Bogdan, Dragos" <dragos.bogdan@...log.com>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH v3 06/11] iio: core: merge buffer/ & scan_elements/ attributes
On Mon, Feb 1, 2021 at 5:28 PM Alexandru Ardelean
<alexandru.ardelean@...log.com> 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
Powered by blists - more mailing lists