Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: bcm-qspi: check for valid cs before applying chip select

Apply only valid chip select value. This change fixes case where chip
select is set to initial value of '-1' during probe and PM supend and
subsequent resume can try to use the value with undefined behaviour.
Also in case where gpio based chip select, the check in
bcm_qspi_chip_select() shall prevent undefined behaviour on resume.

Fixes: fa236a7ef240 ("spi: bcm-qspi: Add Broadcom MSPI driver")
Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20220127185359.27322-1-kdasu.kdev@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Kamal Dasu and committed by
Mark Brown
2cbd2726 37c2c83c

+1 -1
+1 -1
drivers/spi/spi-bcm-qspi.c
··· 585 585 u32 rd = 0; 586 586 u32 wr = 0; 587 587 588 - if (qspi->base[CHIP_SELECT]) { 588 + if (cs >= 0 && qspi->base[CHIP_SELECT]) { 589 589 rd = bcm_qspi_read(qspi, CHIP_SELECT, 0); 590 590 wr = (rd & ~0xff) | (1 << cs); 591 591 if (rd == wr)