From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, linux@analog.com,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Radu Sabau" <radu.sabau@analog.com>,
"Song Qiang" <songqiang1304521@gmail.com>,
"Siratul Islam" <siratul.islam@linux.dev>,
"Alisa-Dariana Roman" <alisa.roman@analog.com>,
"Ramona Bolboaca" <ramona.bolboaca@analog.com>,
"Jean-Baptiste Maneyrol" <jean-baptiste.maneyrol@tdk.com>,
"Jonathan Cameron" <jonathan.cameron@oss.qualcomm.com>
Subject: Re: [PATCH 09/15] iio: humidity: hts221: use iio_trigger_set_default_immutable()
Date: Mon, 30 Nov 2026 09:21:30 +0100 [thread overview]
Message-ID: <aw0yChc8pCeot1jI@lore-desk> (raw)
In-Reply-To: <20261130-messing-immutable3323-v1-9-f44aa3082603@oss.qualcomm.com>
[-- Attachment #1: Type: text/plain, Size: 3136 bytes --]
On Nov 30, Jonathan Cameron wrote:
> From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
>
> Use iio_trigger_set_default_immutable() rather than taking a reference
> to the trigger in probe(). The IIO core now takes the reference during
> iio_device_register(), so it is not leaked if probe() fails after the
> trigger is set up.
>
> Previously the reference was taken even if devm_iio_trigger_register()
> failed, hitting the WARN_ONCE() in iio_trigger_get() for an unregistered
> trigger. Return the error before setting the default trigger instead.
>
> The driver only accepts its own data ready trigger and used
> hts221_validate_trigger() to enforce that. That callback is equivalent
> to iio_validate_own_trigger(). An immutable trigger gives the same
> guarantee.
>
> Potential userspace ABI impact. Previously the trigger could be cleared
> by writing an empty string, or any name that is not a registered trigger,
> to current_trigger. That now fails with -EPERM, as does selecting a
> different trigger, which previously failed with -EINVAL. Writing the name
> of the current trigger still succeeds. Userspace software may exist that
> is dependent on the tear down behavior however that userspace would not
> have worked with the existing immutable triggers so needs fixing anyway.
>
> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Reviewed-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/iio/humidity/hts221_buffer.c | 6 +++---
> drivers/iio/humidity/hts221_core.c | 9 ---------
> 2 files changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/iio/humidity/hts221_buffer.c b/drivers/iio/humidity/hts221_buffer.c
> index ee81d5e73ab5..5e6f9c9eb08d 100644
> --- a/drivers/iio/humidity/hts221_buffer.c
> +++ b/drivers/iio/humidity/hts221_buffer.c
> @@ -134,10 +134,10 @@ int hts221_allocate_trigger(struct iio_dev *iio_dev)
> hw->trig->ops = &hts221_trigger_ops;
>
> err = devm_iio_trigger_register(hw->dev, hw->trig);
> + if (err)
> + return err;
>
> - iio_dev->trig = iio_trigger_get(hw->trig);
> -
> - return err;
> + return iio_trigger_set_default_immutable(iio_dev, hw->trig);
> }
>
> static int hts221_buffer_preenable(struct iio_dev *iio_dev)
> diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
> index 47a10884d812..2b5e71aa7b2e 100644
> --- a/drivers/iio/humidity/hts221_core.c
> +++ b/drivers/iio/humidity/hts221_core.c
> @@ -522,19 +522,10 @@ static int hts221_write_raw(struct iio_dev *iio_dev,
> return ret;
> }
>
> -static int hts221_validate_trigger(struct iio_dev *iio_dev,
> - struct iio_trigger *trig)
> -{
> - struct hts221_hw *hw = iio_priv(iio_dev);
> -
> - return hw->trig == trig ? 0 : -EINVAL;
> -}
> -
> static const struct iio_info hts221_info = {
> .read_raw = hts221_read_raw,
> .write_raw = hts221_write_raw,
> .read_avail = hts221_read_avail,
> - .validate_trigger = hts221_validate_trigger,
> };
>
> static const unsigned long hts221_scan_masks[] = {0x3, 0x0};
>
> --
> 2.56.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-11-30 8:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 0:13 [PATCH 00/15] IIO: Immutable triggers. Close leaks in registration and use more widely Jonathan Cameron
2026-11-30 0:13 ` [PATCH 01/15] iio: core: add iio_trigger_set_default_immutable() Jonathan Cameron
2026-11-30 0:13 ` [PATCH 02/15] iio: adc: dln2-adc: use iio_trigger_set_default_immutable() Jonathan Cameron
2026-11-30 0:13 ` [PATCH 03/15] iio: core: allow writing the current trigger when it is immutable Jonathan Cameron
2026-11-30 0:13 ` [PATCH 04/15] iio: adc: ad7606: use iio_trigger_set_default_immutable() Jonathan Cameron
2026-11-30 0:13 ` [PATCH 05/15] iio: adc: ad4691: " Jonathan Cameron
2026-11-30 0:13 ` [PATCH 06/15] iio: proximity: vl53l0x-i2c: " Jonathan Cameron
2026-11-30 0:13 ` [PATCH 07/15] iio: proximity: vl53l1x-i2c: " Jonathan Cameron
2026-11-30 0:13 ` [PATCH 08/15] iio: humidity: hts221: use iio_dev->trig in iio_trigger_notify_done() Jonathan Cameron
2026-11-30 8:20 ` Lorenzo Bianconi
2026-11-30 0:13 ` [PATCH 09/15] iio: humidity: hts221: use iio_trigger_set_default_immutable() Jonathan Cameron
2026-11-30 8:21 ` Lorenzo Bianconi [this message]
2026-11-30 0:13 ` [PATCH 10/15] iio: adc: ad_sigma_delta: use an immutable default trigger Jonathan Cameron
2026-11-30 0:13 ` [PATCH 11/15] iio: adc: ad_sigma_delta: drop ad_sd_validate_trigger() Jonathan Cameron
2026-11-30 0:13 ` [PATCH 12/15] iio: imu: inv_mpu6050: use iio_trigger_set_default_immutable() Jonathan Cameron
2026-11-30 0:13 ` [PATCH 13/15] iio: core: add devm_iio_trigger_set_immutable() Jonathan Cameron
2026-11-30 0:13 ` [PATCH 14/15] iio: potentiostat: lmp91000: use devm managed probe Jonathan Cameron
2026-11-30 0:13 ` [PATCH 15/15] iio: potentiostat: lmp91000: undo immutable trigger on unbind Jonathan Cameron
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=aw0yChc8pCeot1jI@lore-desk \
--to=lorenzo@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=alisa.roman@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jean-baptiste.maneyrol@tdk.com \
--cc=jic23@kernel.org \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux@analog.com \
--cc=nuno.sa@analog.com \
--cc=radu.sabau@analog.com \
--cc=ramona.bolboaca@analog.com \
--cc=siratul.islam@linux.dev \
--cc=songqiang1304521@gmail.com \
/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