Skip to content

Commit e16e0a7

Browse files
commodoJonathan Cameron
authored andcommitted
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: Alexandru Ardelean <alexandru.ardelean@analog.com> Link: https://lore.kernel.org/r/20200917125951.861-1-alexandru.ardelean@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 14b15f3 commit e16e0a7

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

‎drivers/iio/industrialio-buffer.c‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,26 +1264,14 @@ static struct attribute *iio_buffer_attrs[] = {
12641264
&dev_attr_data_available.attr,
12651265
};
12661266

1267-
int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
1267+
static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
1268+
struct iio_dev *indio_dev)
12681269
{
12691270
struct iio_dev_attr *p;
12701271
struct attribute **attr;
1271-
struct iio_buffer *buffer = indio_dev->buffer;
12721272
int ret, i, attrn, attrcount;
12731273
const struct iio_chan_spec *channels;
12741274

1275-
channels = indio_dev->channels;
1276-
if (channels) {
1277-
int ml = indio_dev->masklength;
1278-
1279-
for (i = 0; i < indio_dev->num_channels; i++)
1280-
ml = max(ml, channels[i].scan_index + 1);
1281-
indio_dev->masklength = ml;
1282-
}
1283-
1284-
if (!buffer)
1285-
return 0;
1286-
12871275
attrcount = 0;
12881276
if (buffer->attrs) {
12891277
while (buffer->attrs[attrcount] != NULL)
@@ -1367,19 +1355,45 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
13671355
return ret;
13681356
}
13691357

1370-
void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
1358+
int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
13711359
{
13721360
struct iio_buffer *buffer = indio_dev->buffer;
1361+
const struct iio_chan_spec *channels;
1362+
int i;
1363+
1364+
channels = indio_dev->channels;
1365+
if (channels) {
1366+
int ml = indio_dev->masklength;
1367+
1368+
for (i = 0; i < indio_dev->num_channels; i++)
1369+
ml = max(ml, channels[i].scan_index + 1);
1370+
indio_dev->masklength = ml;
1371+
}
13731372

13741373
if (!buffer)
1375-
return;
1374+
return 0;
1375+
1376+
return __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev);
1377+
}
13761378

1379+
static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer)
1380+
{
13771381
bitmap_free(buffer->scan_mask);
13781382
kfree(buffer->buffer_group.attrs);
13791383
kfree(buffer->scan_el_group.attrs);
13801384
iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
13811385
}
13821386

1387+
void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
1388+
{
1389+
struct iio_buffer *buffer = indio_dev->buffer;
1390+
1391+
if (!buffer)
1392+
return;
1393+
1394+
__iio_buffer_free_sysfs_and_mask(buffer);
1395+
}
1396+
13831397
/**
13841398
* iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected
13851399
* @indio_dev: the iio device

0 commit comments

Comments
 (0)