2018-07-04 08:22:07

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next] mtd: spinand: Fix missing unlock on error path

Add the missing unlock before return from function
spinand_mtd_(read|write) in the error handling case.

Fixes: c898e0526fb6 ("mtd: nand: Add core infrastructure to support SPI NANDs")
Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/mtd/nand/spi/core.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 17d207a..8ac1ba95 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -560,12 +560,16 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,

nanddev_io_for_each_page(nand, from, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target);
- if (ret)
+ if (ret) {
+ mutex_unlock(&spinand->lock);
return ret;
+ }

ret = spinand_ecc_enable(spinand, enable_ecc);
- if (ret)
+ if (ret) {
+ mutex_unlock(&spinand->lock);
return ret;
+ }

ret = spinand_read_page(spinand, &iter.req, enable_ecc);
if (ret < 0 && ret != -EBADMSG)
@@ -609,11 +613,11 @@ static int spinand_mtd_write(struct mtd_info *mtd, loff_t to,
nanddev_io_for_each_page(nand, to, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target);
if (ret)
- return ret;
+ break;

ret = spinand_ecc_enable(spinand, enable_ecc);
if (ret)
- return ret;
+ break;

ret = spinand_write_page(spinand, &iter.req);
if (ret)



2018-07-04 08:27:38

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH -next] mtd: spinand: Fix missing unlock on error path

On Wed, 4 Jul 2018 08:29:39 +0000
Wei Yongjun <[email protected]> wrote:

> Add the missing unlock before return from function
> spinand_mtd_(read|write) in the error handling case.
>
> Fixes: c898e0526fb6 ("mtd: nand: Add core infrastructure to support SPI NANDs")
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> drivers/mtd/nand/spi/core.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index 17d207a..8ac1ba95 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -560,12 +560,16 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
>
> nanddev_io_for_each_page(nand, from, ops, &iter) {
> ret = spinand_select_target(spinand, iter.req.pos.target);
> - if (ret)
> + if (ret) {
> + mutex_unlock(&spinand->lock);
> return ret;
> + }

Why not
if (ret)
break;

?

>
> ret = spinand_ecc_enable(spinand, enable_ecc);
> - if (ret)
> + if (ret) {
> + mutex_unlock(&spinand->lock);
> return ret;
> + }

Ditto.

>
> ret = spinand_read_page(spinand, &iter.req, enable_ecc);
> if (ret < 0 && ret != -EBADMSG)
> @@ -609,11 +613,11 @@ static int spinand_mtd_write(struct mtd_info *mtd, loff_t to,
> nanddev_io_for_each_page(nand, to, ops, &iter) {
> ret = spinand_select_target(spinand, iter.req.pos.target);
> if (ret)
> - return ret;
> + break;
>
> ret = spinand_ecc_enable(spinand, enable_ecc);
> if (ret)
> - return ret;
> + break;
>
> ret = spinand_write_page(spinand, &iter.req);
> if (ret)
>

2018-07-04 09:13:35

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next v2] mtd: spinand: fix missing unlock on error

Add the missing unlock before return from function
spinand_mtd_(read|write) in the error handling case.

Fixes: c898e0526fb6 ("mtd: nand: Add core infrastructure to support SPI NANDs")
Signed-off-by: Wei Yongjun <[email protected]>
---
v1 -> v2: using break instead of return
---
drivers/mtd/nand/spi/core.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 17d207a..e072464 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -561,11 +561,12 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
nanddev_io_for_each_page(nand, from, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target);
if (ret)
- return ret;
+ break;

ret = spinand_ecc_enable(spinand, enable_ecc);
if (ret)
- return ret;
+ break;
+

ret = spinand_read_page(spinand, &iter.req, enable_ecc);
if (ret < 0 && ret != -EBADMSG)
@@ -609,11 +610,11 @@ static int spinand_mtd_write(struct mtd_info *mtd, loff_t to,
nanddev_io_for_each_page(nand, to, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target);
if (ret)
- return ret;
+ break;

ret = spinand_ecc_enable(spinand, enable_ecc);
if (ret)
- return ret;
+ break;

ret = spinand_write_page(spinand, &iter.req);
if (ret)


2018-07-04 09:23:00

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next v3] mtd: spinand: fix missing unlock on error

Add the missing unlock before return from function
spinand_mtd_(read|write) in the error handling case.

Fixes: c898e0526fb6 ("mtd: nand: Add core infrastructure to support SPI NANDs")
Signed-off-by: Wei Yongjun <[email protected]>
---
v2 -> v3: remove blank line
v1 -> v2: using break instead of return
---
drivers/mtd/nand/spi/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 17d207a..8998dca 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -561,11 +561,11 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
nanddev_io_for_each_page(nand, from, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target);
if (ret)
- return ret;
+ break;

ret = spinand_ecc_enable(spinand, enable_ecc);
if (ret)
- return ret;
+ break;

ret = spinand_read_page(spinand, &iter.req, enable_ecc);
if (ret < 0 && ret != -EBADMSG)
@@ -609,11 +609,11 @@ static int spinand_mtd_write(struct mtd_info *mtd, loff_t to,
nanddev_io_for_each_page(nand, to, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target);
if (ret)
- return ret;
+ break;

ret = spinand_ecc_enable(spinand, enable_ecc);
if (ret)
- return ret;
+ break;

ret = spinand_write_page(spinand, &iter.req);
if (ret)


2018-07-05 07:01:07

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH -next v3] mtd: spinand: fix missing unlock on error

Hi Wei,

Wei Yongjun <[email protected]> wrote on Wed, 4 Jul 2018 09:30:27
+0000:

> Add the missing unlock before return from function
> spinand_mtd_(read|write) in the error handling case.
>
> Fixes: c898e0526fb6 ("mtd: nand: Add core infrastructure to support SPI NANDs")
> Signed-off-by: Wei Yongjun <[email protected]>
> ---

Thanks for the two fixes over the spinand work. As this code is not
yet upstream, do you mind if I fold those fixes directly with the
initial patch?

Thanks,
Miquèl

2018-07-05 08:49:12

by Wei Yongjun

[permalink] [raw]
Subject: RE: [PATCH -next v3] mtd: spinand: fix missing unlock on error

>
> Hi Wei,
>
> Wei Yongjun <[email protected]> wrote on Wed, 4 Jul 2018
> 09:30:27
> +0000:
>
> > Add the missing unlock before return from function
> > spinand_mtd_(read|write) in the error handling case.
> >
> > Fixes: c898e0526fb6 ("mtd: nand: Add core infrastructure to support SPI
> NANDs")
> > Signed-off-by: Wei Yongjun <[email protected]>
> > ---
>
> Thanks for the two fixes over the spinand work. As this code is not
> yet upstream, do you mind if I fold those fixes directly with the
> initial patch?

No, I don't. Feel free to fold them to the initial patch.

Regards,
Wei yongjun

2018-07-08 21:51:48

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH -next v3] mtd: spinand: fix missing unlock on error

Hi Wei,

Wei Yongjun <[email protected]> wrote on Wed, 4 Jul 2018 09:30:27
+0000:

> Add the missing unlock before return from function
> spinand_mtd_(read|write) in the error handling case.
>
> Fixes: c898e0526fb6 ("mtd: nand: Add core infrastructure to support SPI NANDs")
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> v2 -> v3: remove blank line
> v1 -> v2: using break instead of return
> ---

Merged with the original commit too.

Thanks,
Miquèl