Commit ca52aa4
spi: add defer_optimize_message controller flag
Adding spi_optimize_message() broke the spi-mux driver because it
calls spi_async() from it's transfer_one_message() callback. This
resulted in passing an incorrectly optimized message to the controller.
For example, if the underlying controller has an optimize_message()
callback, this would have not been called and can cause a crash when
the underlying controller driver tries to transfer the message.
Also, since the spi-mux driver swaps out the controller pointer by
replacing msg->spi, __spi_unoptimize_message() was being called with a
different controller than the one used in __spi_optimize_message(). This
could cause a crash when attempting to free the message resources when
__spi_unoptimize_message() is called in spi_finalize_current_message()
since it is being called with a controller that did not allocate the
resources.
This is fixed by adding a defer_optimize_message flag for controllers.
This flag causes all of the spi_[maybe_][un]optimize_message() calls to
be a no-op (other than attaching a pointer to the spi device to the
message).
This allows the spi-mux driver to pass an unmodified message to
spi_async() in spi_mux_transfer_one_message() after the spi device has
been swapped out. This causes __spi_optimize_message() and
__spi_unoptimize_message() to be called only once per message and with
the correct/same controller in each case.
Reported-by: Oleksij Rempel <[email protected]>
Closes: https://lore.kernel.org/linux-spi/[email protected]/
Reported-by: Marc Kleine-Budde <[email protected]>
Closes: https://lore.kernel.org/linux-spi/[email protected]/
Fixes: 7b1d87a ("spi: add spi_optimize_message() APIs")
Signed-off-by: David Lechner <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>1 parent c86a918 commit ca52aa4
3 files changed
+22
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2151 | 2151 | | |
2152 | 2152 | | |
2153 | 2153 | | |
2154 | | - | |
| 2154 | + | |
| 2155 | + | |
2155 | 2156 | | |
2156 | 2157 | | |
2157 | 2158 | | |
| |||
4294 | 4295 | | |
4295 | 4296 | | |
4296 | 4297 | | |
| 4298 | + | |
| 4299 | + | |
| 4300 | + | |
| 4301 | + | |
| 4302 | + | |
4297 | 4303 | | |
4298 | 4304 | | |
4299 | 4305 | | |
| |||
4324 | 4330 | | |
4325 | 4331 | | |
4326 | 4332 | | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
| 4336 | + | |
| 4337 | + | |
| 4338 | + | |
| 4339 | + | |
4327 | 4340 | | |
4328 | 4341 | | |
4329 | 4342 | | |
| |||
4350 | 4363 | | |
4351 | 4364 | | |
4352 | 4365 | | |
| 4366 | + | |
| 4367 | + | |
| 4368 | + | |
4353 | 4369 | | |
4354 | 4370 | | |
4355 | 4371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
536 | 539 | | |
537 | 540 | | |
538 | 541 | | |
| |||
776 | 779 | | |
777 | 780 | | |
778 | 781 | | |
| 782 | + | |
779 | 783 | | |
780 | 784 | | |
781 | 785 | | |
| |||
0 commit comments