]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
mtd: spi-nor: Move condition to avoid a NULL check
authorTudor Ambarus <tudor.ambarus@microchip.com>
Fri, 25 Oct 2019 14:28:36 +0000 (14:28 +0000)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Mon, 11 Nov 2019 18:42:52 +0000 (20:42 +0200)
When the controller is not under the SPI-MEM interface it may implement
the optional controller_ops->erase() method.

nor->spimem and nor->controller_ops are mutually exclusive. Move the
nor->controller_ops->erase != NULL check as an 'else if' case to
nor->spimem, in order to avoid the nor->controller_ops != NULL
check.

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 f5d24ccf5108bbd58d86292c31d9798f66c24acd..fc39db179cbc6a7df9f084f3bcb9b34a5ac08b89 100644 (file)
@@ -1367,9 +1367,6 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 
        addr = spi_nor_convert_addr(nor, addr);
 
-       if (nor->controller_ops && nor->controller_ops->erase)
-               return nor->controller_ops->erase(nor, addr);
-
        if (nor->spimem) {
                struct spi_mem_op op =
                        SPI_MEM_OP(SPI_MEM_OP_CMD(nor->erase_opcode, 1),
@@ -1378,6 +1375,8 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
                                   SPI_MEM_OP_NO_DATA);
 
                return spi_mem_exec_op(nor->spimem, &op);
+       } else if (nor->controller_ops->erase) {
+               return nor->controller_ops->erase(nor, addr);
        }
 
        /*