From patchwork Sun Jan 19 23:13:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 239776 List-Id: U-Boot discussion From: seanga2 at gmail.com (Sean Anderson) Date: Sun, 19 Jan 2020 18:13:26 -0500 Subject: [PATCH v2] cmd: Ensure sf operates on spi flash In-Reply-To: <65962791-e8ca-ac64-9bc0-1de8f19d94d2@gmail.com> References: <65962791-e8ca-ac64-9bc0-1de8f19d94d2@gmail.com> Message-ID: Currently, the sf command will probe anything attached to an spi bus, regardless of whether it is UCLASS_SPI_FLASH. This came up when testing the mmc_spi driver, which is accessed via spi but is UCLASS_MMC. If the uclass is not what sf expects, then the "flash" variable will not actually have type spi_nor. This patch adds a check so we don't clobber any data if the user requests us to probe a device which is not an spi flash. Signed-off-by: Sean Anderson --- Changes for v2: Fixed Signed-off-by line Fix typo (SPU_FLASH -> SPI_FLASH) cmd/sf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/sf.c b/cmd/sf.c index e993b3e5ad..39d05ae229 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -132,6 +132,10 @@ static int do_spi_flash_probe(int argc, char * const argv[]) printf("Failed to initialize SPI flash at %u:%u (error %d)\n", bus, cs, ret); return 1; + } else if (new->driver->id != UCLASS_SPI_FLASH) { + printf("SPI device is not SPI flash: uclass is %d, expected %d\n", + new->driver->id, UCLASS_SPI_FLASH); + return 1; } flash = dev_get_uclass_priv(new);