spi: Make spi_delay_exec() warn if called from atomic context
Mark Brown
maintainerPATCH 1/1 spi: Make spi_delay_exec() warn if called from atomic context
If the delay used is long enough the spi_delay_exec() will use a sleeping function to implement it. Add a might_sleep() here to help avoid callers using this from an atomic context and running into problems at runtime on other systems.
--- drivers/spi/spi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/spi/spi.c +2 -0
@@ -1160,6 +1160,8 @@ int spi_delay_exec(struct spi_delay *_delay, struct spi_transfer *xfer) {int delay; +might_sleep (); +if (!_delay)return -EINVAL ;
Signature · 1 line
2.20.1
Quoted 4 lines · Mark Brown
If the delay used is long enough the
spi_delay_exec()will use a sleeping function to implement it. Add amight_sleep()here to help avoid callers using this from an atomic context and running into problems at runtime on other systems.
Thanks!
Quoted 23 lines
Suggested-by Serge Semin <[email protected]>Signed-off-by Mark Brown <[email protected]>--- drivers/spi/spi.c | 2 ++ 1 file changed, 2 insertions(+)drivers/spi/spi.c +2
-0@@ -1160,6 +1160,8 @@ int spi_delay_exec(struct spi_delay *_delay, struct spi_transfer *xfer) {int delay; +might_sleep (); +if (!_delay)return -EINVAL ;Signature · 1 line
2.20.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Mark Brown
If the delay used is long enough the
spi_delay_exec()will use a sleeping function to implement it. Add amight_sleep()here to help avoid callers using this from an atomic context and running into problems at runtime on other systems.Thanks!
Reviewed-by Andy Shevchenko <[email protected]>
We may improve it later, though, to be smarter and spill a warning only when it uses non-atomic delays. For now this is good enough.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Mark Brown
If the delay used is long enough the
spi_delay_exec()will use a sleeping function to implement it. Add amight_sleep()here to help avoid callers using this from an atomic context and running into problems at runtime on other systems.
Quoted 5 lines
Quoted 2 lines
Thanks!
Reviewed-by Andy Shevchenko <[email protected]>We may improve it later, though, to be smarter and spill a warning only when it uses non-atomic delays. For now this is good enough.
IMO this wouldn't be better than the current solution. might_sleep() is called "might" to warn that the called method may get to sleep, not shall, not will. As I see it it's better to warn about the consequences straight away, but not at the point when the sleeping method is actually called in the atomic context.
-Sergey
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
Mark Brown
maintainerQuoted 9 lines · Serge Semin
Quoted 2 lines · Andy Shevchenko
We may improve it later, though, to be smarter and spill a warning only when it uses non-atomic delays. For now this is good enough.
IMO this wouldn't be better than the current solution.
might_sleep()is called "might" to warn that the called method may get to sleep, not shall, not will. As I see it it's better to warn about the consequences straight away, but not at the point when the sleeping method is actually called in the atomic context.
Yes, this is the whole point of might_sleep() - it's to ensure that we always get a warning about code that might sleep, rather than only getting a warning if we happen to go down a path that does actually sleep. This means we're less likely to run into bugs at runtime in unusual use cases.
Mark Brown
maintainerQuoted 4 lines · Mark Brown
If the delay used is long enough the
spi_delay_exec()will use a sleeping function to implement it. Add amight_sleep()here to help avoid callers using this from an atomic context and running into problems at runtime on other systems.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: Make spi_delay_exec() warn if called from atomic context
commit: 8fede89f853a7bfc671f9d8f069ccfe4190061f3
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark