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-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 25 May 2012 13:57:40 -0700
From:	Kent Overstreet <koverstreet@...gle.com>
To:	linux-kernel@...r.kernel.org, linux-bcache@...r.kernel.org
Cc:	Kent Overstreet <koverstreet@...gle.com>, tj@...nel.org,
	axboe@...nel.dk, paul.gortmaker@...driver.com
Subject: [PATCH 2/3] timerqueue: convert to generic rb tree code

Change-Id: Ib31c42c037203b7eb78515673475130db9fa6b0b

Signed-off-by: Kent Overstreet <koverstreet@...gle.com>
---
 lib/timerqueue.c |   23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/lib/timerqueue.c b/lib/timerqueue.c
index a382e4a..3014abe 100644
--- a/lib/timerqueue.c
+++ b/lib/timerqueue.c
@@ -27,6 +27,14 @@
 #include <linux/rbtree.h>
 #include <linux/export.h>
 
+static int timerqueue_cmp(struct rb_node *l, struct rb_node *r)
+{
+	return clamp_t(int64_t,
+		       rb_entry(l, struct timerqueue_node, node)->expires.tv64 -
+		       rb_entry(r, struct timerqueue_node, node)->expires.tv64,
+		       -1, 1);
+}
+
 /**
  * timerqueue_add - Adds timer to timerqueue.
  *
@@ -38,23 +46,10 @@
  */
 void timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node)
 {
-	struct rb_node **p = &head->head.rb_node;
-	struct rb_node *parent = NULL;
-	struct timerqueue_node  *ptr;
-
 	/* Make sure we don't add nodes that are already added */
 	WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node));
 
-	while (*p) {
-		parent = *p;
-		ptr = rb_entry(parent, struct timerqueue_node, node);
-		if (node->expires.tv64 < ptr->expires.tv64)
-			p = &(*p)->rb_left;
-		else
-			p = &(*p)->rb_right;
-	}
-	rb_link_node(&node->node, parent, p);
-	rb_insert_color(&node->node, &head->head);
+	rb_insert_allow_dup(&head->head, &node->node, timerqueue_cmp);
 
 	if (!head->next || node->expires.tv64 < head->next->expires.tv64)
 		head->next = node;
-- 
1.7.9.3.327.g2980b

--
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