[PATCH 03/19] talloc: remove unused talloc_steal() and talloc_steal_children()
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Oct 28 02:14:37 PDT 2026
From: Ahmad Fatoum <a.fatoum at barebox.org>
Neither has users and devres doesn't reparent, so let's drop them
instead of teaching them about destructors. Internally, call
mem_set_parent() directly, which talloc_steal() just wrapped.
Assisted-by: Claude:opus-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
include/talloc.h | 2 --
lib/talloc.c | 67 ++----------------------------------------------
2 files changed, 2 insertions(+), 67 deletions(-)
diff --git a/include/talloc.h b/include/talloc.h
index 79a175bd5441..1f2dd346a7c1 100644
--- a/include/talloc.h
+++ b/include/talloc.h
@@ -35,8 +35,6 @@ const char *talloc_strdup_const(const void *parent, const char *str);
void talloc_free_const(const void *ptr);
void *talloc_parent(const void *mem);
-void talloc_steal(const void *parent, void *mem);
-void talloc_steal_children(const void *parent, void *mem);
size_t talloc_total_blocks(const void *mem);
diff --git a/lib/talloc.c b/lib/talloc.c
index a1a7f8f0adc8..2bfbac2e9c29 100644
--- a/lib/talloc.c
+++ b/lib/talloc.c
@@ -34,7 +34,6 @@
#include <asm/sections.h>
#include "talloc.h"
-// TODO difference between set_parent and steal?
// TODO use a bit from TLSF for extra safety to differentiate talloc
// TODO allow leaf nodes (that have no children to be destructors!!)
#define is_root(hdr) (!(hdr)->prev)
@@ -69,7 +68,7 @@ static void *talloc_ctx_init(struct talloc *hdr, const void *parent)
memset(hdr, 0, sizeof(*hdr));
mem = hdr2mem(hdr);
- talloc_steal(parent, mem);
+ mem_set_parent(hdr, mem2hdr(parent));
return mem;
}
@@ -261,7 +260,7 @@ void talloc_free(void *mem)
if (ZERO_OR_NULL_PTR(mem))
return;
- talloc_steal(NULL, mem);
+ mem_set_parent(hdr, NULL);
__tfree(hdr->child);
@@ -335,68 +334,6 @@ void mem_set_parent(struct talloc *hdr, struct talloc *parent_hdr)
}
EXPORT_SYMBOL(mem_set_parent);
-/**
- * talloc_steal() - Reparent talloc'ed memory chunk
- *
- * @parent: pointer to previously talloc'ed memory chunk from which this
- * chunk depends, or NULL.
- * @mem: pointer to previously talloc'ed memory chunk.
- *
- * Change the parent of a talloc'ed memory chunk. This will affect the
- * dependencies of the entire subtree rooted at the given chunk.
- */
-void talloc_steal(const void *parent, void *mem)
-{
- struct talloc *hdr = mem2hdr(mem);
- struct talloc *parent_hdr = mem2hdr(parent);
-
- mem_set_parent(hdr, parent_hdr);
-}
-EXPORT_SYMBOL(talloc_steal);
-
-/**
- * talloc_steal_children() - Remove a talloc'ed memory chunk from the dependency tree
- *
- * @parent: pointer to previously talloc'ed memory chunk from which this
- * chunk's children will depend, or NULL.
- * @mem: pointer to previously talloc'ed memory chunk.
- *
- * Removing a talloc'ed memory chunk from the dependency tree takes care of its
- * children (they will depend on the specified parent).
- */
-void talloc_steal_children(const void *parent, void *mem)
-{
- struct talloc *hdr = mem2hdr(mem);
- struct talloc *parent_hdr = mem2hdr(parent);
-
- if (ZERO_OR_NULL_PTR(hdr))
- return;
-
- talloc_steal(NULL, mem);
-
- if (!hdr->child)
- return;
-
- if (parent_hdr) {
- /* Insert mem children in front of the list of parent children. */
- if (parent_hdr->child) {
- struct talloc *last = hdr->child;
-
- while (last->next)
- last = last->next;
-
- parent_hdr->child->prev = last;
- last->next = parent_hdr->child;
- }
-
- parent_hdr->child = hdr->child;
- }
-
- hdr->child->parent = parent_hdr;
- hdr->child = NULL;
-}
-EXPORT_SYMBOL(talloc_steal_children);
-
size_t talloc_total_blocks(const void *mem)
{
struct talloc *hdr = mem2hdr(mem);
--
2.47.3
More information about the barebox
mailing list