All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Rokosov <DDRokosov@sberdevices.ru>
To: "robh+dt@kernel.org" <robh+dt@kernel.org>,
	"jic23@kernel.org" <jic23@kernel.org>,
	"lars@metafoo.de" <lars@metafoo.de>,
	"andy.shevchenko@gmail.com" <andy.shevchenko@gmail.com>,
	"noname.nuno@gmail.com" <noname.nuno@gmail.com>
Cc: "linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	kernel <kernel@sberdevices.ru>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"rockosov@gmail.com" <rockosov@gmail.com>,
	Dmitry Rokosov <DDRokosov@sberdevices.ru>
Subject: [PATCH v3] iio: trigger: warn about non-registered iio trigger getting attempt
Date: Tue, 7 Jun 2022 18:39:18 +0000	[thread overview]
Message-ID: <20220607183907.20017-1-ddrokosov@sberdevices.ru> (raw)

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>
---
Changes:
v1 -> v2: totally reworked the patch, used trig->list entry instead of
          trig->owner as driver registration indicator.
          It works perfectly for both builtin and built as a module
          drivers.

v2 -> v3: changed WARN() call to WARN_ONCE() to avoid warn spamming
          during deferred probe() as Andy suggested.
---
 drivers/iio/industrialio-trigger.c | 2 ++
 include/linux/iio/trigger.h        | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index f504ed351b3e..d6277e72d515 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -581,6 +581,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;
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h
index 4c69b144677b..03b1d6863436 100644
--- a/include/linux/iio/trigger.h
+++ b/include/linux/iio/trigger.h
@@ -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;
-- 
2.36.0

             reply	other threads:[~2022-06-07 21:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07 18:39 Dmitry Rokosov [this message]
2022-06-16  9:13 ` Dmitry Rokosov
2022-06-18 13:27   ` Jonathan Cameron
2022-06-22 17:51     ` Dmitry Rokosov
2022-06-16 13:59 ` Dmitry Rokosov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220607183907.20017-1-ddrokosov@sberdevices.ru \
    --to=ddrokosov@sberdevices.ru \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=kernel@sberdevices.ru \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=noname.nuno@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=rockosov@gmail.com \
    --subject='Re: [PATCH v3] iio: trigger: warn about non-registered iio trigger getting attempt' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.