Skip to content

Commit f38bc92

Browse files
larsclausenjic23
authored andcommitted
staging:iio:sysfs-trigger: Use irq_work to properly active trigger
Since iio_trigger_poll() calls generic_handle_irq() it need to be called from hardirq context. The sysfs trigger is kicked from userspace, so it is obviously not possible to fulfill this requirement by calling iio_trigger_poll directly. As a workaround commit 1f78568 ("staging:iio:trigger sysfs userspace trigger rework.") added iio_trigger_poll_chained() which uses handle_nested_irq instead of generic_handle_irq. This in itself is a hack and only works by chance. handle_nested_irq is intended to be called from the threaded interrupt handler of the parent IRQ. Using handle_nested_irq is also problematic since it will only call the threaded handler of the IRQ. But quite a few IIO drivers rely on their hardirq handler being called or undefined behaviour will occur. This patch uses the irq_work framework to schedule the call to iio_trigger_poll() from hardirq context, which fixes the issues described above. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent ed5514c commit f38bc92

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎drivers/staging/iio/trigger/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ config IIO_GPIO_TRIGGER
2121
config IIO_SYSFS_TRIGGER
2222
tristate "SYSFS trigger"
2323
depends on SYSFS
24+
depends on HAVE_IRQ_WORK
25+
select IRQ_WORK
2426
help
2527
Provides support for using SYSFS entry as IIO triggers.
2628
If unsure, say N (but it's safe to say "Y").

‎drivers/staging/iio/trigger/iio-trig-sysfs.c‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#include <linux/platform_device.h>
1111
#include <linux/slab.h>
1212
#include <linux/list.h>
13+
#include <linux/irq_work.h>
1314

1415
#include <linux/iio/iio.h>
1516
#include <linux/iio/trigger.h>
1617

1718
struct iio_sysfs_trig {
1819
struct iio_trigger *trig;
20+
struct irq_work work;
1921
int id;
2022
struct list_head l;
2123
};
@@ -89,11 +91,21 @@ static struct device iio_sysfs_trig_dev = {
8991
.release = &iio_trigger_sysfs_release,
9092
};
9193

94+
static void iio_sysfs_trigger_work(struct irq_work *work)
95+
{
96+
struct iio_sysfs_trig *trig = container_of(work, struct iio_sysfs_trig,
97+
work);
98+
99+
iio_trigger_poll(trig->trig, 0);
100+
}
101+
92102
static ssize_t iio_sysfs_trigger_poll(struct device *dev,
93103
struct device_attribute *attr, const char *buf, size_t count)
94104
{
95105
struct iio_trigger *trig = to_iio_trigger(dev);
96-
iio_trigger_poll_chained(trig, 0);
106+
struct iio_sysfs_trig *sysfs_trig = trig->private_data;
107+
108+
irq_work_queue(&sysfs_trig->work);
97109

98110
return count;
99111
}
@@ -148,6 +160,9 @@ static int iio_sysfs_trigger_probe(int id)
148160
t->trig->dev.groups = iio_sysfs_trigger_attr_groups;
149161
t->trig->ops = &iio_sysfs_trigger_ops;
150162
t->trig->dev.parent = &iio_sysfs_trig_dev;
163+
t->trig->private_data = t;
164+
165+
init_irq_work(&t->work, iio_sysfs_trigger_work);
151166

152167
ret = iio_trigger_register(t->trig);
153168
if (ret)

0 commit comments

Comments
 (0)