[PATCH] iio: core: make iio_device_claim_direct_mode() __must_check

From: David Lechner
Date: Wed Oct 02 2024 - 11:35:47 EST


Add __must_check attribute to iio_device_claim_direct_mode().

Since we have now DEFINE_GUARD(iio_claim_direct, ...,
iio_device_claim_direct_mode, ...), it is possible to write:

guard(iio_claim_direct)(indio_dev);

This would be a bug, since the return value is not checked. Adding
__must_check to iio_device_claim_direct_mode() makes the compiler emit
a warning for the above code.

Suggested-by: Dan Williams <dan.j.williams@xxxxxxxxx>
Signed-off-by: David Lechner <dlechner@xxxxxxxxxxxx>
---
This comes from the suggestion at the end of [1]. It seems like a
reasonable thing to do regardless if the other series works out or not,
so submitting it separately.

[1]: https://lore.kernel.org/all/66fcac2dbde60_964f229426@xxxxxxxxxxxxxxxxxxxxxxxxx.notmuch/
---
include/linux/iio/iio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 18779b631e90..2dc6470d20a4 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -659,7 +659,7 @@ 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);
+__must_check int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
void iio_device_release_direct_mode(struct iio_dev *indio_dev);

/*

---
base-commit: 431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e
change-id: 20241002-iio-must-check-claim-direct-e6988a195368

Best regards,
--
David Lechner <dlechner@xxxxxxxxxxxx>