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>
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>,
Dmitry Rokosov <DDRokosov@sberdevices.ru>
Subject: [PATCH v1] iio: trigger: warn about non-registered iio trigger getting attempt
Date: Tue, 31 May 2022 18:15:05 +0000 [thread overview]
Message-ID: <20220531181457.26034-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() is added to alarm IIO driver authors who make such
a mistake.
When IIO driver allocates a new IIO trigger, it should register it before
calling get() operation. Otherwise, the next iio_trigger_put() will upset
refcnt balance.
Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
---
include/linux/iio/trigger.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h
index 4c69b144677b..4a008b952710 100644
--- a/include/linux/iio/trigger.h
+++ b/include/linux/iio/trigger.h
@@ -93,6 +93,15 @@ 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);
+
+ /*
+ * If driver hasn't called iio_trigger_register() before and trig->owner
+ * wasn't initialized properly, trigger will have wrong number of users
+ */
+ WARN(!trig->owner,
+ "Ignore module getting for non-registered iio trigger %s\n",
+ trig->name);
+
__module_get(trig->owner);
return trig;
--
2.36.0
next reply other threads:[~2022-05-31 18:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 18:15 Dmitry Rokosov [this message]
2022-05-31 18:57 ` [PATCH v1] iio: trigger: warn about non-registered iio trigger getting attempt Dmitry Rokosov
2022-06-01 8:47 ` Nuno Sá
2022-06-01 10:33 ` Dmitry Rokosov
2022-06-01 13:09 ` Nuno Sá
2022-06-01 18:03 ` 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=20220531181457.26034-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=robh+dt@kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).