[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220531185729.z6246gexteyo4xmd@CAB-WSD-L081021.sigma.sbrf.ru>
Date: Tue, 31 May 2022 18:57:30 +0000
From: Dmitry Rokosov <DDRokosov@...rdevices.ru>
To: "robh+dt@...nel.org" <robh+dt@...nel.org>,
"jic23@...nel.org" <jic23@...nel.org>,
"lars@...afoo.de" <lars@...afoo.de>,
"andy.shevchenko@...il.com" <andy.shevchenko@...il.com>
CC: "linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
kernel <kernel@...rdevices.ru>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v1] iio: trigger: warn about non-registered iio trigger
getting attempt
Hi Jonathan,
I have one question about a cases when trigger owner is builtin module.
In the such cases trig->owner == null, because THIS_MODULE equals to
null. How do you think, should we take into account such situations?
IMHO we have to take in and save this information to trig_info during
trigger allocation call. For example we can check THIS_MODULE from the
iio_trigger_alloc(), save builtin status to trig_info and look into it
from iio_trigger_get().
On Tue, May 31, 2022 at 06:15:05PM +0000, Dmitry Rokosov wrote:
> 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@...rdevices.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
--
Thank you,
Dmitry
Powered by blists - more mailing lists