diff mbox series

[37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.

Message ID 20250331121317.1694135-38-jic23@kernel.org (mailing list archive)
State New
Headers show
Series IIO: Sparse friendly claim of direct mode (the rest) | expand

Commit Message

Jonathan Cameron March 31, 2025, 12:13 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Now there are no remaining callers of iio_device_claim_direct_mode()
and iio_device_release_direct_mode() rename those functions to ensure
they are no used in new drivers. Also make them now return booleans
in line with the sparse friendly static inline wrappers.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-core.c | 28 ++++++++++++++++------------
 include/linux/iio/iio.h         | 10 ++++------
 2 files changed, 20 insertions(+), 18 deletions(-)

Comments

Andy Shevchenko March 31, 2025, 1:41 p.m. UTC | #1
On Mon, Mar 31, 2025 at 3:17 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Now there are no remaining callers of iio_device_claim_direct_mode()
> and iio_device_release_direct_mode() rename those functions to ensure
> they are no used in new drivers. Also make them now return booleans

not used

> in line with the sparse friendly static inline wrappers.

...

>  /**
> - * iio_device_claim_direct_mode - Keep device in direct mode
> + * __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_mode() is called.
> + * that way until __iio_device_release_direct() is called.
>   *
> - * Use with iio_device_release_direct_mode()
> + * Use with __iio_device_release_direct().
>   *
> - * Returns: 0 on success, -EBUSY on failure.
> + * Drivers should only call iio_device_claim_direct()

Missed period.

> + * Returns: true on success, false on failure.
>   */

...

> -EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
> +EXPORT_SYMBOL_GPL(__iio_device_claim_direct);

Can we move it to the namespace while at it?

...

>  /**
> - * iio_device_release_direct_mode - releases claim on direct mode
> + * __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_mode()
> + * Drivers should only call iio_device_release_direct()

Missed period.

> + * Use with __iio_device_claim_direct()
>   */

...

> -EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
> +EXPORT_SYMBOL_GPL(__iio_device_release_direct);

Namespace?
Note, the good outcome of the namespace is that we can easily see who
(ab)uses these... OTOH, there are static inline functions in the
header, which provokes this to add MODULE_IMPORT_NS() into the header
as well. That said, perhaps also get rid of static inliners and have
them to be real functions?
David Lechner March 31, 2025, 2:07 p.m. UTC | #2
On 3/31/25 8:41 AM, Andy Shevchenko wrote:


> That said, perhaps also get rid of static inliners and have
> them to be real functions?
> 

That requires fixing sparse first. It doesn't currently support __cond_acquires().
So we are suck with static inline until then.

longer explanation: https://lore.kernel.org/linux-iio/20250209180624.701140-1-jic23@kernel.org/
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index c9955a1c1090..c1921b55cfc5 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -2157,17 +2157,19 @@  int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
 EXPORT_SYMBOL_GPL(__devm_iio_device_register);
 
 /**
- * iio_device_claim_direct_mode - Keep device in direct mode
+ * __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_mode() is called.
+ * that way until __iio_device_release_direct() is called.
  *
- * Use with iio_device_release_direct_mode()
+ * Use with __iio_device_release_direct().
  *
- * Returns: 0 on success, -EBUSY on failure.
+ * Drivers should only call iio_device_claim_direct()
+ *
+ * Returns: true on success, false on failure.
  */
-int iio_device_claim_direct_mode(struct iio_dev *indio_dev)
+bool __iio_device_claim_direct(struct iio_dev *indio_dev)
 {
 	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 
@@ -2175,26 +2177,28 @@  int iio_device_claim_direct_mode(struct iio_dev *indio_dev)
 
 	if (iio_buffer_enabled(indio_dev)) {
 		mutex_unlock(&iio_dev_opaque->mlock);
-		return -EBUSY;
+		return false;
 	}
-	return 0;
+	return true;
 }
-EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
+EXPORT_SYMBOL_GPL(__iio_device_claim_direct);
 
 /**
- * iio_device_release_direct_mode - releases claim on direct mode
+ * __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_mode()
+ * Drivers should only call iio_device_release_direct()
+ *
+ * Use with __iio_device_claim_direct()
  */
-void iio_device_release_direct_mode(struct iio_dev *indio_dev)
+void __iio_device_release_direct(struct iio_dev *indio_dev)
 {
 	mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock);
 }
-EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
+EXPORT_SYMBOL_GPL(__iio_device_release_direct);
 
 /**
  * iio_device_claim_buffer_mode - Keep device in buffer mode
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 07a0e8132e88..638cf2420fbd 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -659,8 +659,8 @@  void iio_device_unregister(struct iio_dev *indio_dev);
 int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
 			       struct module *this_mod);
 int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
-int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
-void iio_device_release_direct_mode(struct iio_dev *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
@@ -671,9 +671,7 @@  void iio_device_release_direct_mode(struct iio_dev *indio_dev);
  */
 static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
 {
-	int ret = iio_device_claim_direct_mode(indio_dev);
-
-	if (ret)
+	if (!__iio_device_claim_direct(indio_dev))
 		return false;
 
 	__acquire(iio_dev);
@@ -683,7 +681,7 @@  static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
 
 static inline void iio_device_release_direct(struct iio_dev *indio_dev)
 {
-	iio_device_release_direct_mode(indio_dev);
+	__iio_device_release_direct(indio_dev);
 	__release(indio_dev);
 }