2019-10-29 11:20:38

by Tudor Ambarus

[permalink] [raw]
Subject: [PATCH v3 14/32] mtd: spi-nor: Fix retlen handling in sst_write()

From: Tudor Ambarus <[email protected]>

In case the write of the first byte failed, retlen was incorrectly
incremented to *retlen += actual; on the exit path. retlen should be
incremented when actual data was written to the flash.

Signed-off-by: Tudor Ambarus <[email protected]>
---
drivers/mtd/spi-nor/spi-nor.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index bc46b946ac77..889fd77dbe96 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2667,7 +2667,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf)
{
struct spi_nor *nor = mtd_to_spi_nor(mtd);
- size_t actual;
+ size_t actual = 0;
int ret;

dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
@@ -2680,9 +2680,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,

nor->sst_write_second = false;

- actual = to % 2;
/* Start write from odd address. */
- if (actual) {
+ if (to % 2) {
nor->program_opcode = SPINOR_OP_BP;

/* write one byte. */
@@ -2693,8 +2692,10 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
ret = spi_nor_wait_till_ready(nor);
if (ret)
goto sst_write_err;
+
+ to++;
+ actual++;
}
- to += actual;

/* Write out most of the data here. */
for (; actual < len - 1; actual += 2) {
--
2.9.5


2019-10-31 11:13:42

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH v3 14/32] mtd: spi-nor: Fix retlen handling in sst_write()

On Tue, 29 Oct 2019 11:17:10 +0000
<[email protected]> wrote:

> From: Tudor Ambarus <[email protected]>
>
> In case the write of the first byte failed, retlen was incorrectly
> incremented to *retlen += actual; on the exit path. retlen should be
> incremented when actual data was written to the flash.
>
> Signed-off-by: Tudor Ambarus <[email protected]>

Reviewed-by: Boris Brezillon <[email protected]>

> ---
> drivers/mtd/spi-nor/spi-nor.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index bc46b946ac77..889fd77dbe96 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2667,7 +2667,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
> size_t *retlen, const u_char *buf)
> {
> struct spi_nor *nor = mtd_to_spi_nor(mtd);
> - size_t actual;
> + size_t actual = 0;
> int ret;
>
> dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
> @@ -2680,9 +2680,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
>
> nor->sst_write_second = false;
>
> - actual = to % 2;
> /* Start write from odd address. */
> - if (actual) {
> + if (to % 2) {
> nor->program_opcode = SPINOR_OP_BP;
>
> /* write one byte. */
> @@ -2693,8 +2692,10 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
> ret = spi_nor_wait_till_ready(nor);
> if (ret)
> goto sst_write_err;
> +
> + to++;
> + actual++;
> }
> - to += actual;
>
> /* Write out most of the data here. */
> for (; actual < len - 1; actual += 2) {

2019-11-02 10:51:00

by Tudor Ambarus

[permalink] [raw]
Subject: Re: [PATCH v3 14/32] mtd: spi-nor: Fix retlen handling in sst_write()



On 10/29/2019 01:17 PM, Tudor Ambarus - M18064 wrote:
> From: Tudor Ambarus <[email protected]>
>
> In case the write of the first byte failed, retlen was incorrectly
> incremented to *retlen += actual; on the exit path. retlen should be
> incremented when actual data was written to the flash.
>
> Signed-off-by: Tudor Ambarus <[email protected]>
> ---
> drivers/mtd/spi-nor/spi-nor.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)

Applied to spi-nor/next. Thanks.