env: mtd: fix usability with NAND flashes
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 should be set correctly to write_size
Fixes: 03fb08d4aef (env: Introduce support for MTD)
Reviewed-by: Christian Marangi <ansuelsmth@gmail.com>
diff --git a/env/mtd.c b/env/mtd.c
index 721faeb..d7ec30e 100644
--- a/env/mtd.c
+++ b/env/mtd.c
@@ -32,7 +32,7 @@
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 @@
}
offset = CONFIG_ENV_OFFSET;
- remaining = sect_size;
+ remaining = write_size;
tmp = write_buf;
puts("Writing to MTD...");