Re: [RFC PATCH] i2c: remove use of in_atomic()

Peter Zijlstra
2019-04-01T13:42:24Z

On Mon, Apr 01, 2019 at 01:54:14PM +0200, Wolfram Sang wrote:
>
> > > "This matches the use cases for atomic I2C transfers I have seen so far:
> > > very late communication (mostly to a PMIC) to powerdown or reboot the
> > > system."
> >
> > Ah, sorry, I missed that.
> >
> > > And yes, I would never recommend a HW design to use I2C for shutting
> > > down/rebooting. But such HW is out there.
> >
> > Can we then make the whole thing conditional on:
> >
> > system_state > SYSTEM_RUNNING
> >
> > Such that we're sure to never trigger this under any other conditions?
>
> Oh, we can for sure modify the code to something else. Actually, this is
> why I was calling out to you. I was never comfortable with the old
> 'in_atomic() || irqs_disabled()' code, but wasn't sure what would be an
> adequate replacement which will not risk regressions.
>
> The above condition makes much more sense to me and is also much more
> readable. Can it simply replace irqs_disabled()? Are interrupts already
> disabled for system_state > SYSTEM_RUNNING? (I got a bit lost in the
> code paths when trying to figure it out)

Looking at kernel_restart_prepare(), we set SYSTEM_REBOOT in normal
context, specifically it just did a blocking notifier call.

So no, you'll have to combine the two.