lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1339293473-29444-1-git-send-email-daniel.santos@pobox.com>
Date:	Sat,  9 Jun 2012 20:57:53 -0500
From:	Daniel Santos <daniel.santos@...ox.com>
To:	Richard Weinberger <richard@....at>
Cc:	LKML <linux-kernel@...r.kernel.org>,
	Daniel Santos <daniel.santos@...ox.com>
Subject: [PATCH] drivers/mtd/ubi/wl.c: optimization for in_wl_tree()

Essentially, instead of performing a search through the tree from the
top down, like we would when doing a lookup, we can just search from the
node up and then check to see if the root of the tree that the node is
in is the same as the one supplied.  Note that if you call this passing
a ubi_wl_entry who's u.rb member has not been inited with rb_init_node()
or added to a tree, the results are undefined.

This should be a little faster, but mostly, it'll be smaller.
---
 drivers/mtd/ubi/wl.c |   32 ++++++++------------------------
 1 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 9df100a..d415011 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -287,33 +287,17 @@ static int produce_free_peb(struct ubi_device *ubi)
  */
 static int in_wl_tree(struct ubi_wl_entry *e, struct rb_root *root)
 {
-	struct rb_node *p;
-
-	p = root->rb_node;
-	while (p) {
-		struct ubi_wl_entry *e1;
+	struct rb_node *p = &e->u.rb, *parent = rb_parent(&e->u.rb);
 
-		e1 = rb_entry(p, struct ubi_wl_entry, u.rb);
-
-		if (e->pnum == e1->pnum) {
-			ubi_assert(e == e1);
-			return 1;
-		}
+	if (parent == p)
+		return 0;
 
-		if (e->ec < e1->ec)
-			p = p->rb_left;
-		else if (e->ec > e1->ec)
-			p = p->rb_right;
-		else {
-			ubi_assert(e->pnum != e1->pnum);
-			if (e->pnum < e1->pnum)
-				p = p->rb_left;
-			else
-				p = p->rb_right;
-		}
-	}
+	do {
+		p = parent;
+		parent = rb_parent(parent);
+	} while (parent);
 
-	return 0;
+	return p == root->rb_node;
 }
 
 /**
-- 
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