* [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API
@ 2018-08-15 6:33 Chuanhua Han
2018-08-16 6:33 ` Boris Brezillon
0 siblings, 1 reply; 2+ messages in thread
From: Chuanhua Han @ 2018-08-15 6:33 UTC (permalink / raw)
To: dwmw2, computersforpeace, boris.brezillon, marek.vasut, richard
Cc: cyrille.pitchen, broonie, pp, Zhiqiang.Hou, chuanhua.han,
linux-mtd, linux-kernel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API
2018-08-15 6:33 [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API Chuanhua Han
@ 2018-08-16 6:33 ` Boris Brezillon
0 siblings, 0 replies; 2+ messages in thread
From: Boris Brezillon @ 2018-08-16 6:33 UTC (permalink / raw)
To: Chuanhua Han
Cc: dwmw2, computersforpeace, marek.vasut, richard, cyrille.pitchen,
broonie, pp, Zhiqiang.Hou, linux-mtd, linux-kernel
Hi Chuanhua,
On Wed, 15 Aug 2018 14:33:43 +0800
Chuanhua Han <chuanhua.han@nxp.com> wrote:
> 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);
Nope, this sort of things should go in the SPI controller driver
->adjust_op_size() hook or directly in spi_mem_adjust_op_size() if it's
generic enough (which doesn't seem to be the case since your not
counting the opcode, addr and dummy bytes in the message length).
Regards,
Boris
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-08-16 6:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15 6:33 [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API Chuanhua Han
2018-08-16 6:33 ` Boris Brezillon
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).