Skip to content

Commit ff3f7e0

Browse files
commodoJonathan Cameron
authored andcommitted
iio: buffer: extend short-hand use for 'indio_dev->buffer'
This change is both cosmetic and a prequel to adding support for attaching multiple buffers per IIO device. The IIO buffer sysfs attrs are mostly designed to support only one attached buffer, and in order to support more, we need to centralize [in each attr function] the buffer which is being accessed. This also makes it a bit more uniform, as in some functions there is a short-hand 'buffer' variable and at the same time the 'indio_dev->buffer' is still access directly. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 256d4b8 commit ff3f7e0

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

‎drivers/iio/industrialio-buffer.c‎

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ __poll_t iio_buffer_poll(struct file *filp,
189189
*/
190190
void iio_buffer_wakeup_poll(struct iio_dev *indio_dev)
191191
{
192-
if (!indio_dev->buffer)
192+
struct iio_buffer *buffer = indio_dev->buffer;
193+
194+
if (!buffer)
193195
return;
194196

195-
wake_up(&indio_dev->buffer->pollq);
197+
wake_up(&buffer->pollq);
196198
}
197199

198200
void iio_buffer_init(struct iio_buffer *buffer)
@@ -262,10 +264,11 @@ static ssize_t iio_scan_el_show(struct device *dev,
262264
{
263265
int ret;
264266
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
267+
struct iio_buffer *buffer = indio_dev->buffer;
265268

266269
/* Ensure ret is 0 or 1. */
267270
ret = !!test_bit(to_iio_dev_attr(attr)->address,
268-
indio_dev->buffer->scan_mask);
271+
buffer->scan_mask);
269272

270273
return sprintf(buf, "%d\n", ret);
271274
}
@@ -381,7 +384,7 @@ static ssize_t iio_scan_el_store(struct device *dev,
381384
if (ret < 0)
382385
return ret;
383386
mutex_lock(&indio_dev->mlock);
384-
if (iio_buffer_is_active(indio_dev->buffer)) {
387+
if (iio_buffer_is_active(buffer)) {
385388
ret = -EBUSY;
386389
goto error_ret;
387390
}
@@ -410,7 +413,9 @@ static ssize_t iio_scan_el_ts_show(struct device *dev,
410413
char *buf)
411414
{
412415
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
413-
return sprintf(buf, "%d\n", indio_dev->buffer->scan_timestamp);
416+
struct iio_buffer *buffer = indio_dev->buffer;
417+
418+
return sprintf(buf, "%d\n", buffer->scan_timestamp);
414419
}
415420

416421
static ssize_t iio_scan_el_ts_store(struct device *dev,
@@ -420,29 +425,30 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,
420425
{
421426
int ret;
422427
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
428+
struct iio_buffer *buffer = indio_dev->buffer;
423429
bool state;
424430

425431
ret = strtobool(buf, &state);
426432
if (ret < 0)
427433
return ret;
428434

429435
mutex_lock(&indio_dev->mlock);
430-
if (iio_buffer_is_active(indio_dev->buffer)) {
436+
if (iio_buffer_is_active(buffer)) {
431437
ret = -EBUSY;
432438
goto error_ret;
433439
}
434-
indio_dev->buffer->scan_timestamp = state;
440+
buffer->scan_timestamp = state;
435441
error_ret:
436442
mutex_unlock(&indio_dev->mlock);
437443

438444
return ret ? ret : len;
439445
}
440446

441447
static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
448+
struct iio_buffer *buffer,
442449
const struct iio_chan_spec *chan)
443450
{
444451
int ret, attrcount = 0;
445-
struct iio_buffer *buffer = indio_dev->buffer;
446452

447453
ret = __iio_add_chan_devattr("index",
448454
chan,
@@ -518,7 +524,7 @@ static ssize_t iio_buffer_write_length(struct device *dev,
518524
return len;
519525

520526
mutex_lock(&indio_dev->mlock);
521-
if (iio_buffer_is_active(indio_dev->buffer)) {
527+
if (iio_buffer_is_active(buffer)) {
522528
ret = -EBUSY;
523529
} else {
524530
buffer->access->set_length(buffer, val);
@@ -539,7 +545,9 @@ static ssize_t iio_buffer_show_enable(struct device *dev,
539545
char *buf)
540546
{
541547
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
542-
return sprintf(buf, "%d\n", iio_buffer_is_active(indio_dev->buffer));
548+
struct iio_buffer *buffer = indio_dev->buffer;
549+
550+
return sprintf(buf, "%d\n", iio_buffer_is_active(buffer));
543551
}
544552

545553
static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev,
@@ -1129,6 +1137,7 @@ static ssize_t iio_buffer_store_enable(struct device *dev,
11291137
int ret;
11301138
bool requested_state;
11311139
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1140+
struct iio_buffer *buffer = indio_dev->buffer;
11321141
bool inlist;
11331142

11341143
ret = strtobool(buf, &requested_state);
@@ -1138,17 +1147,15 @@ static ssize_t iio_buffer_store_enable(struct device *dev,
11381147
mutex_lock(&indio_dev->mlock);
11391148

11401149
/* Find out if it is in the list */
1141-
inlist = iio_buffer_is_active(indio_dev->buffer);
1150+
inlist = iio_buffer_is_active(buffer);
11421151
/* Already in desired state */
11431152
if (inlist == requested_state)
11441153
goto done;
11451154

11461155
if (requested_state)
1147-
ret = __iio_update_buffers(indio_dev,
1148-
indio_dev->buffer, NULL);
1156+
ret = __iio_update_buffers(indio_dev, buffer, NULL);
11491157
else
1150-
ret = __iio_update_buffers(indio_dev,
1151-
NULL, indio_dev->buffer);
1158+
ret = __iio_update_buffers(indio_dev, NULL, buffer);
11521159

11531160
done:
11541161
mutex_unlock(&indio_dev->mlock);
@@ -1190,7 +1197,7 @@ static ssize_t iio_buffer_store_watermark(struct device *dev,
11901197
goto out;
11911198
}
11921199

1193-
if (iio_buffer_is_active(indio_dev->buffer)) {
1200+
if (iio_buffer_is_active(buffer)) {
11941201
ret = -EBUSY;
11951202
goto out;
11961203
}
@@ -1207,11 +1214,9 @@ static ssize_t iio_dma_show_data_available(struct device *dev,
12071214
char *buf)
12081215
{
12091216
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1210-
size_t bytes;
1211-
1212-
bytes = iio_buffer_data_available(indio_dev->buffer);
1217+
struct iio_buffer *buffer = indio_dev->buffer;
12131218

1214-
return sprintf(buf, "%zu\n", bytes);
1219+
return sprintf(buf, "%zu\n", iio_buffer_data_available(buffer));
12151220
}
12161221

12171222
static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length,
@@ -1292,7 +1297,7 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
12921297
if (channels[i].scan_index < 0)
12931298
continue;
12941299

1295-
ret = iio_buffer_add_channel_sysfs(indio_dev,
1300+
ret = iio_buffer_add_channel_sysfs(indio_dev, buffer,
12961301
&channels[i]);
12971302
if (ret < 0)
12981303
goto error_cleanup_dynamic;
@@ -1332,20 +1337,22 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
13321337
bitmap_free(buffer->scan_mask);
13331338
error_cleanup_dynamic:
13341339
iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
1335-
kfree(indio_dev->buffer->buffer_group.attrs);
1340+
kfree(buffer->buffer_group.attrs);
13361341

13371342
return ret;
13381343
}
13391344

13401345
void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
13411346
{
1342-
if (!indio_dev->buffer)
1347+
struct iio_buffer *buffer = indio_dev->buffer;
1348+
1349+
if (!buffer)
13431350
return;
13441351

1345-
bitmap_free(indio_dev->buffer->scan_mask);
1346-
kfree(indio_dev->buffer->buffer_group.attrs);
1347-
kfree(indio_dev->buffer->scan_el_group.attrs);
1348-
iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list);
1352+
bitmap_free(buffer->scan_mask);
1353+
kfree(buffer->buffer_group.attrs);
1354+
kfree(buffer->scan_el_group.attrs);
1355+
iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
13491356
}
13501357

13511358
/**

0 commit comments

Comments
 (0)