linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuanhua Han <chuanhua.han@nxp.com>
To: dwmw2@infradead.org, computersforpeace@gmail.com,
	boris.brezillon@bootlin.com, marek.vasut@gmail.com,
	richard@nod.at
Cc: cyrille.pitchen@wedev4u.fr, broonie@kernel.org, pp@emlix.com,
	Zhiqiang.Hou@nxp.com, chuanhua.han@nxp.com,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API
Date: Wed, 15 Aug 2018 14:33:43 +0800	[thread overview]
Message-ID: <1534314823-14048-1-git-send-email-chuanhua.han@nxp.com> (raw)

Consider a message size limit when calculating the maximum amount
of data that can be read.

Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
---
 drivers/mtd/devices/m25p80.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index e84563d..87efa56 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -128,7 +128,12 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
 	op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
 
 	while (remaining) {
-		op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
+		op.data.nbytes = min3(remaining,
+				spi_max_transfer_size(flash->spimem->spi),
+				spi_max_message_size(flash->spimem->spi) -
+				sizeof(op.cmd.opcode) -
+				op.addr.nbytes -
+				op.dummy.nbytes);
 		ret = spi_mem_adjust_op_size(flash->spimem, &op);
 		if (ret)
 			return ret;
-- 
2.7.4


             reply	other threads:[~2018-08-15  6:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-15  6:33 Chuanhua Han [this message]
2018-08-16  6:33 ` [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API Boris Brezillon

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=1534314823-14048-1-git-send-email-chuanhua.han@nxp.com \
    --to=chuanhua.han@nxp.com \
    --cc=Zhiqiang.Hou@nxp.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=broonie@kernel.org \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=pp@emlix.com \
    --cc=richard@nod.at \
    /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).