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

gpio: max7301: fix driver for use with CONFIG_VMAP_STACK

spi_read() and spi_write() require DMA-safe memory. When
CONFIG_VMAP_STACK is selected, those functions cannot be used
with buffers on stack.

This patch replaces calls to spi_read() and spi_write() by
spi_write_then_read() which doesn't require DMA-safe buffers.

Fixes: 0c36ec314735 ("gpio: gpio driver for max7301 SPI GPIO expander")
Cc: <stable@vger.kernel.org>
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Christophe Leroy and committed by
Linus Walleij
abf221d2 00ded24c

+3 -9
+3 -9
drivers/gpio/gpio-max7301.c
··· 25 25 struct spi_device *spi = to_spi_device(dev); 26 26 u16 word = ((reg & 0x7F) << 8) | (val & 0xFF); 27 27 28 - return spi_write(spi, (const u8 *)&word, sizeof(word)); 28 + return spi_write_then_read(spi, &word, sizeof(word), NULL, 0); 29 29 } 30 30 31 31 /* A read from the MAX7301 means two transfers; here, one message each */ ··· 37 37 struct spi_device *spi = to_spi_device(dev); 38 38 39 39 word = 0x8000 | (reg << 8); 40 - ret = spi_write(spi, (const u8 *)&word, sizeof(word)); 41 - if (ret) 42 - return ret; 43 - /* 44 - * This relies on the fact, that a transfer with NULL tx_buf shifts out 45 - * zero bytes (=NOOP for MAX7301) 46 - */ 47 - ret = spi_read(spi, (u8 *)&word, sizeof(word)); 40 + ret = spi_write_then_read(spi, &word, sizeof(word), &word, 41 + sizeof(word)); 48 42 if (ret) 49 43 return ret; 50 44 return word & 0xff;