Patchwork [1/2] ubi: Remove PEB from free tree in get_peb_for_wl()

login
register
mail settings
Submitter Richard Weinberger
Date Dec. 3, 2012, 7:57 p.m.
Message ID <1354564667-9549-2-git-send-email-richard@nod.at>
Download mbox | patch
Permalink /patch/203431/
State Accepted
Commit ed4b7021cb51fe5a0f260df03298709347a26967
Headers show

Comments

Richard Weinberger - Dec. 3, 2012, 7:57 p.m.
If UBI is built without fastmap, get_peb_for_wl() has to
remove the PEB manially from the free tree.
Otherwise the requested PEB lives in two trees.

Reported-by: Zach Sadecki <zsadecki@itwatchdogs.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/wl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Artem Bityutskiy - Dec. 4, 2012, 8:34 a.m.
On Mon, 2012-12-03 at 20:57 +0100, Richard Weinberger wrote:
> If UBI is built without fastmap, get_peb_for_wl() has to
> remove the PEB manially from the free tree.
> Otherwise the requested PEB lives in two trees.
> 
> Reported-by: Zach Sadecki <zsadecki@itwatchdogs.com>
> Signed-off-by: Richard Weinberger <richard@nod.at>

Thanks Richard, I'll send this to Linus ASAP.

> diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> index da7b449..1f9f5f7 100644
> --- a/drivers/mtd/ubi/wl.c
> +++ b/drivers/mtd/ubi/wl.c
> @@ -679,7 +679,13 @@ static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
>  #else
>  static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
>  {
> -	return find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
> +	struct ubi_wl_entry *e;
> +
> +	e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
> +	self_check_in_wl_tree(ubi, e, &ubi->free);

Looking at all for these 'self_check_in_wl_tree()', I think can kill
most of them and just make 'find_wl_entry()' complain if it did not find
anything. But this is a subject of a separate patch.
Richard Weinberger - Dec. 4, 2012, 10:24 a.m.
Am Tue, 04 Dec 2012 10:34:39 +0200
schrieb Artem Bityutskiy <dedekind1@gmail.com>:
 > Looking at all for these 'self_check_in_wl_tree()', I think can kill
> most of them and just make 'find_wl_entry()' complain if it did not
> find anything. But this is a subject of a separate patch.
>

Yeah. I've also thought about that.
This is material for 3.8-rc0.

Thanks,
//richard

Patch

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index da7b449..1f9f5f7 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -679,7 +679,13 @@  static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
 #else
 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
 {
-	return find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
+	struct ubi_wl_entry *e;
+
+	e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
+	self_check_in_wl_tree(ubi, e, &ubi->free);
+	rb_erase(&e->u.rb, &ubi->free);
+
+	return e;
 }
 
 int ubi_wl_get_peb(struct ubi_device *ubi)