public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: st_sensors: fix trigger allocation
@ 2026-02-28 17:11 Aleksandrs Vinarskis
  2026-02-28 19:22 ` David Lechner
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Aleksandrs Vinarskis @ 2026-02-28 17:11 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, stable

Current hardcoded name prevents adding multiple st-sensors devices
on the same platform. Fix by aligning trigger name with other drivers.

Signed-off-by: Aleksandrs Vinarskis <alex@vinarskis.com>
---
Some platforms such as Dell XPS 9345 contains multiple accelerometers.
Fix st_sensors that currently only allows one device at the time.
---
 drivers/iio/common/st_sensors/st_sensors_trigger.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
index 8a8ab688d7980f6dd43c660f90a0eba32c38388b..3b5615d1b6dd66ee0af6ccc83eb2fbd7b2c64d29 100644
--- a/drivers/iio/common/st_sensors/st_sensors_trigger.c
+++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
@@ -124,8 +124,9 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
 	unsigned long irq_trig;
 	int err;
 
-	sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
-					     indio_dev->name);
+	sdata->trig = devm_iio_trigger_alloc(parent, "%s-dev%d",
+					     indio_dev->name,
+					     iio_device_id(indio_dev));
 	if (sdata->trig == NULL) {
 		dev_err(parent, "failed to allocate iio trigger.\n");
 		return -ENOMEM;

---
base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
change-id: 20260228-st-iio-trigger-8ee1f219b566

Best regards,
-- 
Aleksandrs Vinarskis <alex@vinarskis.com>


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: st_sensors: fix trigger allocation
  2026-02-28 17:11 [PATCH] iio: st_sensors: fix trigger allocation Aleksandrs Vinarskis
@ 2026-02-28 19:22 ` David Lechner
  2026-03-01 10:50   ` Aleksandrs Vinarskis
  2026-03-01 13:05 ` Greg KH
  2026-03-02  8:15 ` Andy Shevchenko
  2 siblings, 1 reply; 6+ messages in thread
From: David Lechner @ 2026-02-28 19:22 UTC (permalink / raw)
  To: Aleksandrs Vinarskis, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel, stable

On 2/28/26 11:11 AM, Aleksandrs Vinarskis wrote:
> Current hardcoded name prevents adding multiple st-sensors devices
> on the same platform. Fix by aligning trigger name with other drivers.
> 
> Signed-off-by: Aleksandrs Vinarskis <alex@vinarskis.com>
> ---
> Some platforms such as Dell XPS 9345 contains multiple accelerometers.
> Fix st_sensors that currently only allows one device at the time.
> ---
>  drivers/iio/common/st_sensors/st_sensors_trigger.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> index 8a8ab688d7980f6dd43c660f90a0eba32c38388b..3b5615d1b6dd66ee0af6ccc83eb2fbd7b2c64d29 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> @@ -124,8 +124,9 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
>  	unsigned long irq_trig;
>  	int err;
>  
> -	sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
> -					     indio_dev->name);
> +	sdata->trig = devm_iio_trigger_alloc(parent, "%s-dev%d",
> +					     indio_dev->name,
> +					     iio_device_id(indio_dev));

Is this something that could potentially break userspace? Or are all of these
just "always there" triggers that userspace doesn't have to touch?

>  	if (sdata->trig == NULL) {
>  		dev_err(parent, "failed to allocate iio trigger.\n");
>  		return -ENOMEM;
> 
> ---
> base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
> change-id: 20260228-st-iio-trigger-8ee1f219b566
> 
> Best regards,


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: st_sensors: fix trigger allocation
  2026-02-28 19:22 ` David Lechner
