public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: trigger: Add validation to reject devices requiring top half
@ 2025-05-03 19:00 Gyeyoung Baek
  2025-05-04 11:15 ` Gyeyoung Baek
  2025-05-04 14:24 ` Jonathan Cameron
  0 siblings, 2 replies; 9+ messages in thread
From: Gyeyoung Baek @ 2025-05-03 19:00 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
  Cc: Gyeyoung Baek, linux-iio, linux-kernel

Some device drivers implement top-half handler,
which is not compatible with threaded handler trigger.
This patch adds a validation function to reject such devices,
allowing only iio_pollfunc_store_time().

Signed-off-by: Gyeyoung Baek <gye976@gmail.com>
---
 drivers/iio/trigger/iio-trig-loop.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/trigger/iio-trig-loop.c b/drivers/iio/trigger/iio-trig-loop.c
index 7aaed0611899..a37615567a6c 100644
--- a/drivers/iio/trigger/iio-trig-loop.c
+++ b/drivers/iio/trigger/iio-trig-loop.c
@@ -7,18 +7,12 @@
  *
  * Note this is still rather experimental and may eat babies.
  *
- * Todo
- * * Protect against connection of devices that 'need' the top half
- *   handler.
- * * Work out how to run top half handlers in this context if it is
- *   safe to do so (timestamp grabbing for example)
- *
  * Tested against a max1363. Used about 33% cpu for the thread and 20%
  * for generic_buffer piping to /dev/null. Watermark set at 64 on a 128
  * element kfifo buffer.
  */
 
-#include <linux/kernel.h>
+#include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
@@ -27,8 +21,10 @@
 #include <linux/freezer.h>
 
 #include <linux/iio/iio.h>
-#include <linux/iio/trigger.h>
 #include <linux/iio/sw_trigger.h>
+#include <linux/iio/trigger.h>
+
+#include "linux/iio/trigger_consumer.h"
 
 struct iio_loop_info {
 	struct iio_sw_trigger swt;
@@ -71,8 +67,25 @@ static int iio_loop_trigger_set_state(struct iio_trigger *trig, bool state)
 	return 0;
 }
 
+/*
+ * Protect against connection of devices that 'need' the top half
+ * handler.
+ */
+static int iio_loop_trigger_validate_device(struct iio_trigger *trig,
+						struct iio_dev *indio_dev)
+{
+	struct iio_poll_func *pf = indio_dev->pollfunc;
+
+	/* Only iio timestamp grabbing is allowed. */
+	if (pf->h && pf->h != iio_pollfunc_store_time)
+		return -EINVAL;
+
+	return 0;
+}
+
 static const struct iio_trigger_ops iio_loop_trigger_ops = {
 	.set_trigger_state = iio_loop_trigger_set_state,
+	.validate_device = iio_loop_trigger_validate_device,
 };
 
 static struct iio_sw_trigger *iio_trig_loop_probe(const char *name)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-05-19 14:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-03 19:00 [PATCH] iio: trigger: Add validation to reject devices requiring top half Gyeyoung Baek
2025-05-04 11:15 ` Gyeyoung Baek
2025-05-04 14:24 ` Jonathan Cameron
2025-05-06 15:55   ` Gyeyoung Baek
2025-05-07 19:40     ` Jonathan Cameron
2025-05-10 19:26       ` Gyeyoung Baek
2025-05-11 15:47       ` Gyeyoung Baek
2025-05-15  7:49         ` Jonathan Cameron
2025-05-19 14:34           ` Gyeyoung Baek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox