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: <20240328064539.95795-1-richard120310@gmail.com>
Date: Thu, 28 Mar 2024 14:45:39 +0800
From: I Hsin Cheng <richard120310@...il.com>
To: akpm@...ux-foundation.org
Cc: linux-kernel@...r.kernel.org,
	I Hsin Cheng <richard120310@...il.com>
Subject: [PATCH] rbtree: Introduce rb_remove()

Implement the function "rb_remove()", which can perform the removal of a
certain key from the tree. Once the node with the searched key is found,
we call "rb_erase()" to perform the removal of the node, otherwise the
key doesn't exists in the tree then we return NULL.

Signed-off-by: I Hsin Cheng <richard120310@...il.com>
---
 include/linux/rbtree.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
index f7edca369..1958be66f 100644
--- a/include/linux/rbtree.h
+++ b/include/linux/rbtree.h
@@ -302,6 +302,34 @@ rb_find_first(const void *key, const struct rb_root *tree,
 	return match;
 }
 
+/**
+ * rb_remove() - remove @key in tree @tree
+ * @key: key to remove
+ * @tree: tree to modify
+ * @less: operator defining the (partial) node order
+ */
+static __always_inline struct rb_node *
+rb_remove(const void *key, const struct rb_root *tree,
+	  int (*cmp)(const void *key, const struct rb_node *))
+{
+	struct rb_node *node = tree->rb_node;
+
+	while (node) {
+		int c = cmp(key, node);
+
+		if (c < 0)
+			node = node->rb_left;
+		else if (c > 0)
+			node = node->rb_right;
+		else {
+			rb_erase(node, tree->rb_node);
+			return node;
+		}
+	}
+
+	return NULL;
+}
+
 /**
  * rb_next_match() - find the next @key in @tree
  * @key: key to match
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