All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomas Hlavacek <tmshlvck@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v8] [RFC] early_malloc for DM added.
Date: Tue, 25 Sep 2012 10:43:58 +0200	[thread overview]
Message-ID: <CAEB7QLCaFBAWQNVaRYQoSkcgzfLwj765fAh2QG4tMnRihDy_Mw@mail.gmail.com> (raw)
In-Reply-To: <CALButCK8f7A5t5ARbokEpRBWtn=EdN0n111u6MXa7M+k4MD6zg@mail.gmail.com>

Hello Graeme!

On Tue, Sep 25, 2012 at 2:37 AM, Graeme Russ <graeme.russ@gmail.com> wrote:
> Hi Marek,

[...]

> The last two are NOPs for early heap as we have no way to track free'd blocks
>
> Keep in mind that 'real' realloc() has access to information providing
> the size of the source block of allocated memory, so it can do a
> memcpy using (at least a good guess of) the size of the source block.
> In the early heap case, we do not have that data, so we would need to
> memcpy the entire size of the destination block - this will likely
> bring in garbage (no problem as we there is nothing in the spec to
> forbid that) and _might_ have some interesting boundary conditions
> (what happens if we memcpy past the end of an early heap block into
> ga-ga land?)

I was thinking about such simple implementation:

static inline void *dmrealloc(void *oldaddr, size_t bytes)
{
#ifdef CONFIG_SYS_EARLY_MALLOC
        char *addr;
        if (early_malloc_active()) {
                addr = dmalloc(bytes);
                memcpy(addr, oldaddr, bytes);
                return addr;
        }
#endif /* CONFIG_SYS_EARLY_MALLOC */
        return dmrealloc(oldmem, bytes);
}

But then the fun comes: I can not distinguish the case when you have
100 B char *x allocated and you called dmrealloc(x, 99). And I can hit
some boundaries as

But yes, we can have such a stupid implementation. Or I can use
early_malloc frame header which would contain magic (to detect wrong
dmrealloc calls on arbitrary pointer) and size, so I would be able to
do free and realloc. Then I would need new free-space enumeration
mechanism to reuse free space (let's say that I can create a linked
list of free headers), so the frame header is going to be 12 B total.
Or we can have no implementation of dmrealloc at all.

Tomas

  reply	other threads:[~2012-09-25  8:43 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-27 12:12 [U-Boot] [PATCH 1/1] [RFC] DM: early_malloc for DM added Tomas Hlavacek
2012-08-27 12:18 ` Marek Vasut
2012-08-27 12:37   ` Tomas Hlavacek
2012-08-27 12:42 ` [U-Boot] [PATCHv2 " Tomas Hlavacek
2012-08-27 23:02   ` Graeme Russ
2012-08-28  0:11     ` Graeme Russ
2012-08-28  0:18     ` Graeme Russ
2012-09-18  7:13 ` [U-Boot] [PATCHv4] " Tomas Hlavacek
2012-09-18 10:57   ` Marek Vasut
2012-09-18 23:29     ` Graeme Russ
2012-09-18 23:33       ` Marek Vasut
2012-09-18 23:44         ` Graeme Russ
2012-09-18 23:53           ` Marek Vasut
2012-09-19 18:29       ` Tom Rini
2012-09-22  0:37       ` Tomas Hlavacek
2012-09-18 23:25   ` Graeme Russ
2012-09-22  0:25 ` [U-Boot] [PATCH v5] [RFC] " Tomas Hlavacek
2012-09-22  0:28   ` Marek Vasut
2012-09-22  7:52     ` Tomas Hlavacek
2012-09-22 13:19       ` Marek Vasut
2012-09-22 22:09 ` [U-Boot] [PATCH v6] " Tomas Hlavacek
2012-09-23 13:06   ` Graeme Russ
2012-09-23 15:30     ` Tomas Hlavacek
2012-09-23 15:38 ` [U-Boot] [PATCH v7] " Tomas Hlavacek
2012-09-23 16:15 ` [U-Boot] [PATCH v8] " Tomas Hlavacek
2012-09-23 16:32   ` Wolfgang Denk
2012-09-23 16:47     ` Tomas Hlavacek
2012-09-24 21:48       ` Tom Rini
2012-09-23 23:11   ` Marek Vasut
2012-09-24 14:16     ` Tomas Hlavacek
2012-09-24 14:19       ` Marek Vasut
2012-09-25  0:37         ` Graeme Russ
2012-09-25  8:43           ` Tomas Hlavacek [this message]
2012-09-25  9:09             ` Graeme Russ
2012-09-25 23:04               ` Graeme Russ
2012-09-26 10:16                 ` Tomas Hlavacek
2012-09-26 23:03                   ` Graeme Russ
2012-09-24  0:00   ` Graeme Russ
2012-09-24  0:35     ` Tomas Hlavacek
2012-09-24  0:46       ` Graeme Russ
2012-10-24 23:49 ` [U-Boot] [PATCH v9] [RFC] Add dmmalloc module for DM Tomas Hlavacek
2012-10-25  1:40   ` Graeme Russ
2012-10-25 19:16     ` Tomas Hlavacek
2012-10-25 23:04       ` Graeme Russ
2012-10-28 23:20 ` [U-Boot] [PATCH v10] " Tomas Hlavacek
2013-11-05 15:26   ` Mateusz Zalega
2013-11-05 17:17     ` Tom Rini
2013-11-05 17:26       ` Mateusz Zalega

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=CAEB7QLCaFBAWQNVaRYQoSkcgzfLwj765fAh2QG4tMnRihDy_Mw@mail.gmail.com \
    --to=tmshlvck@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.