[PATCH] [MTD] UBI: simplify wl.c

Alexander Schmidt alexs at linux.vnet.ibm.com
Mon Mar 26 09:10:10 EDT 2007


The patch simplifies the wear leveling a little bit by reusing the
find_wl_entry function and removing some duplicated code.

Signed-off-by: Alexander Schmidt <alexs at linux.vnet.ibm.com>
---
 drivers/mtd/ubi/wl.c |   69 +++++++++++++++------------------------------------
 1 files changed, 21 insertions(+), 48 deletions(-)

--- dedekind-ubi-2.6.orig/drivers/mtd/ubi/wl.c
+++ dedekind-ubi-2.6/drivers/mtd/ubi/wl.c
@@ -492,51 +492,6 @@ static struct ubi_wl_entry *find_wl_entr
 }
 
 /**
- * pick_unknown - select an "unknown" physical eraseblock.
- * @ubi: UBI device description object
- *
- * This function returns a physical eraseblock for "unknown" data. The wl->lock
- * must be locked. The @wl->free list must not be empty.
- */
-static struct ubi_wl_entry *pick_unknown(struct ubi_device *ubi)
-{
-	int medium_ec;
-	struct rb_node *p;
-	struct ubi_wl_entry *first, *last, *e;
-
-	/*
-	 * For unknown data we are trying to pick a physical eraseblock with
-	 * medium erase counter. But we by no means can pick a physical
-	 * eraseblock with erase counter greater or equivalent then the the
-	 * lowest erase counter plus %WL_FREE_MAX_DIFF.
-	 */
-
-	first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb);
-	last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, rb);
-
-	if (last->ec - first->ec < WL_FREE_MAX_DIFF)
-		return rb_entry(ubi->free.rb_node, struct ubi_wl_entry, rb);
-
-	medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2;
-	e = first;
-
-	p = ubi->free.rb_node;
-	while (p) {
-		struct ubi_wl_entry *e1;
-
-		e1 = rb_entry(p, struct ubi_wl_entry, rb);
-		if (e1->ec >= medium_ec)
-			p = p->rb_left;
-		else {
-			p = p->rb_right;
-			e = e1;
-		}
-	}
-
-	return e;
-}
-
-/**
  * ubi_wl_get_peb - get a physical eraseblock.
  * @ubi: UBI device description object
  * @dtype: type of data which will be stored in this physical eraseblock
@@ -546,8 +501,8 @@ static struct ubi_wl_entry *pick_unknown
  */
 int ubi_wl_get_peb(struct ubi_device *ubi, int dtype)
 {
-	int err, protect;
-	struct ubi_wl_entry *e;
+	int err, protect, medium_ec;
+	struct ubi_wl_entry *e, *first, *last;
 	struct ubi_wl_prot_entry *pe;
 
 	ubi_assert(dtype == UBI_DATA_LONGTERM || dtype == UBI_DATA_SHORTTERM ||
@@ -589,7 +544,25 @@ retry:
 			protect = LT_PROTECTION;
 			break;
 		case UBI_DATA_UNKNOWN:
-			e = pick_unknown(ubi);
+			/*
+			 * For unknown data we pick a physical eraseblock with
+			 * medium erase counter. But we by no means can pick a
+			 * physical eraseblock with erase counter greater or
+			 * equivalent than the lowest erase counter plus
+			 * %WL_FREE_MAX_DIFF.
+			 */
+			first = rb_entry(rb_first(&ubi->free),
+					 struct ubi_wl_entry, rb);
+			last = rb_entry(rb_last(&ubi->free),
+					struct ubi_wl_entry, rb);
+
+			if (last->ec - first->ec < WL_FREE_MAX_DIFF)
+				e = rb_entry(ubi->free.rb_node,
+						struct ubi_wl_entry, rb);
+			else {
+				medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2;
+				e = find_wl_entry(&ubi->free, medium_ec);
+			}
 			protect = U_PROTECTION;
 			break;
 		case UBI_DATA_SHORTTERM:




More information about the linux-mtd mailing list