]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
env: mtd: add the missing put_mtd_device()
authorShiji Yang <yangshiji66@outlook.com>
Fri, 25 Jul 2025 00:20:44 +0000 (08:20 +0800)
committerTom Rini <trini@konsulko.com>
Fri, 1 Aug 2025 23:58:58 +0000 (17:58 -0600)
The mtd device is got in setup_mtd_device(), we must put the mtd
device before exiting the function to update the mtd use count.
This patch fixes the following env error:

> Removing MTD device #2 (u-boot-env) with use count 1
> Error when deleting partition "u-boot-env" (-16)

Fixes: 03fb08d4aef8 ("env: Introduce support for MTD")
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
env/mtd.c

index d7ec30e183acd75aeb00d34a38de5f9ddda55680..ad263ed4b29b636a97e2d6c1ecdcfc4d54264652 100644 (file)
--- a/env/mtd.c
+++ b/env/mtd.c
@@ -131,6 +131,8 @@ static int env_mtd_save(void)
        puts("done\n");
 
 done:
+       put_mtd_device(mtd_env);
+
        if (saved_buf)
                free(saved_buf);
 
@@ -188,6 +190,8 @@ static int env_mtd_load(void)
                gd->env_valid = ENV_VALID;
 
 out:
+       put_mtd_device(mtd_env);
+
        free(buf);
 
        return ret;
@@ -280,6 +284,8 @@ static int env_mtd_erase(void)
        ret = 0;
 
 done:
+       put_mtd_device(mtd_env);
+
        if (saved_buf)
                free(saved_buf);