diff mbox

[v2] mtd: spi-nor: Potential oops on error path in quad_enable()

Message ID 20170505053356.vcgboleyqigluhc3@mwanda
State Accepted
Commit 05d090f00203bdcf722b9cb6d5ac57c165e2c95c
Delegated to: Cyrille Pitchen
Headers show

Commit Message

Dan Carpenter May 5, 2017, 5:33 a.m. UTC
Before commit cff959958832 ("mtd: spi-nor: introduce SPI 1-2-2 and SPI
1-4-4 protocols") then we treated 1 as -EINVAL in the caller but after
that commit we changed to propagate the return.  My static checker
complains that it's eventually passed to an ERR_PTR() and later
dereferenced, but I'm not totally certain if that's true.  Regardless,
returning 1 is wrong.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Propogate the error code from spi_nor_wait_till_ready() instead of
    just returning -EINVAL

Comments

Cyrille Pitchen May 10, 2017, 10:03 a.m. UTC | #1
Le 05/05/2017 à 07:33, Dan Carpenter a écrit :
> Before commit cff959958832 ("mtd: spi-nor: introduce SPI 1-2-2 and SPI
> 1-4-4 protocols") then we treated 1 as -EINVAL in the caller but after
> that commit we changed to propagate the return.  My static checker
> complains that it's eventually passed to an ERR_PTR() and later
> dereferenced, but I'm not totally certain if that's true.  Regardless,
> returning 1 is wrong.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied to the github/spi-nor tree.

Thanks!
> ---
> v2: Propogate the error code from spi_nor_wait_till_ready() instead of
>     just returning -EINVAL
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 060a59e716be..eef55b597ec7 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -1389,8 +1389,9 @@ static int macronix_quad_enable(struct spi_nor *nor)
>  
>  	write_sr(nor, val | SR_QUAD_EN_MX);
>  
> -	if (spi_nor_wait_till_ready(nor))
> -		return 1;
> +	ret = spi_nor_wait_till_ready(nor);
> +	if (ret)
> +		return ret;
>  
>  	ret = read_sr(nor);
>  	if (!(ret > 0 && (ret & SR_QUAD_EN_MX))) {
>
diff mbox

Patch

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 060a59e716be..eef55b597ec7 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1389,8 +1389,9 @@  static int macronix_quad_enable(struct spi_nor *nor)
 
 	write_sr(nor, val | SR_QUAD_EN_MX);
 
-	if (spi_nor_wait_till_ready(nor))
-		return 1;
+	ret = spi_nor_wait_till_ready(nor);
+	if (ret)
+		return ret;
 
 	ret = read_sr(nor);
 	if (!(ret > 0 && (ret & SR_QUAD_EN_MX))) {