]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
spi: mux: repair mux usage
authorPeter Rosin <peda@axentia.se>
Mon, 25 May 2020 10:43:52 +0000 (12:43 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 22 Jun 2020 07:32:25 +0000 (09:32 +0200)
[ Upstream commit a2b02e4623fb127fa65a13e4ac5aa56e4ae16291 ]

It is not valid to cache/short out selection of the mux.

mux_control_select() only locks the mux until mux_control_deselect()
is called. mux_control_deselect() may put the mux in some low power
state or some other user of the mux might select it for other purposes.
These things are probably not happening in the original setting where
this driver was developed, but it is said to be a generic SPI mux.

Also, the mux framework will short out the actual low level muxing
operation when/if that is possible.

Fixes: e9e40543ad5b ("spi: Add generic SPI multiplexer")
Signed-off-by: Peter Rosin <peda@axentia.se>
Link: https://lore.kernel.org/r/20200525104352.26807-1-peda@axentia.se
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/spi-mux.c

index 4f94c9127fc10fd33ab5d98689d8da1041104fb7..cc9ef371db14c2db20fefb9e1d5d3e4f30e927dc 100644 (file)
@@ -51,6 +51,10 @@ static int spi_mux_select(struct spi_device *spi)
        struct spi_mux_priv *priv = spi_controller_get_devdata(spi->controller);
        int ret;
 
+       ret = mux_control_select(priv->mux, spi->chip_select);
+       if (ret)
+               return ret;
+
        if (priv->current_cs == spi->chip_select)
                return 0;
 
@@ -62,10 +66,6 @@ static int spi_mux_select(struct spi_device *spi)
        priv->spi->mode = spi->mode;
        priv->spi->bits_per_word = spi->bits_per_word;
 
-       ret = mux_control_select(priv->mux, spi->chip_select);
-       if (ret)
-               return ret;
-
        priv->current_cs = spi->chip_select;
 
        return 0;