UBI: Fastmap: free unused fastmap anchor peb during detach
PATCH v2 1/2 UBI: Fastmap: free unused fastmap anchor peb during detach
When CONFIG_MTD_UBI_FASTMAP is enabled, fm_anchor will be assigned a free PEB during ubi_wl_init() or ubi_update_fastmap(). However if fastmap is not used or disabled on the MTD device, ubi_wl_entry related with the PEB will not be freed during detach.
So Fix it by freeing the unused fastmap anchor during detach.
--- drivers/mtd/ubi/fastmap-wl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
---
v2: patch splitting as suggested by Sascha
drivers/mtd/ubi/fastmap-wl.c +13 -2
@@ -39,6 +39,13 @@ static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)return victim; } +static inline void return_unused_peb (struct ubi_device *ubi, +struct ubi_wl_entry *e) +{ +wl_tree_add (e, &ubi->free); + ubi->free_count++; +} +/** * return_unused_pool_pebs - returns unused PEB to the free tree. * @ubi: UBI device description object
@@ -52,8 +59,7 @@ static void return_unused_pool_pebs(struct ubi_device *ubi,for (i = pool->used; i < pool->size; i++) { e = ubi->lookuptbl[pool->pebs[i]]; -wl_tree_add (e, &ubi->free); - ubi->free_count++; +return_unused_peb (ubi, e); } }
@@ -361,6 +367,11 @@ static void ubi_fastmap_close(struct ubi_device *ubi)return_unused_pool_pebs (ubi, &ubi->fm_pool);return_unused_pool_pebs (ubi, &ubi->fm_wl_pool); +if (ubi->fm_anchor) { +return_unused_peb (ubi, ubi->fm_anchor); + ubi->fm_anchor =NULL ; + } +if (ubi->fm) {for (i =0 ; i < ubi->fm->used_blocks; i++)kfree (ubi->fm->e[i]);
Signature · 6 lines
2.22.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 2/2 UBI: fastmap: only produce the initial anchor PEB when fastmap is used
Don't produce the initial anchor PEB when ubi device is read-only or fastmap is disabled, else the resulting PEB will be unusable to any volume.
--- drivers/mtd/ubi/wl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/ubi/wl.c +2 -1
@@ -1879,7 +1879,8 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai) goto out_free;#ifdef CONFIG_MTD_UBI_FASTMAP -ubi_ensure_anchor_pebs (ubi); +if (!ubi->ro_mode && !ubi->fm_disabled) +ubi_ensure_anchor_pebs (ubi);#endif return 0 ;
Signature · 6 lines
2.22.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 12 lines · Hou Tao
When
CONFIG_MTD_UBI_FASTMAPis enabled,fm_anchorwill be assigned a free PEB duringubi_wl_init()orubi_update_fastmap(). However if fastmap is not used or disabled on the MTD device,ubi_wl_entryrelated with the PEB will not be freed during detach.So Fix it by freeing the unused fastmap anchor during detach.
Fixes f9c34bb52997 ("ubi: Fix producing anchor PEBs")Reported-by [email protected]Reviewed-by Sascha Hauer <[email protected]>Signed-off-by Hou Tao <[email protected]>
Quoted 5 lines
--- drivers/mtd/ubi/fastmap-wl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)---
v2: patch splitting as suggested by Sascha
Both applied, thanks a lot!
Signature · 6 lines
Thanks, //richard ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/