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

iio:ad5504: Do not store transfer buffers on the stack

Some SPI controllers may not be able to handle transfer buffers that are placed
on the stack.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
0dbe59c7 61c358e3

+19 -19
+19 -19
drivers/iio/dac/ad5504.c
··· 47 47 * @vref_mv: actual reference voltage used 48 48 * @pwr_down_mask power down mask 49 49 * @pwr_down_mode current power down mode 50 + * @data: transfer buffer 50 51 */ 51 - 52 52 struct ad5504_state { 53 53 struct spi_device *spi; 54 54 struct regulator *reg; 55 55 unsigned short vref_mv; 56 56 unsigned pwr_down_mask; 57 57 unsigned pwr_down_mode; 58 + 59 + __be16 data[2] ____cacheline_aligned; 58 60 }; 59 61 60 62 /** ··· 68 66 ID_AD5501, 69 67 }; 70 68 71 - static int ad5504_spi_write(struct spi_device *spi, u8 addr, u16 val) 69 + static int ad5504_spi_write(struct ad5504_state *st, u8 addr, u16 val) 72 70 { 73 - __be16 tmp = cpu_to_be16(AD5504_CMD_WRITE | 74 - AD5504_ADDR(addr) | 71 + st->data[0] = cpu_to_be16(AD5504_CMD_WRITE | AD5504_ADDR(addr) | 75 72 (val & AD5504_RES_MASK)); 76 73 77 - return spi_write(spi, (u8 *)&tmp, 2); 74 + return spi_write(st->spi, &st->data[0], 2); 78 75 } 79 76 80 - static int ad5504_spi_read(struct spi_device *spi, u8 addr) 77 + static int ad5504_spi_read(struct ad5504_state *st, u8 addr) 81 78 { 82 - __be16 tmp = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr)); 83 - __be16 val; 84 79 int ret; 85 - struct spi_transfer t = { 86 - .tx_buf = &tmp, 87 - .rx_buf = &val, 88 - .len = 2, 89 - }; 90 - ret = spi_sync_transfer(spi, &t, 1); 80 + struct spi_transfer t = { 81 + .tx_buf = &st->data[0], 82 + .rx_buf = &st->data[1], 83 + .len = 2, 84 + }; 91 85 86 + st->data[0] = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr)); 87 + ret = spi_sync_transfer(st->spi, &t, 1); 92 88 if (ret < 0) 93 89 return ret; 94 90 95 - return be16_to_cpu(val) & AD5504_RES_MASK; 91 + return be16_to_cpu(st->data[1]) & AD5504_RES_MASK; 96 92 } 97 93 98 94 static int ad5504_read_raw(struct iio_dev *indio_dev, ··· 104 104 105 105 switch (m) { 106 106 case IIO_CHAN_INFO_RAW: 107 - ret = ad5504_spi_read(st->spi, chan->address); 107 + ret = ad5504_spi_read(st, chan->address); 108 108 if (ret < 0) 109 109 return ret; 110 110 ··· 133 133 if (val >= (1 << chan->scan_type.realbits) || val < 0) 134 134 return -EINVAL; 135 135 136 - return ad5504_spi_write(st->spi, chan->address, val); 136 + return ad5504_spi_write(st, chan->address, val); 137 137 default: 138 138 ret = -EINVAL; 139 139 } ··· 197 197 else 198 198 st->pwr_down_mask &= ~(1 << chan->channel); 199 199 200 - ret = ad5504_spi_write(st->spi, AD5504_ADDR_CTRL, 200 + ret = ad5504_spi_write(st, AD5504_ADDR_CTRL, 201 201 AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) | 202 202 AD5504_DAC_PWR(st->pwr_down_mask)); 203 203 204 204 /* writes to the CTRL register must be followed by a NOOP */ 205 - ad5504_spi_write(st->spi, AD5504_ADDR_NOOP, 0); 205 + ad5504_spi_write(st, AD5504_ADDR_NOOP, 0); 206 206 207 207 return ret ? ret : len; 208 208 }