mtd: spi-nor: Make sure nor->spimem and nor->controller_ops are mutually exclusive
authorTudor Ambarus <tudor.ambarus@microchip.com>
Fri, 25 Oct 2019 14:28:34 +0000 (14:28 +0000)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Mon, 11 Nov 2019 18:42:13 +0000 (20:42 +0200)
Expand the spi_nor_check() to make sure that nor->spimem and
nor->controller_ops are mutually 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>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
drivers/mtd/spi-nor/spi-nor.c

index 824649e..f5d24cc 100644 (file)
@@ -2878,6 +2878,7 @@ write_err:
 static int spi_nor_check(struct spi_nor *nor)
 {
        if (!nor->dev ||
+           (!nor->spimem && !nor->controller_ops) ||
            (!nor->spimem && nor->controller_ops &&
            (!nor->controller_ops->read ||
             !nor->controller_ops->write ||
@@ -2887,6 +2888,11 @@ static int spi_nor_check(struct spi_nor *nor)
                return -EINVAL;
        }
 
+       if (nor->spimem && nor->controller_ops) {
+               dev_err(nor->dev, "nor->spimem and nor->controller_ops are mutually exclusive, please set just one of them.\n");
+               return -EINVAL;
+       }
+
        return 0;
 }