From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@barebox.org>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH RFC 1/3] lib: add talloc for overlaying a tree onto allocations
Date: Tue, 28 Oct 2025 10:42:15 +0100 [thread overview]
Message-ID: <aQCP95IqfhGo1zJg@pengutronix.de> (raw)
In-Reply-To: <20251027075438.2480311-1-a.fatoum@barebox.org>
On Mon, Oct 27, 2025 at 08:54:32AM +0100, Ahmad Fatoum wrote:
> +#ifndef __TALLOC_H__
> +#define __TALLOC_H__
> +
> +#include <linux/types.h>
> +
> +struct talloc {
> + struct talloc *child;
> + struct talloc *next;
> + union {
> + struct talloc *prev;
> + struct talloc *parent; /* Valid only when is_first(mem) */
> + };
> +};
Currently tlsf allocations are 8 byte aligned. On 32bit architectures
struct talloc will be 12 bytes, so talloc allocations will only have 4
byte alignment.
> +static void *talloc_ctx_init(struct talloc *hdr, const void *parent)
> +{
> + void *mem;
> +
> + if (!hdr)
> + return NULL;
> +
> + memset(hdr, 0, sizeof(*hdr));
> +
> + mem = hdr2mem(hdr);
> + talloc_steal(parent, mem);
> + return mem;
> +}
> +
> +/**
> + * talloc_usable_size() - Report the size of the talloation
s/talloation/tallocation/
> + *
> + * @mem: pointer to previously talloc'ed memory chunk.
> + *
> + * Return: size of tallocation
> + */
> +size_t talloc_usable_size(void *mem)
> +{
> + return malloc_usable_size(mem) - sizeof(struct talloc);
> +}
> +EXPORT_SYMBOL(talloc_usable_size);
This function is unused. Do we need it?
> +/**
> + * talloc_free() - Deallocate a talloc'ed memory chunk and all the chunks depending on it.
> + *
> + * @mem: pointer to previously talloc'ed memory chunk.
> + */
> +void talloc_free(void *mem)
> +{
> + struct talloc *hdr = mem2hdr(mem);
> +
> + if (ZERO_OR_NULL_PTR(hdr))
> + return;
For correctness I believe you have to check mem here, not hdr.
(Although the above works as long as sizeof(struct talloc) <= ZERO_SIZE_PTR)
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2025-10-28 9:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 7:54 Ahmad Fatoum
2025-10-27 7:54 ` [PATCH RFC 2/3] test: self: add talloc selftest Ahmad Fatoum
2025-10-27 7:54 ` [PATCH RFC 3/3] hush: fix memory leaks Ahmad Fatoum
2025-10-28 9:42 ` Sascha Hauer [this message]
2025-10-28 10:26 ` [PATCH RFC 1/3] lib: add talloc for overlaying a tree onto allocations Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aQCP95IqfhGo1zJg@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox