summaryrefslogtreecommitdiff
path: root/include/linux/iio
diff options
context:
space:
mode:
authorKurt Borja <kuurtb@gmail.com>2026-01-20 01:20:42 -0500
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2026-01-22 20:53:17 +0000
commitc37ec9d507966a827913f42e06179e3475a00181 (patch)
treebe7993e0348a805f77e6fd018c11c6d6260dc0d6 /include/linux/iio
parent88fd1f90792411226f49e5f285bf3faca5ac970b (diff)
downloadlwn-c37ec9d507966a827913f42e06179e3475a00181.tar.gz
lwn-c37ec9d507966a827913f42e06179e3475a00181.zip
iio: core: Refactor iio_device_claim_direct() implementation
In order to eventually unify the locking API, implement iio_device_claim_direct() fully inline, with the use of __iio_dev_mode_lock(), which takes care of sparse annotations. 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/iio')
-rw-r--r--include/linux/iio/iio.h40
1 files changed, 28 insertions, 12 deletions
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index aecda887d833..e263ab5eeccf 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -664,31 +664,47 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev);
void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev);
-bool __iio_device_claim_direct(struct iio_dev *indio_dev);
-void __iio_device_release_direct(struct iio_dev *indio_dev);
/*
* Helper functions that allow claim and release of direct mode
* in a fashion that doesn't generate many false positives from sparse.
* Note this must remain static inline in the header so that sparse
- * can see the __acquire() marking. Revisit when sparse supports
- * __cond_acquires()
+ * can see the __acquires() and __releases() annotations.
+ */
+
+/**
+ * iio_device_claim_direct() - Keep device in direct mode
+ * @indio_dev: the iio_dev associated with the device
+ *
+ * If the device is in direct mode it is guaranteed to stay
+ * that way until iio_device_release_direct() is called.
+ *
+ * Use with iio_device_release_direct().
+ *
+ * Returns: true on success, false on failure.
*/
static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
{
- if (!__iio_device_claim_direct(indio_dev))
- return false;
+ __iio_dev_mode_lock(indio_dev);
- __acquire(iio_dev);
+ if (iio_buffer_enabled(indio_dev)) {
+ __iio_dev_mode_unlock(indio_dev);
+ return false;
+ }
return true;
}
-static inline void iio_device_release_direct(struct iio_dev *indio_dev)
-{
- __iio_device_release_direct(indio_dev);
- __release(indio_dev);
-}
+/**
+ * iio_device_release_direct() - Releases claim on direct mode
+ * @indio_dev: the iio_dev associated with the device
+ *
+ * Release the claim. Device is no longer guaranteed to stay
+ * in direct mode.
+ *
+ * Use with iio_device_claim_direct().
+ */
+#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);