@ 2026-03-01 10:50   ` Aleksandrs Vinarskis
  2026-03-01 11:30     ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Aleksandrs Vinarskis @ 2026-03-01 10:50 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel, stable





On Saturday, February 28th, 2026 at 20:22, David Lechner <dlechner@baylibre.com> wrote:

> On 2/28/26 11:11 AM, Aleksandrs Vinarskis wrote:
> > Current hardcoded name prevents adding multiple st-sensors devices
> > on the same platform. Fix by aligning trigger name with other drivers.
> >
> > Signed-off-by: Aleksandrs Vinarskis <alex@vinarskis.com>
> > ---
> > Some platforms such as Dell XPS 9345 contains multiple accelerometers.
> > Fix st_sensors that currently only allows one device at the time.
> > ---
> >  drivers/iio/common/st_sensors/st_sensors_trigger.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> > index 8a8ab688d7980f6dd43c660f90a0eba32c38388b..3b5615d1b6dd66ee0af6ccc83eb2fbd7b2c64d29 100644
> > --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c
> > +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> > @@ -124,8 +124,9 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
> >  	unsigned long irq_trig;
> >  	int err;
> >
> > -	sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
> > -					     indio_dev->name);
> > +	sdata->trig = devm_iio_trigger_alloc(parent, "%s-dev%d",
> > +					     indio_dev->name,
> > +					     iio_device_id(indio_dev));
> 
> Is this something that could potentially break userspace? Or are all of these
> just "always there" triggers that userspace doesn't have to touch?

I don't see why it would. This simply makes the name of the registered
trigger globally unique, the same way like other drivers already do.
Userspace does care about these but it relies on capabilities as per
my understanding to figure what sensor it is. I have tested it with
`monitor-sensors`, which relies on `iio-sensor-proxy`: in both cases
accelerator device was detected.

Alex

> 
> >  	if (sdata->trig == NULL) {
> >  		dev_err(parent, "failed to allocate iio trigger.\n");
> >  		return -ENOMEM;
> >
> > ---
> > base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
> > change-id: 20260228-st-iio-trigger-8ee1f219b566
> >
> > Best regards,
> 
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: st_sensors: fix trigger allocation
  2026-03-01 10:50   ` Aleksandrs Vinarskis
@ 2026-03-01 11:30     ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2026-03-01 11:30 UTC (permalink / raw)
  To: Aleksandrs Vinarskis
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel, stable

On Sun, 01 Mar 2026 10:50:10 +0000
Aleksandrs Vinarskis <alex@vinarskis.com> wrote:

> On Saturday, February 28th, 2026 at 20:22, David Lechner <dlechner@baylibre.com> wrote:
> 
> > On 2/28/26 11:11 AM, Aleksandrs Vinarskis wrote:  
> > > Current hardcoded name prevents adding multiple st-sensors devices
> > > on the same platform. Fix by aligning trigger name with other drivers.
> > >
> > > Signed-off-by: Aleksandrs Vinarskis <alex@vinarskis.com>
> > > ---
> > > Some platforms such as Dell XPS 9345 contains multiple accelerometers.
> > > Fix st_sensors that currently only allows one device at the time.
> > > ---
> > >  drivers/iio/common/st_sensors/st_sensors_trigger.c | 5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> > > index 8a8ab688d7980f6dd43c660f90a0eba32c38388b..3b5615d1b6dd66ee0af6ccc83eb2fbd7b2c64d29 100644
> > > --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c
> > > +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> > > @@ -124,8 +124,9 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
> > >  	unsigned long irq_trig;
> > >  	int err;
> > >
> > > -	sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
> > > -					     indio_dev->name);
> > > +	sdata->trig = devm_iio_trigger_alloc(parent, "%s-dev%d",
> > > +					     indio_dev->name,
> > > +					     iio_device_id(indio_dev));  
> > 
> > Is this something that could potentially break userspace? Or are all of these
> > just "always there" triggers that userspace doesn't have to touch?  
> 
> I don't see why it would. This simply makes the name of the registered
> trigger globally unique, the same way like other drivers already do.
> Userspace does care about these but it relies on capabilities as per
> my understanding to figure what sensor it is. I have tested it with
> `monitor-sensors`, which relies on `iio-sensor-proxy`: in both cases
> accelerator device was detected.

Most userspace hopefully relies on the relationship between the trigger
and the device (basically that they have the same parent) rather than the
explicit name, but it is always possible someone does have a script using
this name.  I don't think these drivers are setting a default (which is
reasonable as IIRC they have always supported other triggers and people
have a habit of not wiring the interrupts up).

So David's right that this could cause a user visible regression. 
We might get away with it though.

