public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2] cmd: Ensure sf operates on spi flash
Date: Sun, 19 Jan 2020 18:13:26 -0500	[thread overview]
Message-ID: <f002d2ef-539e-175a-7184-a431d73f9341@gmail.com> (raw)
In-Reply-To: <65962791-e8ca-ac64-9bc0-1de8f19d94d2@gmail.com>

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 <seanga2@gmail.com>
---
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);
-- 
2.25.0

  reply	other threads:[~2020-01-19 23:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-19 23:02 [PATCH] cmd: Ensure sf operates on spi flash Sean Anderson
2020-01-19 23:13 ` Sean Anderson [this message]
2020-02-04 10:49   ` [PATCH v2] " Bin Meng
2020-02-04 14:10     ` Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f002d2ef-539e-175a-7184-a431d73f9341@gmail.com \
    --to=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox