All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Revert "part: Allocate only one legacy_mbr buffer"
Date: Wed, 4 Sep 2019 13:23:02 +0000	[thread overview]
Message-ID: <CY4PR1201MB0120273A9504356D34C14D7FA1B80@CY4PR1201MB0120.namprd12.prod.outlook.com> (raw)
In-Reply-To: <51d70f01-0fb8-ef8a-3ca8-3621fcceb23e@ti.com>

Hi Faiz,

> -----Original Message-----
> From: Faiz Abbas <faiz_abbas@ti.com>
> Sent: Wednesday, September 4, 2019 4:09 PM
> To: Alexey Brodkin <abrodkin@synopsys.com>
> Cc: paulemge at forallsecure.com; trini at konsulko.com; u-boot at lists.denx.de
> Subject: Re: [PATCH] Revert "part: Allocate only one legacy_mbr buffer"
> 
> Hi Alexey,
> 
> On 04/09/19 6:27 PM, Alexey Brodkin wrote:
> > Hi Faiz,
> >
> > [snip]
> >
> >>>>> I guess what you really want to do is to allocate buffer for "mbr"
> >>>>> dynamically of size which is max(sizeof(legacy_mbr), dev_desc->blksz).
> >>>>>
> >>>>
> >>>> With the assumption that blksz is always greater than
> >>>> sizeof(legacy_mbr), this should work:
> >>>>
> >>>> ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, DIV_ROUND_UP(dev_desc->blksz,
> >>>> sizeof(legacy_mbr)));
> >>>
> >>> No this won't work. See ALLOC_CACHE_ALIGN_BUFFER does static allocation
> >>> in compile-time while blksz is set in runtime.
> >>>
> >>> That's why I mentioned switch to runtime allocation.
> >>>
> >>
> >> Hmm. So the problem isn't as much about allocating too much in the
> >> buffer but about using dynamically determined size for static array
> >> declaration.
> >
> > In fact it was a problem of huge static allocation I discovered just by
> > chance building U-Boot for a very memory-limited device, see [1].
> >
> >> This is being used all over this disk/part_dos.c file.
> >> Shouldn't we fix all of that? Not sure how it has been working all along.
> >
> > That part I don't quite understand. What's being used, where and how?
> > And what's the problem with dynamic allocation of the buffer for MBR?
> >
> 
> Isn't the following line (being used in different functions in
> disk/part_dos.c) also problematic because we don't know the value of
> blksz at compile time?
> 
> ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);

Ok I see now. Looks like I missed that Variable-Length Array (VLA) feature
added to C99 so up-to-date GCC apparently supports it.

But I would strongly recommend to get rid of VLA usage by all means,
see [1] & [2].

[1] https://lwn.net/Articles/749064/
[2] https://lwn.net/Articles/749089/

-Alexey

  reply	other threads:[~2019-09-04 13:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-04  9:22 [U-Boot] [PATCH] Revert "part: Allocate only one legacy_mbr buffer" Faiz Abbas
2019-09-04 10:12 ` Alexey Brodkin
2019-09-04 11:43   ` Faiz Abbas
2019-09-04 11:46     ` Alexey Brodkin
2019-09-04 12:49       ` Faiz Abbas
2019-09-04 12:57         ` Alexey Brodkin
2019-09-04 13:09           ` Faiz Abbas
2019-09-04 13:23             ` Alexey Brodkin [this message]
2019-09-04 13:46               ` Alexey Brodkin
2019-09-04 13:49                 ` Tom Rini
2019-09-04 14:07                   ` Faiz Abbas
2019-09-04 14:08               ` Faiz Abbas

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=CY4PR1201MB0120273A9504356D34C14D7FA1B80@CY4PR1201MB0120.namprd12.prod.outlook.com \
    --to=alexey.brodkin@synopsys.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.