Today, iio_trigger_acquire_by_name() just matches the first one with a
given string.   This isn't a fast path so we could be a little cleverer
and add a heuristic that first tries to find a trigger with that name
and a common parent device.  If that fails, it just falls back to the
current approach?  That way it would do the right thing in cases like
the one seen here, but we'd not be able to have one ST sensor trigger
off a specific other on - not sure that's a big loss however as it
is fairly unusual to do that for similar sensor types.

What do people think?  Alex, would that work for your case?

Jonathan



> 
> Alex
> 
> >   
> > >  	if (sdata->trig == NULL) {
> > >  		dev_err(parent, "failed to allocate iio trigger.\n");
> > >  		return -ENOMEM;
> > >
> > > ---
> > > base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
> > > change-id: 20260228-st-iio-trigger-8ee1f219b566
> > >
> > > Best regards,  
> > 
> >   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: st_sensors: fix trigger allocation
  2026-02-28 17:11 [PATCH] iio: st_sensors: fix trigger allocation Aleksandrs Vinarskis
  2026-02-28 19:22 ` David Lechner
@ 2026-03-01 13:05 ` Greg KH
  2026-03-02  8:15 ` Andy Shevchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2026-03-01 13:05 UTC (permalink / raw)
  To: Aleksandrs Vinarskis
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel, stable

On Sat, Feb 28, 2026 at 06:11:02PM +0100, Aleksandrs Vinarskis wrote:
> Current hardcoded name prevents adding multiple st-sensors devices
> on the same platform. Fix by aligning trigger name with other drivers.
> 
> Signed-off-by: Aleksandrs Vinarskis <alex@vinarskis.com>
> ---
> Some platforms such as Dell XPS 9345 contains multiple accelerometers.
> Fix st_sensors that currently only allows one device at the time.
> ---
>  drivers/iio/common/st_sensors/st_sensors_trigger.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> index 8a8ab688d7980f6dd43c660f90a0eba32c38388b..3b5615d1b6dd66ee0af6ccc83eb2fbd7b2c64d29 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> @@ -124,8 +124,9 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
>  	unsigned long irq_trig;
>  	int err;
>  
> -	sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
> -					     indio_dev->name);
> +	sdata->trig = devm_iio_trigger_alloc(parent, "%s-dev%d",
> +					     indio_dev->name,
> +					     iio_device_id(indio_dev));
>  	if (sdata->trig == NULL) {
>  		dev_err(parent, "failed to allocate iio trigger.\n");
>  		return -ENOMEM;
> 
> ---
> base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
> change-id: 20260228-st-iio-trigger-8ee1f219b566
> 
> Best regards,
> -- 
> Aleksandrs Vinarskis <alex@vinarskis.com>
> 
> 

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: st_sensors: fix trigger allocation
  2026-02-28 17:11 [PATCH] iio: st_sensors: fix trigger allocation Aleksandrs Vinarskis
  2026-02-28 19:22 ` David Lechner
  2026-03-01 13:05 ` Greg KH
@ 2026-03-02  8:15 ` Andy Shevchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-03-02  8:15 UTC (permalink / raw)
  To: Aleksandrs Vinarskis
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel, stable

On Sat, Feb 28, 2026 at 06:11:02PM +0100, Aleksandrs Vinarskis wrote:
> Current hardcoded name prevents adding multiple st-sensors devices
> on the same platform. Fix by aligning trigger name with other drivers.

...

> -	sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
> -					     indio_dev->name);
> +	sdata->trig = devm_iio_trigger_alloc(parent, "%s-dev%d",
> +					     indio_dev->name,
> +					     iio_device_id(indio_dev));

I think you need to split this to more complex approach, id est:
- register the first one as with the current name
- use indexed variant for the rest

It will give something like %s-trigger, %s-trigger1 (if start from 0),
and so on. This way you won't break user space when it was defined for
a single trigger.

(Yes, I have read all emails in this thread as of time of replying to it.)

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-02  8:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-28 17:11 [PATCH] iio: st_sensors: fix trigger allocation Aleksandrs Vinarskis
2026-02-28 19:22 ` David Lechner
2026-03-01 10:50   ` Aleksandrs Vinarskis
2026-03-01 11:30     ` Jonathan Cameron
2026-03-01 13:05 ` Greg KH
2026-03-02  8:15 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox