All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cmd: Ensure sf operates on spi flash
@ 2020-01-19 23:02 Sean Anderson
  2020-01-19 23:13 ` [PATCH v2] " Sean Anderson
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Anderson @ 2020-01-19 23:02 UTC (permalink / raw)
  To: u-boot

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>
---
 cmd/sf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cmd/sf.c b/cmd/sf.c
index e993b3e5ad..21a410c40f 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_SPU_FLASH);
+		return 1;
 	}
 
 	flash = dev_get_uclass_priv(new);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] cmd: Ensure sf operates on spi flash
  2020-01-19 23:02 [PATCH] cmd: Ensure sf operates on spi flash Sean Anderson
@ 2020-01-19 23:13 ` Sean Anderson
  2020-02-04 10:49   ` Bin Meng
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Anderson @ 2020-01-19 23:13 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] cmd: Ensure sf operates on spi flash
  2020-01-19 23:13 ` [PATCH v2] " Sean Anderson
@ 2020-02-04 10:49   ` Bin Meng
  2020-02-04 14:10     ` Sean Anderson
  0 siblings, 1 reply; 4+ messages in thread
From: Bin Meng @ 2020-02-04 10:49 UTC (permalink / raw)
  To: u-boot

Hi Sean,

On Mon, Jan 20, 2020 at 7:13 AM Sean Anderson <seanga2@gmail.com> wrote:
>
> 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,

Did you do something like:

=> sf probe 1 0

?

> 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(+)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Regards,
Bin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] cmd: Ensure sf operates on spi flash
  2020-02-04 10:49   ` Bin Meng
@ 2020-02-04 14:10     ` Sean Anderson
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Anderson @ 2020-02-04 14:10 UTC (permalink / raw)
  To: u-boot

On 2/4/20 5:49 AM, Bin Meng wrote:
> Hi Sean,
> 
> On Mon, Jan 20, 2020 at 7:13 AM Sean Anderson <seanga2@gmail.com> wrote:
>>
>> 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,
> 
> Did you do something like:
> 
> => sf probe 1 0

sf probe 0, but yes. I forgot that my spi bus 0 had the SD card on it
not the spi flash. I feel like this sort of thing should be caught by
u-boot to prevent the user from almost certainly causing a segfault.

--Sean

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-04 14:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-19 23:02 [PATCH] cmd: Ensure sf operates on spi flash Sean Anderson
2020-01-19 23:13 ` [PATCH v2] " Sean Anderson
2020-02-04 10:49   ` Bin Meng
2020-02-04 14:10     ` Sean Anderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.