Commit e16e0a77 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

iio: buffer: split buffer sysfs creation to take buffer as primary arg

Currently the iio_buffer_{alloc,free}_sysfs_and_mask() take 'indio_dev' as
primary argument. This change splits the main logic into a private function
that takes an IIO buffer as primary argument.

That way, the functions can be extended to configure the sysfs for multiple
buffers.
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20200917125951.861-1-alexandru.ardelean@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 14b15f3f
...@@ -1264,26 +1264,14 @@ static struct attribute *iio_buffer_attrs[] = { ...@@ -1264,26 +1264,14 @@ static struct attribute *iio_buffer_attrs[] = {
&dev_attr_data_available.attr, &dev_attr_data_available.attr,
}; };
int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
struct iio_dev *indio_dev)
{ {
struct iio_dev_attr *p; struct iio_dev_attr *p;
struct attribute **attr; struct attribute **attr;
struct iio_buffer *buffer = indio_dev->buffer;
int ret, i, attrn, attrcount; int ret, i, attrn, attrcount;
const struct iio_chan_spec *channels; const struct iio_chan_spec *channels;
channels = indio_dev->channels;
if (channels) {
int ml = indio_dev->masklength;
for (i = 0; i < indio_dev->num_channels; i++)
ml = max(ml, channels[i].scan_index + 1);
indio_dev->masklength = ml;
}
if (!buffer)
return 0;
attrcount = 0; attrcount = 0;
if (buffer->attrs) { if (buffer->attrs) {
while (buffer->attrs[attrcount] != NULL) while (buffer->attrs[attrcount] != NULL)
...@@ -1367,19 +1355,45 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1367,19 +1355,45 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
return ret; return ret;
} }
void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev) int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
{ {
struct iio_buffer *buffer = indio_dev->buffer; struct iio_buffer *buffer = indio_dev->buffer;
const struct iio_chan_spec *channels;
int i;
channels = indio_dev->channels;
if (channels) {
int ml = indio_dev->masklength;
for (i = 0; i < indio_dev->num_channels; i++)
ml = max(ml, channels[i].scan_index + 1);
indio_dev->masklength = ml;
}
if (!buffer) if (!buffer)
return; return 0;
return __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev);
}
static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer)
{
bitmap_free(buffer->scan_mask); bitmap_free(buffer->scan_mask);
kfree(buffer->buffer_group.attrs); kfree(buffer->buffer_group.attrs);
kfree(buffer->scan_el_group.attrs); kfree(buffer->scan_el_group.attrs);
iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list); iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
} }
void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
{
struct iio_buffer *buffer = indio_dev->buffer;
if (!buffer)
return;
__iio_buffer_free_sysfs_and_mask(buffer);
}
/** /**
* iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected * iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected
* @indio_dev: the iio device * @indio_dev: the iio device
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment