iio: trigger: warn about non-registered iio trigger getting attempt
authorDmitry Rokosov <DDRokosov@sberdevices.ru>
Tue, 7 Jun 2022 18:39:18 +0000 (18:39 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 18 Jun 2022 13:26:17 +0000 (14:26 +0100)
As a part of patch series about wrong trigger register() and get()
calls order in the some IIO drivers trigger initialization path:

https://lore.kernel.org/all/20220524181150.9240-1-ddrokosov@sberdevices.ru/

runtime WARN_ONCE() is added to alarm IIO driver authors who make such
a mistake.

When an IIO driver allocates a new IIO trigger, it should register it
before calling the get() operation. In other words, each IIO driver
must abide by IIO trigger alloc()/register()/get() calls order.

Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
Link: https://lore.kernel.org/r/20220607183907.20017-1-ddrokosov@sberdevices.ru
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-trigger.c
include/linux/iio/trigger.h

index d89bf90..26d610d 100644 (file)
@@ -576,6 +576,8 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
        if (trig->name == NULL)
                goto free_descs;
 
+       INIT_LIST_HEAD(&trig->list);
+
        trig->subirq_chip.name = trig->name;
        trig->subirq_chip.irq_mask = &iio_trig_subirqmask;
        trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask;
index 4c69b14..03b1d68 100644 (file)
@@ -93,6 +93,11 @@ static inline void iio_trigger_put(struct iio_trigger *trig)
 static inline struct iio_trigger *iio_trigger_get(struct iio_trigger *trig)
 {
        get_device(&trig->dev);
+
+       WARN_ONCE(list_empty(&trig->list),
+                 "Getting non-registered iio trigger %s is prohibited\n",
+                 trig->name);
+
        __module_get(trig->owner);
 
        return trig;