Re: [PATCH v3 4.19.y-cip 12/17] spi: spi-mem: Compute length only when needed


Lad Prabhakar
 

Hi Pavel,

Thank you for the review.

-----Original Message-----
From: Pavel Machek <pavel@...>
Sent: 05 January 2021 16:54
To: Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@...>
Cc: cip-dev@...; Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@...>; Pavel Machek
<pavel@...>; Biju Das <biju.das.jz@...>
Subject: Re: [PATCH v3 4.19.y-cip 12/17] spi: spi-mem: Compute length only when needed

Hi!

From: Tudor Ambarus <tudor.ambarus@...>

commit c0e035ac56680e74b27fc218c07e70f4b9b8b7a5 upstream.

When adjust_op_size is defined, len is never used. Move the len
computation where it's actually used.
index 59f7aa117a10..02cf8c3f7350 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -412,12 +412,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;
If we are doing this kind of cleanups... I'd move "len" declaration
inside the if, too... Not that it matters much.
Should live without this change, will drop this for now.

Cheers,
Prabhakar

Best regards,

Pavel

Signed-off-by: Pavel Machek (CIP) <pavel@...>

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index c3a08afb6edf..bc64b4223913 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -410,13 +410,12 @@ EXPORT_SYMBOL_GPL(spi_mem_get_name);
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;

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 +
+ size_t len = sizeof(op->cmd.opcode) + op->addr.nbytes +
op->dummy.nbytes;

if (len > spi_max_transfer_size(mem->spi))

--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Join cip-dev@lists.cip-project.org to automatically receive all group messages.