U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] env: mtd: fix usability with NAND flashes
@ 2025-05-06  7:15 Weijie Gao
  2025-05-06 11:44 ` Christian Marangi
  2025-05-23 14:01 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Weijie Gao @ 2025-05-06  7:15 UTC (permalink / raw)
  To: u-boot
  Cc: GSS_MTK_Uboot_upstream, Joe Hershberger, Tom Rini,
	Christian Marangi, Weijie Gao

1. As this is for MTD-based devices, the Kconfig dependency should be MTD
   instead of only spi-nor flashes
2. Initialize saved_buf to avoid crash on free()
3. Remaining size shoule be set correctly to write_size

Fixes: 03fb08d4aef (env: Introduce support for MTD)
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
---
 env/Kconfig | 2 +-
 env/mtd.c   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/env/Kconfig b/env/Kconfig
index 1e876c6fa85..ce869a24d46 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -404,7 +404,7 @@ config ENV_IS_IN_SPI_FLASH
 
 config ENV_IS_IN_MTD
 	bool "Environment is in MTD flash"
-	depends on !CHAIN_OF_TRUST && (SPI_FLASH || DM_SPI_FLASH)
+	depends on !CHAIN_OF_TRUST && MTD
 	default y if ARCH_AIROHA
 	help
 	  Define this if you have a MTD Flash memory device which you
diff --git a/env/mtd.c b/env/mtd.c
index 721faebd8f2..d7ec30e183a 100644
--- a/env/mtd.c
+++ b/env/mtd.c
@@ -32,7 +32,7 @@ static int setup_mtd_device(struct mtd_info **mtd_env)
 
 static int env_mtd_save(void)
 {
-	char *saved_buf, *write_buf, *tmp;
+	char *saved_buf = NULL, *write_buf, *tmp;
 	struct erase_info ei = { };
 	struct mtd_info *mtd_env;
 	u32 sect_size, sect_num;
@@ -105,7 +105,7 @@ static int env_mtd_save(void)
 	}
 
 	offset = CONFIG_ENV_OFFSET;
-	remaining = sect_size;
+	remaining = write_size;
 	tmp = write_buf;
 
 	puts("Writing to MTD...");
-- 
2.34.1


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

* Re: [PATCH] env: mtd: fix usability with NAND flashes
  2025-05-06  7:15 [PATCH] env: mtd: fix usability with NAND flashes Weijie Gao
@ 2025-05-06 11:44 ` Christian Marangi
  2025-05-23 14:01 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Marangi @ 2025-05-06 11:44 UTC (permalink / raw)
  To: Weijie Gao; +Cc: u-boot, GSS_MTK_Uboot_upstream, Joe Hershberger, Tom Rini

On Tue, May 06, 2025 at 03:15:01PM +0800, Weijie Gao wrote:
> 1. As this is for MTD-based devices, the Kconfig dependency should be MTD
>    instead of only spi-nor flashes
> 2. Initialize saved_buf to avoid crash on free()
> 3. Remaining size shoule be set correctly to write_size
> 
> Fixes: 03fb08d4aef (env: Introduce support for MTD)
> Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>

Reviewed-by: Christian Marangi <ansuelsmth@gmail.com>

> ---
>  env/Kconfig | 2 +-
>  env/mtd.c   | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/env/Kconfig b/env/Kconfig
> index 1e876c6fa85..ce869a24d46 100644
> --- a/env/Kconfig
> +++ b/env/Kconfig
> @@ -404,7 +404,7 @@ config ENV_IS_IN_SPI_FLASH
>  
>  config ENV_IS_IN_MTD
>  	bool "Environment is in MTD flash"
> -	depends on !CHAIN_OF_TRUST && (SPI_FLASH || DM_SPI_FLASH)
> +	depends on !CHAIN_OF_TRUST && MTD
>  	default y if ARCH_AIROHA
>  	help
>  	  Define this if you have a MTD Flash memory device which you
> diff --git a/env/mtd.c b/env/mtd.c
> index 721faebd8f2..d7ec30e183a 100644
> --- a/env/mtd.c
> +++ b/env/mtd.c
> @@ -32,7 +32,7 @@ static int setup_mtd_device(struct mtd_info **mtd_env)
>  
>  static int env_mtd_save(void)
>  {
> -	char *saved_buf, *write_buf, *tmp;
> +	char *saved_buf = NULL, *write_buf, *tmp;
>  	struct erase_info ei = { };
>  	struct mtd_info *mtd_env;
>  	u32 sect_size, sect_num;
> @@ -105,7 +105,7 @@ static int env_mtd_save(void)
>  	}
>  
>  	offset = CONFIG_ENV_OFFSET;
> -	remaining = sect_size;
> +	remaining = write_size;
>  	tmp = write_buf;
>  
>  	puts("Writing to MTD...");
> -- 
> 2.34.1
> 

-- 
	Ansuel

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

* Re: [PATCH] env: mtd: fix usability with NAND flashes
  2025-05-06  7:15 [PATCH] env: mtd: fix usability with NAND flashes Weijie Gao
  2025-05-06 11:44 ` Christian Marangi
@ 2025-05-23 14:01 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2025-05-23 14:01 UTC (permalink / raw)
  To: u-boot, Weijie Gao
  Cc: GSS_MTK_Uboot_upstream, Joe Hershberger, Christian Marangi

On Tue, 06 May 2025 15:15:01 +0800, Weijie Gao wrote:

> 1. As this is for MTD-based devices, the Kconfig dependency should be MTD
>    instead of only spi-nor flashes
> 2. Initialize saved_buf to avoid crash on free()
> 3. Remaining size shoule be set correctly to write_size
> 
> 

Applied to u-boot/master, thanks!

[1/1] env: mtd: fix usability with NAND flashes
      commit: 7c52bca8121fdd967edf24402590b8aacf4fd23a
-- 
Tom



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

end of thread, other threads:[~2025-05-23 14:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06  7:15 [PATCH] env: mtd: fix usability with NAND flashes Weijie Gao
2025-05-06 11:44 ` Christian Marangi
2025-05-23 14:01 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox