From: Chuanhong Guo <gch981213@gmail.com>
To: linux-spi@vger.kernel.org
Cc: "Bayi Cheng (程八意)" <bayi.cheng@mediatek.com>,
stable@vger.kernel.org, "Mark Brown" <broonie@kernel.org>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"moderated list:ARM/Mediatek SoC support"
<linux-arm-kernel@lists.infradead.org>,
"moderated list:ARM/Mediatek SoC support"
<linux-mediatek@lists.infradead.org>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] spi: spi-mtk-nor: fix timeout calculation overflow
Date: Tue, 22 Sep 2020 19:47:04 +0800 [thread overview]
Message-ID: <CAJsYDVJugyZQage-aWUqUoHEq6dhNdMw4J+0PmzGKrO=s9hoBw@mail.gmail.com> (raw)
In-Reply-To: <20200922114317.2935897-1-gch981213@gmail.com>
On Tue, Sep 22, 2020 at 7:43 PM Chuanhong Guo <gch981213@gmail.com> wrote:
>
> CLK_TO_US macro is used to calculate potential transfer time for various
> timeout handling. However it overflows on transfer bigger than 512 bytes
> because it first did (len * 8 * 1000000).
> This controller typically operates at 45MHz. This patch did 2 things:
> 1. calculate clock / 1000000 first
> 2. add a 4M transfer size cap so that the final timeout in DMA reading
> doesn't overflow
>
> Fixes: 881d1ee9fe81f ("spi: add support for mediatek spi-nor controller")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
> ---
> drivers/spi/spi-mtk-nor.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
> index 6e6ca2b8e6c82..619313db42c0e 100644
> --- a/drivers/spi/spi-mtk-nor.c
> +++ b/drivers/spi/spi-mtk-nor.c
> @@ -89,7 +89,7 @@
> // Buffered page program can do one 128-byte transfer
> #define MTK_NOR_PP_SIZE 128
>
> -#define CLK_TO_US(sp, clkcnt) ((clkcnt) * 1000000 / sp->spi_freq)
> +#define CLK_TO_US(sp, clkcnt) DIV_ROUND_UP(clkcnt, sp->spi_freq / 1000000)
>
> struct mtk_nor {
> struct spi_controller *ctlr;
> @@ -177,6 +177,10 @@ static int mtk_nor_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
> if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) {
> if ((op->data.dir == SPI_MEM_DATA_IN) &&
> mtk_nor_match_read(op)) {
> + // limit size to prevent timeout calculation overflow
> + if (op->data.nbytes > 0x2000000)
> + op->data.nbytes = 0x2000000;
> +
Sorry, wrong patch. This cap should be 4M not 32M. I'll send a v2 immediately.
--
Regards,
Chuanhong Guo
WARNING: multiple messages have this Message-ID (diff)
From: Chuanhong Guo <gch981213@gmail.com>
To: linux-spi@vger.kernel.org
Cc: "open list" <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org, "Mark Brown" <broonie@kernel.org>,
"moderated list:ARM/Mediatek SoC support"
<linux-mediatek@lists.infradead.org>,
"Bayi Cheng (程八意)" <bayi.cheng@mediatek.com>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"moderated list:ARM/Mediatek SoC support"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] spi: spi-mtk-nor: fix timeout calculation overflow
Date: Tue, 22 Sep 2020 19:47:04 +0800 [thread overview]
Message-ID: <CAJsYDVJugyZQage-aWUqUoHEq6dhNdMw4J+0PmzGKrO=s9hoBw@mail.gmail.com> (raw)
In-Reply-To: <20200922114317.2935897-1-gch981213@gmail.com>
On Tue, Sep 22, 2020 at 7:43 PM Chuanhong Guo <gch981213@gmail.com> wrote:
>
> CLK_TO_US macro is used to calculate potential transfer time for various
> timeout handling. However it overflows on transfer bigger than 512 bytes
> because it first did (len * 8 * 1000000).
> This controller typically operates at 45MHz. This patch did 2 things:
> 1. calculate clock / 1000000 first
> 2. add a 4M transfer size cap so that the final timeout in DMA reading
> doesn't overflow
>
> Fixes: 881d1ee9fe81f ("spi: add support for mediatek spi-nor controller")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
> ---
> drivers/spi/spi-mtk-nor.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
> index 6e6ca2b8e6c82..619313db42c0e 100644
> --- a/drivers/spi/spi-mtk-nor.c
> +++ b/drivers/spi/spi-mtk-nor.c
> @@ -89,7 +89,7 @@
> // Buffered page program can do one 128-byte transfer
> #define MTK_NOR_PP_SIZE 128
>
> -#define CLK_TO_US(sp, clkcnt) ((clkcnt) * 1000000 / sp->spi_freq)
> +#define CLK_TO_US(sp, clkcnt) DIV_ROUND_UP(clkcnt, sp->spi_freq / 1000000)
>
> struct mtk_nor {
> struct spi_controller *ctlr;
> @@ -177,6 +177,10 @@ static int mtk_nor_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
> if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) {
> if ((op->data.dir == SPI_MEM_DATA_IN) &&
> mtk_nor_match_read(op)) {
> + // limit size to prevent timeout calculation overflow
> + if (op->data.nbytes > 0x2000000)
> + op->data.nbytes = 0x2000000;
> +
Sorry, wrong patch. This cap should be 4M not 32M. I'll send a v2 immediately.
--
Regards,
Chuanhong Guo
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
WARNING: multiple messages have this Message-ID (diff)
From: Chuanhong Guo <gch981213@gmail.com>
To: linux-spi@vger.kernel.org
Cc: "open list" <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org, "Mark Brown" <broonie@kernel.org>,
"moderated list:ARM/Mediatek SoC support"
<linux-mediatek@lists.infradead.org>,
"Bayi Cheng (程八意)" <bayi.cheng@mediatek.com>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"moderated list:ARM/Mediatek SoC support"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] spi: spi-mtk-nor: fix timeout calculation overflow
Date: Tue, 22 Sep 2020 19:47:04 +0800 [thread overview]
Message-ID: <CAJsYDVJugyZQage-aWUqUoHEq6dhNdMw4J+0PmzGKrO=s9hoBw@mail.gmail.com> (raw)
In-Reply-To: <20200922114317.2935897-1-gch981213@gmail.com>
On Tue, Sep 22, 2020 at 7:43 PM Chuanhong Guo <gch981213@gmail.com> wrote:
>
> CLK_TO_US macro is used to calculate potential transfer time for various
> timeout handling. However it overflows on transfer bigger than 512 bytes
> because it first did (len * 8 * 1000000).
> This controller typically operates at 45MHz. This patch did 2 things:
> 1. calculate clock / 1000000 first
> 2. add a 4M transfer size cap so that the final timeout in DMA reading
> doesn't overflow
>
> Fixes: 881d1ee9fe81f ("spi: add support for mediatek spi-nor controller")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
> ---
> drivers/spi/spi-mtk-nor.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
> index 6e6ca2b8e6c82..619313db42c0e 100644
> --- a/drivers/spi/spi-mtk-nor.c
> +++ b/drivers/spi/spi-mtk-nor.c
> @@ -89,7 +89,7 @@
> // Buffered page program can do one 128-byte transfer
> #define MTK_NOR_PP_SIZE 128
>
> -#define CLK_TO_US(sp, clkcnt) ((clkcnt) * 1000000 / sp->spi_freq)
> +#define CLK_TO_US(sp, clkcnt) DIV_ROUND_UP(clkcnt, sp->spi_freq / 1000000)
>
> struct mtk_nor {
> struct spi_controller *ctlr;
> @@ -177,6 +177,10 @@ static int mtk_nor_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
> if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) {
> if ((op->data.dir == SPI_MEM_DATA_IN) &&
> mtk_nor_match_read(op)) {
> + // limit size to prevent timeout calculation overflow
> + if (op->data.nbytes > 0x2000000)
> + op->data.nbytes = 0x2000000;
> +
Sorry, wrong patch. This cap should be 4M not 32M. I'll send a v2 immediately.
--
Regards,
Chuanhong Guo
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-09-22 11:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-22 11:42 [PATCH] spi: spi-mtk-nor: fix timeout calculation overflow Chuanhong Guo
2020-09-22 11:42 ` Chuanhong Guo
2020-09-22 11:42 ` Chuanhong Guo
2020-09-22 11:47 ` Chuanhong Guo [this message]
2020-09-22 11:47 ` Chuanhong Guo
2020-09-22 11:47 ` Chuanhong Guo
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='CAJsYDVJugyZQage-aWUqUoHEq6dhNdMw4J+0PmzGKrO=s9hoBw@mail.gmail.com' \
--to=gch981213@gmail.com \
--cc=bayi.cheng@mediatek.com \
--cc=broonie@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.