summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorKurt Borja <kuurtb@gmail.com>2026-01-20 01:20:43 -0500
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2026-01-22 20:53:17 +0000
commit2daee817df13fb539be01a6a8094d52667d402f6 (patch)
tree22ee4dd50726710bfa3514aa05a7c66f76f096eb /include/linux
parentc37ec9d507966a827913f42e06179e3475a00181 (diff)
iio: core: Match iio_device_claim_*() semantics and implementation
Implement iio_device_claim_buffer_mode() fully inline with the use of __iio_dev_mode_lock(), which takes care of sparse annotations. To completely match iio_device_claim_direct() semantics, we need to also change iio_device_claim_buffer_mode() return semantics to usual true/false conditional lock semantics. Additionally, to avoid silently breaking out-of-tree drivers, rename iio_device_claim_buffer_mode() to iio_device_claim_try_buffer_mode(). Reviewed-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Kurt Borja <kuurtb@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/iio/iio.h35
1 files changed, 33 insertions, 2 deletions
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index e263ab5eeccf..36bd14e93a75 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -706,8 +706,39 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
*/
#define iio_device_release_direct(indio_dev) __iio_dev_mode_unlock(indio_dev)
-int iio_device_claim_buffer_mode(struct iio_dev *indio_dev);
-void iio_device_release_buffer_mode(struct iio_dev *indio_dev);
+/**
+ * iio_device_try_claim_buffer_mode() - Keep device in buffer mode
+ * @indio_dev: the iio_dev associated with the device
+ *
+ * If the device is in buffer mode it is guaranteed to stay
+ * that way until iio_device_release_buffer_mode() is called.
+ *
+ * Use with iio_device_release_buffer_mode().
+ *
+ * Returns: true on success, false on failure.
+ */
+static inline bool iio_device_try_claim_buffer_mode(struct iio_dev *indio_dev)
+{
+ __iio_dev_mode_lock(indio_dev);
+
+ if (!iio_buffer_enabled(indio_dev)) {
+ __iio_dev_mode_unlock(indio_dev);
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * iio_device_release_buffer_mode() - releases claim on buffer mode
+ * @indio_dev: the iio_dev associated with the device
+ *
+ * Release the claim. Device is no longer guaranteed to stay
+ * in buffer mode.
+ *
+ * Use with iio_device_try_claim_buffer_mode().
+ */
+#define iio_device_release_buffer_mode(indio_dev) __iio_dev_mode_unlock(indio_dev)
extern const struct bus_type iio_bus_type;