On Thu, 5 Jun 2025 at 17:18, Philippe Mathieu-Daudé <phi...@linaro.org> wrote:
>
> On 5/6/25 14:50, Stefan Hajnoczi wrote:
> > On Thu, Jun 05, 2025 at 01:28:49PM +0200, Philippe Mathieu-Daudé wrote:
> >> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> >> index 85110bce374..b96c6ec603c 100644
> >> --- a/hw/virtio/virtio.c
> >> +++ b/hw/virtio/virtio.c
> >> @@ -153,6 +153,12 @@ struct VirtQueue
> >>       EventNotifier host_notifier;
> >>       bool host_notifier_enabled;
> >>       QLIST_ENTRY(VirtQueue) node;
> >> +
> >> +    /* Only used by virtqueue_pop() */
> >> +    struct {
> >> +        hwaddr addr[VIRTQUEUE_MAX_SIZE];
> >> +        struct iovec iov[VIRTQUEUE_MAX_SIZE];
> >> +    } pop;
> >
> > This is an alternative. Using g_alloca() is another alternative.
>
> Not a lot of these:
>
> $ git grep -w g_alloca
> backends/tpm/tpm_emulator.c:136:        buf = g_alloca(n);
> tests/unit/test-char.c:1012:        be = g_alloca(sizeof(CharBackend));

There are also some alloca() uses, mostly ancient code in
linux-user that should really not be using it.

Like variable-length-arrays (which we managed to eradicate)
use of alloca is tricky because if the allocation size is
large then it just runs us out of stack in an uncontrolled
way. I'm not sure it's worth trying to remove existing alloca
use, but it would probably be preferable not to add more.

(GCC has a -Walloca option, so if we ever did get rid of all
of them we could avoid new ones creeping back in.)

thanks
-- PMM

Reply via email to