All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] spi: sf_ops: Check the return value from spi_flash_cmd_read_status()
@ 2015-11-17 14:37 Fabio Estevam
  2015-11-17 19:05 ` Jagan Teki
  0 siblings, 1 reply; 2+ messages in thread
From: Fabio Estevam @ 2015-11-17 14:37 UTC (permalink / raw)
  To: u-boot

We should check the return value from spi_flash_cmd_read_status() and
propagate it in the case of error.

This fixes a defect caught by Coverity.

Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 drivers/mtd/spi/sf_ops.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 384224d..6cc2d31 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -663,8 +663,11 @@ int stm_lock(struct spi_flash *flash, u32 ofs, size_t len)
 	u8 status_old, status_new;
 	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
 	u8 shift = ffs(mask) - 1, pow, val;
+	int ret;
 
-	spi_flash_cmd_read_status(flash, &status_old);
+	ret = spi_flash_cmd_read_status(flash, &status_old);
+	if (ret)
+		return ret;
 
 	/* SPI NOR always locks to the end */
 	if (ofs + len != flash->size) {
@@ -714,8 +717,11 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len)
 	uint8_t status_old, status_new;
 	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
 	u8 shift = ffs(mask) - 1, pow, val;
+	int ret;
 
-	spi_flash_cmd_read_status(flash, &status_old);
+	ret = spi_flash_cmd_read_status(flash, &status_old);
+	if (ret)
+		return ret;
 
 	/* Cannot unlock; would unlock larger region than requested */
 	if (stm_is_locked_sr(flash, status_old, ofs - flash->erase_size,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] spi: sf_ops: Check the return value from spi_flash_cmd_read_status()
  2015-11-17 14:37 [U-Boot] [PATCH] spi: sf_ops: Check the return value from spi_flash_cmd_read_status() Fabio Estevam
@ 2015-11-17 19:05 ` Jagan Teki
  0 siblings, 0 replies; 2+ messages in thread
From: Jagan Teki @ 2015-11-17 19:05 UTC (permalink / raw)
  To: u-boot

On 17 November 2015 at 20:07, Fabio Estevam <fabio.estevam@freescale.com> wrote:
> We should check the return value from spi_flash_cmd_read_status() and
> propagate it in the case of error.
>
> This fixes a defect caught by Coverity.
>
> Reported-by: Tom Rini <trini@konsulko.com>
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
>  drivers/mtd/spi/sf_ops.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
> index 384224d..6cc2d31 100644
> --- a/drivers/mtd/spi/sf_ops.c
> +++ b/drivers/mtd/spi/sf_ops.c
> @@ -663,8 +663,11 @@ int stm_lock(struct spi_flash *flash, u32 ofs, size_t len)
>         u8 status_old, status_new;
>         u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
>         u8 shift = ffs(mask) - 1, pow, val;
> +       int ret;
>
> -       spi_flash_cmd_read_status(flash, &status_old);
> +       ret = spi_flash_cmd_read_status(flash, &status_old);
> +       if (ret)

if (ret < 0) is better check.

> +               return ret;
>
>         /* SPI NOR always locks to the end */
>         if (ofs + len != flash->size) {
> @@ -714,8 +717,11 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len)
>         uint8_t status_old, status_new;
>         u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
>         u8 shift = ffs(mask) - 1, pow, val;
> +       int ret;
>
> -       spi_flash_cmd_read_status(flash, &status_old);
> +       ret = spi_flash_cmd_read_status(flash, &status_old);
> +       if (ret)
> +               return ret;
>
>         /* Cannot unlock; would unlock larger region than requested */
>         if (stm_is_locked_sr(flash, status_old, ofs - flash->erase_size,
> --
> 1.9.1

thanks!
-- 
Jagan | openedev.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-17 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 14:37 [U-Boot] [PATCH] spi: sf_ops: Check the return value from spi_flash_cmd_read_status() Fabio Estevam
2015-11-17 19:05 ` Jagan Teki

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.