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]
Message-ID: <20130729150147.GA4381@variantweb.net>
Date:	Mon, 29 Jul 2013 10:01:47 -0500
From:	Seth Jennings <sjenning@...ux.vnet.ibm.com>
To:	Cody P Schafer <cody@...ux.vnet.ibm.com>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	LKML <linux-kernel@...r.kernel.org>,
	Linux MM <linux-mm@...ck.org>,
	David Woodhouse <David.Woodhouse@...el.com>,
	Rik van Riel <riel@...hat.com>,
	Michel Lespinasse <walken@...gle.com>
Subject: Re: [PATCH 1/5] rbtree: add postorder iteration functions

On Fri, Jul 26, 2013 at 02:13:39PM -0700, Cody P Schafer wrote:
> Add postorder iteration functions for rbtree. These are useful for
> safely freeing an entire rbtree without modifying the tree at all.
> 
> Signed-off-by: Cody P Schafer <cody@...ux.vnet.ibm.com>
> ---
>  include/linux/rbtree.h |  4 ++++
>  lib/rbtree.c           | 40 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 44 insertions(+)
> 
> diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
> index 0022c1b..2879e96 100644
> --- a/include/linux/rbtree.h
> +++ b/include/linux/rbtree.h
> @@ -68,6 +68,10 @@ extern struct rb_node *rb_prev(const struct rb_node *);
>  extern struct rb_node *rb_first(const struct rb_root *);
>  extern struct rb_node *rb_last(const struct rb_root *);
> 
> +/* Postorder iteration - always visit the parent after it's children */

s/it's/its/

> +extern struct rb_node *rb_first_postorder(const struct rb_root *);
> +extern struct rb_node *rb_next_postorder(const struct rb_node *);
> +
>  /* Fast replacement of a single node without remove/rebalance/add/rebalance */
>  extern void rb_replace_node(struct rb_node *victim, struct rb_node *new, 
>  			    struct rb_root *root);
> diff --git a/lib/rbtree.c b/lib/rbtree.c
> index c0e31fe..65f4eff 100644
> --- a/lib/rbtree.c
> +++ b/lib/rbtree.c
> @@ -518,3 +518,43 @@ void rb_replace_node(struct rb_node *victim, struct rb_node *new,
>  	*new = *victim;
>  }
>  EXPORT_SYMBOL(rb_replace_node);
> +
> +static struct rb_node *rb_left_deepest_node(const struct rb_node *node)
> +{
> +	for (;;) {
> +		if (node->rb_left)
> +			node = node->rb_left;

Assigning to an argument passed as const seems weird to me.  I would
think it shouldn't compile but it does.  I guess my understanding of
const is incomplete.

> +		else if (node->rb_right)
> +			node = node->rb_right;
> +		else
> +			return (struct rb_node *)node;
> +	}
> +}
> +
> +struct rb_node *rb_next_postorder(const struct rb_node *node)
> +{
> +	const struct rb_node *parent;
> +	if (!node)
> +		return NULL;
> +	parent = rb_parent(node);

Again here.

Seth

> +
> +	/* If we're sitting on node, we've already seen our children */
> +	if (parent && node == parent->rb_left && parent->rb_right) {
> +		/* If we are the parent's left node, go to the parent's right
> +		 * node then all the way down to the left */
> +		return rb_left_deepest_node(parent->rb_right);
> +	} else
> +		/* Otherwise we are the parent's right node, and the parent
> +		 * should be next */
> +		return (struct rb_node *)parent;
> +}
> +EXPORT_SYMBOL(rb_next_postorder);
> +
> +struct rb_node *rb_first_postorder(const struct rb_root *root)
> +{
> +	if (!root->rb_node)
> +		return NULL;
> +
> +	return rb_left_deepest_node(root->rb_node);
> +}
> +EXPORT_SYMBOL(rb_first_postorder);
> -- 
> 1.8.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