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 <o.rempel@pengutronix.de>
Closes: https://lore.kernel.org/linux-spi/Zn6HMrYG2b7epUxT@pengutronix.de/
Reported-by: Marc Kleine-Budde <mkl@pengutronix.de>
Closes: https://lore.kernel.org/linux-spi/20240628-awesome-discerning-bear-1621f9-mkl@pengutronix.de/
Fixes:
|
||
|---|---|---|
| .. | ||
| ad7877.h | ||
| ads7846.h | ||
| altera.h | ||
| at73c213.h | ||
| corgi_lcd.h | ||
| ds1305.h | ||
| eeprom.h | ||
| flash.h | ||
| libertas_spi.h | ||
| max7301.h | ||
| mc33880.h | ||
| mmc_spi.h | ||
| mxs-spi.h | ||
| sh_hspi.h | ||
| sh_msiof.h | ||
| spi-fsl-dspi.h | ||
| spi-mem.h | ||
| spi.h | ||
| spi_bitbang.h | ||
| spi_gpio.h | ||
| spi_oc_tiny.h | ||
| tdo24m.h | ||
| tle62x0.h | ||
| xilinx_spi.h | ||