diff mbox series

[v2,1/2] mtd: spi-nor: Make sure nor->spimem and nor->controller_ops are mutual exclusive

Message ID 20191025142811.541-1-tudor.ambarus@microchip.com
State Changes Requested
Delegated to: Ambarus Tudor
Headers show
Series [v2,1/2] mtd: spi-nor: Make sure nor->spimem and nor->controller_ops are mutual exclusive | expand

Commit Message

Tudor Ambarus Oct. 25, 2019, 2:28 p.m. UTC
From: Tudor Ambarus <tudor.ambarus@microchip.com>

Expand the spi_nor_check() to make sure that nor->spimem and
nor->controller_ops are mutual exclusive.

Fixes: b35b9a10362d ("mtd: spi-nor: Move m25p80 code in spi-nor.c")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
v2: new patch

 drivers/mtd/spi-nor/spi-nor.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Boris Brezillon Nov. 11, 2019, 9:02 a.m. UTC | #1
On Fri, 25 Oct 2019 14:28:34 +0000
<Tudor.Ambarus@microchip.com> wrote:

> From: Tudor Ambarus <tudor.ambarus@microchip.com>
> 
> Expand the spi_nor_check() to make sure that nor->spimem and
> nor->controller_ops are mutual exclusive.

			  ^mutually

> 
> Fixes: b35b9a10362d ("mtd: spi-nor: Move m25p80 code in spi-nor.c")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
> v2: new patch
> 
>  drivers/mtd/spi-nor/spi-nor.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index a6f9f833c862..b452d3d0de28 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2741,6 +2741,12 @@ static int spi_nor_check(struct spi_nor *nor)
>  		return -EINVAL;
>  	}
>  
> +	if ((nor->spimem && nor->controller_ops) ||
> +	    (!nor->spimem && !nor->controller_ops)) {
> +		dev_err(nor->dev, "nor->spimem and nor->controller_ops are mutual exclusive\n");

Hm, the test does more than checking that only one of nor->spimem
nor->controller_ops is set, it also checks that at least one of them is
provided. Maybe you should split those tests and have a different error
message for each, or make the error message more generic.

> +		return -EINVAL;
> +	}
> +
>  	return 0;
>  }
>
diff mbox series

Patch

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index a6f9f833c862..b452d3d0de28 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2741,6 +2741,12 @@  static int spi_nor_check(struct spi_nor *nor)
 		return -EINVAL;
 	}
 
+	if ((nor->spimem && nor->controller_ops) ||
+	    (!nor->spimem && !nor->controller_ops)) {
+		dev_err(nor->dev, "nor->spimem and nor->controller_ops are mutual exclusive\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }