From: Alexander Schmidt <alexs@linux.vnet.ibm.com>
To: Artem.Bityutskiy@nokia.com,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Subject: [PATCH] [MTD] UBI: simplify wl.c
Date: Mon, 26 Mar 2007 15:10:10 +0200 [thread overview]
Message-ID: <200703261510.10287.alexs@linux.vnet.ibm.com> (raw)
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@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:
reply other threads:[~2007-03-26 13:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200703261510.10287.alexs@linux.vnet.ibm.com \
--to=alexs@linux.vnet.ibm.com \
--cc=Artem.Bityutskiy@nokia.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox