[PATCH v2 2/6] iio: light: stk3310: Implement vdd supply and power it off during suspend

Jonathan Cameron jic23 at kernel.org
Sun Apr 28 09:45:09 PDT 2024


On Wed, 24 Apr 2024 18:20:41 +0300
Andy Shevchenko <andy.shevchenko at gmail.com> wrote:

> On Wed, Apr 24, 2024 at 3:59 PM Ondřej Jirman <megi at xff.cz> wrote:
> > On Wed, Apr 24, 2024 at 02:16:06AM GMT, Andy Shevchenko wrote:  
> > > On Wed, Apr 24, 2024 at 1:41 AM Aren Moynihan <aren at peacevolution.org> wrote:  
> 
> ...
> 
> > > >         ret = stk3310_init(indio_dev);
> > > >         if (ret < 0)
> > > > -               return ret;
> > > > +               goto err_vdd_disable;  
> > >
> > > This is wrong. You will have the regulator being disabled _before_
> > > IRQ. Note, that the original code likely has a bug which sets states
> > > before disabling IRQ and removing a handler.  
> >
> > How so? stk3310_init is called before enabling the interrupt.  
> 
> Exactly, IRQ is registered with devm and hence the error path and
> remove stages will got it in a wrong order.
> 
> > Original code has a bug that IRQ is enabled before registering the
> > IIO device,  
> 
> Indeed, but this is another bug.

It shouldn't be.  A device that produces interrupts before we have
told it to is a) buggy, b) almost certainly already had it's interrupt
masked due to spurious interrupt detection.

Definitely don't want to do it in the opposite order where userspace
could turn the device on and have it start generating interrupts before
the irq is registered.  I'd rather assume non buggy hardware (and
that if there are bugs, the normal protections kick in) than
introduce a race into the software. 

> 
> > so if IRQ is triggered before registration, iio_push_event
> > from IRQ handler may be called on a not yet registered IIO device.
> >
> > Never saw it happen, though. :)  
> 
> Because nobody cares enough to enable DEBUG_SHIRQ

In most devices there is a status register and we should be
doing nothing unless that is set.  Interestingly this device either
doesn't have one or the driver doesn't read it - it reads a flag only
and so will always push an event.  Such a register read doesn't require
the IIO device registration to be complete.

There are corner cases where that isn't true that need to manually
mask at the host but they are rare.

There is also a basic level of defense in iio_push_event() against
that being called when the event interface is not registered.

Jonathan


> 




More information about the linux-arm-kernel mailing list