Skip to content

Commit c16f39d

Browse files
Hou Taorichardweinberger
authored andcommitted
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. Fixes: f9c34bb ("ubi: Fix producing anchor PEBs") Reported-by: [email protected] Reviewed-by: Sascha Hauer <[email protected]> Signed-off-by: Hou Tao <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 927cc5c commit c16f39d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/mtd/ubi/fastmap-wl.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)
3939
return victim;
4040
}
4141

42+
static inline void return_unused_peb(struct ubi_device *ubi,
43+
struct ubi_wl_entry *e)
44+
{
45+
wl_tree_add(e, &ubi->free);
46+
ubi->free_count++;
47+
}
48+
4249
/**
4350
* return_unused_pool_pebs - returns unused PEB to the free tree.
4451
* @ubi: UBI device description object
@@ -52,8 +59,7 @@ static void return_unused_pool_pebs(struct ubi_device *ubi,
5259

5360
for (i = pool->used; i < pool->size; i++) {
5461
e = ubi->lookuptbl[pool->pebs[i]];
55-
wl_tree_add(e, &ubi->free);
56-
ubi->free_count++;
62+
return_unused_peb(ubi, e);
5763
}
5864
}
5965

@@ -361,6 +367,11 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
361367
return_unused_pool_pebs(ubi, &ubi->fm_pool);
362368
return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
363369

370+
if (ubi->fm_anchor) {
371+
return_unused_peb(ubi, ubi->fm_anchor);
372+
ubi->fm_anchor = NULL;
373+
}
374+
364375
if (ubi->fm) {
365376
for (i = 0; i < ubi->fm->used_blocks; i++)
366377
kfree(ubi->fm->e[i]);

0 commit comments

Comments
 (0)