Commit 51570c9d authored by Miquel Raynal's avatar Miquel Raynal Committed by Jonathan Cameron

iio: core: Move the currentmode entry to the opaque structure

This entry should, under no situation, be modified by device
drivers. Now that we have limited its read access to device drivers
really needing it and did so through a dedicated helper, we can
easily move this variable to the opaque structure in order to
prevent any further modification from non-authorized code (out of the
core, basically).
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: default avatarAlexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/20220207143840.707510-12-miquel.raynal@bootlin.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 8c576f87
...@@ -1065,7 +1065,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, ...@@ -1065,7 +1065,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
indio_dev->active_scan_mask = config->scan_mask; indio_dev->active_scan_mask = config->scan_mask;
indio_dev->scan_timestamp = config->scan_timestamp; indio_dev->scan_timestamp = config->scan_timestamp;
indio_dev->scan_bytes = config->scan_bytes; indio_dev->scan_bytes = config->scan_bytes;
indio_dev->currentmode = config->mode; iio_dev_opaque->currentmode = config->mode;
iio_update_demux(indio_dev); iio_update_demux(indio_dev);
...@@ -1103,7 +1103,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, ...@@ -1103,7 +1103,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
} }
} }
if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
ret = iio_trigger_attach_poll_func(indio_dev->trig, ret = iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc); indio_dev->pollfunc);
if (ret) if (ret)
...@@ -1122,7 +1122,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, ...@@ -1122,7 +1122,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
return 0; return 0;
err_detach_pollfunc: err_detach_pollfunc:
if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
iio_trigger_detach_poll_func(indio_dev->trig, iio_trigger_detach_poll_func(indio_dev->trig,
indio_dev->pollfunc); indio_dev->pollfunc);
} }
...@@ -1135,7 +1135,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, ...@@ -1135,7 +1135,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
if (indio_dev->setup_ops->postdisable) if (indio_dev->setup_ops->postdisable)
indio_dev->setup_ops->postdisable(indio_dev); indio_dev->setup_ops->postdisable(indio_dev);
err_undo_config: err_undo_config:
indio_dev->currentmode = INDIO_DIRECT_MODE; iio_dev_opaque->currentmode = INDIO_DIRECT_MODE;
indio_dev->active_scan_mask = NULL; indio_dev->active_scan_mask = NULL;
return ret; return ret;
...@@ -1165,7 +1165,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) ...@@ -1165,7 +1165,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev)
ret = ret2; ret = ret2;
} }
if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
iio_trigger_detach_poll_func(indio_dev->trig, iio_trigger_detach_poll_func(indio_dev->trig,
indio_dev->pollfunc); indio_dev->pollfunc);
} }
...@@ -1184,7 +1184,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) ...@@ -1184,7 +1184,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev)
iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask); iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask);
indio_dev->active_scan_mask = NULL; indio_dev->active_scan_mask = NULL;
indio_dev->currentmode = INDIO_DIRECT_MODE; iio_dev_opaque->currentmode = INDIO_DIRECT_MODE;
return ret; return ret;
} }
......
...@@ -190,7 +190,9 @@ EXPORT_SYMBOL_GPL(iio_device_id); ...@@ -190,7 +190,9 @@ EXPORT_SYMBOL_GPL(iio_device_id);
*/ */
bool iio_buffer_enabled(struct iio_dev *indio_dev) bool iio_buffer_enabled(struct iio_dev *indio_dev)
{ {
return indio_dev->currentmode struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
return iio_dev_opaque->currentmode
& (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE | & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE |
INDIO_BUFFER_SOFTWARE); INDIO_BUFFER_SOFTWARE);
} }
...@@ -2072,12 +2074,14 @@ EXPORT_SYMBOL_GPL(iio_device_release_direct_mode); ...@@ -2072,12 +2074,14 @@ EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
/** /**
* iio_device_get_current_mode() - helper function providing read-only access to * iio_device_get_current_mode() - helper function providing read-only access to
* the @currentmode variable * the opaque @currentmode variable
* @indio_dev: IIO device structure for device * @indio_dev: IIO device structure for device
*/ */
int iio_device_get_current_mode(struct iio_dev *indio_dev) int iio_device_get_current_mode(struct iio_dev *indio_dev)
{ {
return indio_dev->currentmode; struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
return iio_dev_opaque->currentmode;
} }
EXPORT_SYMBOL_GPL(iio_device_get_current_mode); EXPORT_SYMBOL_GPL(iio_device_get_current_mode);
......
...@@ -444,7 +444,7 @@ static ssize_t iio_trigger_write_current(struct device *dev, ...@@ -444,7 +444,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
int ret; int ret;
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
return -EBUSY; return -EBUSY;
} }
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
* struct iio_dev_opaque - industrial I/O device opaque information * struct iio_dev_opaque - industrial I/O device opaque information
* @indio_dev: public industrial I/O device information * @indio_dev: public industrial I/O device information
* @id: used to identify device internally * @id: used to identify device internally
* @currentmode: operating mode currently in use, may be eventually
* checked by device drivers but should be considered
* read-only as this is a core internal bit
* @driver_module: used to make it harder to undercut users * @driver_module: used to make it harder to undercut users
* @info_exist_lock: lock to prevent use during removal * @info_exist_lock: lock to prevent use during removal
* @trig_readonly: mark the current trigger immutable * @trig_readonly: mark the current trigger immutable
...@@ -36,6 +39,7 @@ ...@@ -36,6 +39,7 @@
*/ */
struct iio_dev_opaque { struct iio_dev_opaque {
struct iio_dev indio_dev; struct iio_dev indio_dev;
int currentmode;
int id; int id;
struct module *driver_module; struct module *driver_module;
struct mutex info_exist_lock; struct mutex info_exist_lock;
......
...@@ -494,9 +494,6 @@ struct iio_buffer_setup_ops { ...@@ -494,9 +494,6 @@ struct iio_buffer_setup_ops {
* also be filed up by the IIO core, as a result of * also be filed up by the IIO core, as a result of
* enabling particular features in the driver * enabling particular features in the driver
* (see iio_triggered_event_setup()). * (see iio_triggered_event_setup()).
* @currentmode: [INTERN] operating mode currently in use, may be
* eventually checked by device drivers but should be
* considered read-only as this is a core internal bit
* @dev: [DRIVER] device structure, should be assigned a parent * @dev: [DRIVER] device structure, should be assigned a parent
* and owner * and owner
* @buffer: [DRIVER] any buffer present * @buffer: [DRIVER] any buffer present
...@@ -523,7 +520,6 @@ struct iio_buffer_setup_ops { ...@@ -523,7 +520,6 @@ struct iio_buffer_setup_ops {
*/ */
struct iio_dev { struct iio_dev {
int modes; int modes;
int currentmode;
struct device dev; struct device dev;
struct iio_buffer *buffer; struct iio_buffer *buffer;
......
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