aboutsummaryrefslogtreecommitdiff
path: root/package/boot/uboot-mediatek/patches/130-01-env-mtd-add-the-missing-put_mtd_device.patch
blob: 61c4b6e8b1cd33cc7922b9921adfb0d73cd5add8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From 0508c8e120d275d994e6099eb9c60bfaec0c3f5f Mon Sep 17 00:00:00 2001
From: Shiji Yang <yangshiji66@outlook.com>
Date: Mon, 21 Jul 2025 21:32:16 +0800
Subject: [PATCH 1/2] env: mtd: add the missing put_mtd_device()

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 | 6 ++++++
 1 file changed, 6 insertions(+)

--- 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);