Skip to content

Commit 3028e0c

Browse files
Jonathan CameronJonathan Cameron
authored andcommitted
iio: core: move @trig_readonly from struct iio_dev to struct iio_dev_opaque
This is only set via the iio_trig_set_immutable() call and later used by the IIO core so there is no benefit in drivers being able to access it. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Link: https://lore.kernel.org/r/20210426174911.397061-5-jic23@kernel.org
1 parent 6eaf9f6 commit 3028e0c

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎drivers/iio/industrialio-trigger.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,17 @@ EXPORT_SYMBOL(iio_trigger_unregister);
117117

118118
int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig)
119119
{
120+
struct iio_dev_opaque *iio_dev_opaque;
121+
120122
if (!indio_dev || !trig)
121123
return -EINVAL;
122124

125+
iio_dev_opaque = to_iio_dev_opaque(indio_dev);
123126
mutex_lock(&indio_dev->mlock);
124-
WARN_ON(indio_dev->trig_readonly);
127+
WARN_ON(iio_dev_opaque->trig_readonly);
125128

126129
indio_dev->trig = iio_trigger_get(trig);
127-
indio_dev->trig_readonly = true;
130+
iio_dev_opaque->trig_readonly = true;
128131
mutex_unlock(&indio_dev->mlock);
129132

130133
return 0;
@@ -402,6 +405,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
402405
size_t len)
403406
{
404407
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
408+
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
405409
struct iio_trigger *oldtrig = indio_dev->trig;
406410
struct iio_trigger *trig;
407411
int ret;
@@ -411,7 +415,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
411415
mutex_unlock(&indio_dev->mlock);
412416
return -EBUSY;
413417
}
414-
if (indio_dev->trig_readonly) {
418+
if (iio_dev_opaque->trig_readonly) {
415419
mutex_unlock(&indio_dev->mlock);
416420
return -EPERM;
417421
}

‎include/linux/iio/iio-opaque.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @indio_dev: public industrial I/O device information
99
* @id: used to identify device internally
1010
* @driver_module: used to make it harder to undercut users
11+
* @trig_readonly: mark the current trigger immutable
1112
* @event_interface: event chrdevs associated with interrupt lines
1213
* @attached_buffers: array of buffers statically attached by the driver
1314
* @attached_buffers_cnt: number of buffers in the array of statically attached buffers
@@ -30,6 +31,7 @@ struct iio_dev_opaque {
3031
struct iio_dev indio_dev;
3132
int id;
3233
struct module *driver_module;
34+
bool trig_readonly;
3335
struct iio_event_interface *event_interface;
3436
struct iio_buffer **attached_buffers;
3537
unsigned int attached_buffers_cnt;

‎include/linux/iio/iio.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ struct iio_buffer_setup_ops {
503503
* @scan_timestamp: [INTERN] set if any buffers have requested timestamp
504504
* @scan_index_timestamp:[INTERN] cache of the index to the timestamp
505505
* @trig: [INTERN] current device trigger (buffer modes)
506-
* @trig_readonly: [INTERN] mark the current trigger immutable
507506
* @pollfunc: [DRIVER] function run on trigger being received
508507
* @pollfunc_event: [DRIVER] function run on events trigger being received
509508
* @channels: [DRIVER] channel specification structure table
@@ -535,7 +534,6 @@ struct iio_dev {
535534
bool scan_timestamp;
536535
unsigned scan_index_timestamp;
537536
struct iio_trigger *trig;
538-
bool trig_readonly;
539537
struct iio_poll_func *pollfunc;
540538
struct iio_poll_func *pollfunc_event;
541539

0 commit comments

Comments
 (0)