Sun Feb 27 14:18:34 2022 UTC ()
linux: New rb_move(&to, &from) to replace `to = from'.

NetBSD rbtree(3) is not relocatable, so this extra step is needed.
Unfortunately, there's no easy way to automate detection of where we
need to apply this in ported code...


(riastradh)
diff -r1.17 -r1.18 src/sys/external/bsd/drm2/include/linux/rbtree.h

cvs diff -r1.17 -r1.18 src/sys/external/bsd/drm2/include/linux/rbtree.h (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/include/linux/rbtree.h 2022/02/27 14:18:25 1.17
+++ src/sys/external/bsd/drm2/include/linux/rbtree.h 2022/02/27 14:18:34 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rbtree.h,v 1.17 2022/02/27 14:18:25 riastradh Exp $ */ 1/* $NetBSD: rbtree.h,v 1.18 2022/02/27 14:18:34 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -193,23 +193,44 @@ rb_next2_postorder(const struct rb_root  @@ -193,23 +193,44 @@ rb_next2_postorder(const struct rb_root
193 * sibling -- or return the parent if there is none. 193 * sibling -- or return the parent if there is none.
194 */ 194 */
195 if ((node = parent->rb_right) == NULL) 195 if ((node = parent->rb_right) == NULL)
196 return parent; 196 return parent;
197 for (;; node = child) { 197 for (;; node = child) {
198 if ((child = node->rb_left) != NULL) 198 if ((child = node->rb_left) != NULL)
199 continue; 199 continue;
200 if ((child = node->rb_right) != NULL) 200 if ((child = node->rb_right) != NULL)
201 continue; 201 continue;
202 return node; 202 return node;
203 } 203 }
204} 204}
205 205
 206/*
 207 * Extension to Linux API, which allows copying a struct rb_root object
 208 * with `=' or `memcpy' and no additional relocation.
 209 */
 210static inline void
 211rb_move(struct rb_root *to, struct rb_root *from)
 212{
 213 struct rb_node *root;
 214
 215 *to = *from;
 216 memset(from, 0, sizeof(*from)); /* paranoia */
 217 if ((root = to->rbr_tree.rbt_root) == NULL)
 218 return;
 219
 220 /*
 221 * The root node's `parent' is a strict-aliasing-unsafe hack
 222 * pointing at the root of the tree.
 223 */
 224 RB_SET_FATHER(root, (struct rb_node *)(void *)&to->rbr_tree.rbt_root);
 225}
 226
206#define rbtree_postorder_for_each_entry_safe(ENTRY, TMP, ROOT, FIELD) \ 227#define rbtree_postorder_for_each_entry_safe(ENTRY, TMP, ROOT, FIELD) \
207 for ((ENTRY) = rb_entry_safe(rb_first_postorder(ROOT), \ 228 for ((ENTRY) = rb_entry_safe(rb_first_postorder(ROOT), \
208 __typeof__(*(ENTRY)), FIELD); \ 229 __typeof__(*(ENTRY)), FIELD); \
209 ((ENTRY) != NULL && \ 230 ((ENTRY) != NULL && \
210 ((TMP) = rb_entry_safe(rb_next2_postorder((ROOT), \ 231 ((TMP) = rb_entry_safe(rb_next2_postorder((ROOT), \
211 &(ENTRY)->FIELD), __typeof__(*(ENTRY)), FIELD), \ 232 &(ENTRY)->FIELD), __typeof__(*(ENTRY)), FIELD), \
212 1)); \ 233 1)); \
213 (ENTRY) = (TMP)) 234 (ENTRY) = (TMP))
214 235
215#endif /* _LINUX_RBTREE_H_ */ 236#endif /* _LINUX_RBTREE_H_ */