diff options
| author | Jean-Sébastien Pédron <dumbbell@FreeBSD.org> | 2026-04-21 00:38:56 +0000 |
|---|---|---|
| committer | Jean-Sébastien Pédron <dumbbell@FreeBSD.org> | 2026-04-22 18:09:56 +0000 |
| commit | cff716c2854c167ef7ff3a4785f5faed9b0a4f98 (patch) | |
| tree | 9607367523371b6234508231a4b9cb2aca4886f6 | |
| parent | 002c08158f9e7eb61c467fe29ff8e24361fb8470 (diff) | |
linuxkpi: Add `rb_add()`
It is the same as `rb_add_cached()` but it works on `struct rb_root`, not
a `struc rb_root_cached`. It also does not return anything.
The DRM generic code started to use this in Linux 6.12.x.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56577
| -rw-r--r-- | sys/compat/linuxkpi/common/include/linux/rbtree.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/rbtree.h b/sys/compat/linuxkpi/common/include/linux/rbtree.h index e6033cfd760d..834e5645e991 100644 --- a/sys/compat/linuxkpi/common/include/linux/rbtree.h +++ b/sys/compat/linuxkpi/common/include/linux/rbtree.h @@ -199,6 +199,26 @@ rb_add_cached(struct rb_node *node, struct rb_root_cached *tree, return (leftmost ? node : NULL); } +static inline void +rb_add(struct rb_node *node, struct rb_root *tree, + bool (*less)(struct rb_node *, const struct rb_node *)) +{ + struct rb_node **link = &tree->rb_node; + struct rb_node *parent = NULL; + + while (*link != NULL) { + parent = *link; + if (less(node, parent)) { + link = &RB_LEFT(parent, __entry); + } else { + link = &RB_RIGHT(parent, __entry); + } + } + + rb_link_node(node, parent, link); + rb_insert_color(node, tree); +} + #undef RB_ROOT #define RB_ROOT (struct rb_root) { NULL } #define RB_ROOT_CACHED (struct rb_root_cached) { RB_ROOT, NULL } |
