summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTudor Ambarus <tudor.ambarus@microchip.com>2020-02-28 16:07:44 +0000
committerMark Brown <broonie@kernel.org>2020-02-28 18:17:18 +0000
commitc0e035ac56680e74b27fc218c07e70f4b9b8b7a5 (patch)
treeb37a87b58511ac815f2330a0699cedef933bf25f
parent3d24b2a470466aa901ba8354468fc1899259fd84 (diff)
downloadlinux-stable-c0e035ac56680e74b27fc218c07e70f4b9b8b7a5.tar.gz
linux-stable-c0e035ac56680e74b27fc218c07e70f4b9b8b7a5.tar.bz2
linux-stable-c0e035ac56680e74b27fc218c07e70f4b9b8b7a5.zip
spi: spi-mem: Compute length only when needed
When adjust_op_size is defined, len is never used. Move the len computation where it's actually used. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Link: https://lore.kernel.org/r/20200228160735.1565047-1-tudor.ambarus@microchip.com Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-mem.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 3c46747bacb1..adaa0c49f966 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -418,12 +418,13 @@ int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
struct spi_controller *ctlr = mem->spi->controller;
size_t len;
- len = sizeof(op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes;
-
if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)
return ctlr->mem_ops->adjust_op_size(mem, op);
if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) {
+ len = sizeof(op->cmd.opcode) + op->addr.nbytes +
+ op->dummy.nbytes;
+
if (len > spi_max_transfer_size(mem->spi))
return -EINVAL;