cip-dev.lists.cip-project.org archive mirror
 help / color / mirror / Atom feed
From: "Pavel Machek" <pavel@denx.de>
To: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Cc: cip-dev@lists.cip-project.org,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>,
	Pavel Machek <pavel@denx.de>,
	Biju Das <biju.das.jz@bp.renesas.com>
Subject: Re: [cip-dev] [PATCH v3 4.19.y-cip 12/17] spi: spi-mem: Compute length only when needed
Date: Tue, 5 Jan 2021 17:53:58 +0100	[thread overview]
Message-ID: <20210105165358.GC361@amd> (raw)
In-Reply-To: <20210105135757.11069-13-prabhakar.mahadev-lad.rj@bp.renesas.com>


[-- Attachment #1.1: Type: text/plain, Size: 2006 bytes --]

Hi!

> From: Tudor Ambarus <tudor.ambarus@microchip.com>
> 
> 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.

Best regards,

								Pavel

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

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

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

[-- Attachment #2: Type: text/plain, Size: 420 bytes --]


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#6033): https://lists.cip-project.org/g/cip-dev/message/6033
Mute This Topic: https://lists.cip-project.org/mt/79450076/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-


  reply	other threads:[~2021-01-05 16:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-05 13:57 [cip-dev] [PATCH v3 4.19.y-cip 00/17] Add Renesas RPC-IF driver Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 01/17] dt-bindings: memory: document Renesas RPC-IF bindings Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 02/17] memory: add Renesas RPC-IF driver Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 03/17] memory: renesas-rpc-if: Return correct value to the caller of rpcif_manual_xfer() Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 04/17] memory: renesas-rpc-if: Fix unbalanced pm_runtime_enable in rpcif_{enable,disable}_rpm Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 05/17] memory: renesas-rpc-if: Fix a node reference leak in rpcif_probe() Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 06/17] memory: renesas-rpc-if: Make rpcif_enable/disable_rpm() as static inline Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 07/17] spi: spi-mem: Add SPI_MEM_NO_DATA to the spi_mem_data_dir enum Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 08/17] spi: spi-mem: export spi_mem_default_supports_op() Lad Prabhakar
2021-01-05 16:51   ` Pavel Machek
2021-01-05 17:07     ` Lad Prabhakar
2021-01-05 17:47     ` Sudip Mukherjee
2021-01-06 13:19       ` Pavel Machek
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 09/17] spi: spi-mem: Split spi_mem_exec_op() code Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 10/17] spi: spi-mem: fix reference leak in spi_mem_access_start Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 11/17] spi: spi-mem: Fix passing zero to 'PTR_ERR' warning Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 12/17] spi: spi-mem: Compute length only when needed Lad Prabhakar
2021-01-05 16:53   ` Pavel Machek [this message]
2021-01-05 17:10     ` Lad Prabhakar
2021-01-05 17:29       ` Pavel Machek
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 13/17] spi: spi-mem: Add a new API to support direct mapping Lad Prabhakar
2021-01-05 16:57   ` Pavel Machek
2021-01-05 17:12     ` Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 14/17] spi: spi-mem: Fix spi_mem_dirmap_destroy() kerneldoc Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 15/17] spi: spi-mem: Fix a memory leak in spi_mem_dirmap_destroy() Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 16/17] spi: add Renesas RPC-IF driver Lad Prabhakar
2021-01-05 16:58   ` Pavel Machek
2021-01-05 17:14     ` Lad Prabhakar
2021-01-05 13:57 ` [cip-dev] [PATCH v3 4.19.y-cip 17/17] spi: rpc-if: Fix use-after-free on unbind Lad Prabhakar
2021-01-05 17:04 ` [cip-dev] [PATCH v3 4.19.y-cip 00/17] Add Renesas RPC-IF driver Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210105165358.GC361@amd \
    --to=pavel@denx.de \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).