Skip to content

Commit 3e3d11b

Browse files
commodojic23
authored andcommitted
iio: add reference to iio buffer on iio_dev_attr
This change adds a reference to a 'struct iio_buffer' object on the iio_dev_attr object. This way, we can use the created iio_dev_attr objects on per-buffer basis (since they're allocated anyway). A minor downside of this change is that the number of parameters on __iio_add_chan_devattr() grows by 1. This looks like it could do with a bit of a re-think. Signed-off-by: Alexandru Ardelean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d9a6257 commit 3e3d11b

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

drivers/iio/iio_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/kernel.h>
1313
#include <linux/device.h>
1414

15+
struct iio_buffer;
1516
struct iio_chan_spec;
1617
struct iio_dev;
1718

@@ -43,6 +44,7 @@ int __iio_add_chan_devattr(const char *postfix,
4344
u64 mask,
4445
enum iio_shared_by shared_by,
4546
struct device *dev,
47+
struct iio_buffer *buffer,
4648
struct list_head *attr_list);
4749
void iio_free_chan_devattr_list(struct list_head *attr_list);
4850

drivers/iio/industrialio-buffer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
447447
0,
448448
IIO_SEPARATE,
449449
&indio_dev->dev,
450+
buffer,
450451
&buffer->scan_el_dev_attr_list);
451452
if (ret)
452453
return ret;
@@ -458,6 +459,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
458459
0,
459460
0,
460461
&indio_dev->dev,
462+
buffer,
461463
&buffer->scan_el_dev_attr_list);
462464
if (ret)
463465
return ret;
@@ -470,6 +472,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
470472
chan->scan_index,
471473
0,
472474
&indio_dev->dev,
475+
buffer,
473476
&buffer->scan_el_dev_attr_list);
474477
else
475478
ret = __iio_add_chan_devattr("en",
@@ -479,6 +482,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
479482
chan->scan_index,
480483
0,
481484
&indio_dev->dev,
485+
buffer,
482486
&buffer->scan_el_dev_attr_list);
483487
if (ret)
484488
return ret;

drivers/iio/industrialio-core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ int __iio_add_chan_devattr(const char *postfix,
11161116
u64 mask,
11171117
enum iio_shared_by shared_by,
11181118
struct device *dev,
1119+
struct iio_buffer *buffer,
11191120
struct list_head *attr_list)
11201121
{
11211122
int ret;
@@ -1131,6 +1132,7 @@ int __iio_add_chan_devattr(const char *postfix,
11311132
goto error_iio_dev_attr_free;
11321133
iio_attr->c = chan;
11331134
iio_attr->address = mask;
1135+
iio_attr->buffer = buffer;
11341136
list_for_each_entry(t, attr_list, l)
11351137
if (strcmp(t->dev_attr.attr.name,
11361138
iio_attr->dev_attr.attr.name) == 0) {
@@ -1167,6 +1169,7 @@ static int iio_device_add_channel_label(struct iio_dev *indio_dev,
11671169
0,
11681170
IIO_SEPARATE,
11691171
&indio_dev->dev,
1172+
NULL,
11701173
&iio_dev_opaque->channel_attr_list);
11711174
if (ret < 0)
11721175
return ret;
@@ -1192,6 +1195,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
11921195
i,
11931196
shared_by,
11941197
&indio_dev->dev,
1198+
NULL,
11951199
&iio_dev_opaque->channel_attr_list);
11961200
if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
11971201
continue;
@@ -1228,6 +1232,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
12281232
i,
12291233
shared_by,
12301234
&indio_dev->dev,
1235+
NULL,
12311236
&iio_dev_opaque->channel_attr_list);
12321237
kfree(avail_postfix);
12331238
if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
@@ -1324,6 +1329,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
13241329
i,
13251330
ext_info->shared,
13261331
&indio_dev->dev,
1332+
NULL,
13271333
&iio_dev_opaque->channel_attr_list);
13281334
i++;
13291335
if (ret == -EBUSY && ext_info->shared)

drivers/iio/industrialio-event.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
385385

386386
ret = __iio_add_chan_devattr(postfix, chan, show, store,
387387
(i << 16) | spec_index, shared_by, &indio_dev->dev,
388+
NULL,
388389
&iio_dev_opaque->event_interface->dev_attr_list);
389390
kfree(postfix);
390391

include/linux/iio/sysfs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef _INDUSTRIAL_IO_SYSFS_H_
1010
#define _INDUSTRIAL_IO_SYSFS_H_
1111

12+
struct iio_buffer;
1213
struct iio_chan_spec;
1314

1415
/**
@@ -17,12 +18,14 @@ struct iio_chan_spec;
1718
* @address: associated register address
1819
* @l: list head for maintaining list of dynamically created attrs
1920
* @c: specification for the underlying channel
21+
* @buffer: the IIO buffer to which this attribute belongs to (if any)
2022
*/
2123
struct iio_dev_attr {
2224
struct device_attribute dev_attr;
2325
u64 address;
2426
struct list_head l;
2527
struct iio_chan_spec const *c;
28+
struct iio_buffer *buffer;
2629
};
2730

2831
#define to_iio_dev_attr(_dev_attr) \

0 commit comments

Comments
 (0)