From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Jiri Pirko" <jiri@resnulli.us>,
"Daniel P. Berrangé" <berrange@redhat.com>,
qemu-block@nongnu.org, "Jason Wang" <jasowang@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Greg Kurz" <groug@kaod.org>,
qemu-ppc@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>
Subject: [PATCH 15/23] net: Avoid dynamic stack allocation
Date: Wed, 5 May 2021 23:10:39 +0200 [thread overview]
Message-ID: <20210505211047.1496765-16-philmd@redhat.com> (raw)
In-Reply-To: <20210505211047.1496765-1-philmd@redhat.com>
Use autofree heap allocation instead of variable-length
array on the stack.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
hw/net/fsl_etsec/rings.c | 9 ++++-----
hw/net/rocker/rocker_of_dpa.c | 2 +-
net/dump.c | 2 +-
net/tap.c | 2 +-
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/hw/net/fsl_etsec/rings.c b/hw/net/fsl_etsec/rings.c
index 8f084464155..1abdcb5a29c 100644
--- a/hw/net/fsl_etsec/rings.c
+++ b/hw/net/fsl_etsec/rings.c
@@ -381,8 +381,6 @@ static void fill_rx_bd(eTSEC *etsec,
uint16_t to_write;
hwaddr bufptr = bd->bufptr +
((hwaddr)(etsec->regs[TBDBPH].value & 0xF) << 32);
- uint8_t padd[etsec->rx_padding];
- uint8_t rem;
RING_DEBUG("eTSEC fill Rx buffer @ 0x%016" HWADDR_PRIx
" size:%zu(padding + crc:%u) + fcb:%u\n",
@@ -423,11 +421,12 @@ static void fill_rx_bd(eTSEC *etsec,
/* The remaining bytes are only for padding which is not actually
* allocated in the data buffer.
*/
-
- rem = MIN(etsec->regs[MRBLR].value - bd->length, etsec->rx_padding);
+ uint8_t rem = MIN(etsec->regs[MRBLR].value - bd->length,
+ etsec->rx_padding);
if (rem > 0) {
- memset(padd, 0x0, sizeof(padd));
+ g_autofree uint8_t *padd = g_malloc0(etsec->rx_padding);
+
etsec->rx_padding -= rem;
*size -= rem;
bd->length += rem;
diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c
index b3b8c5bb6d4..3e400ceaef7 100644
--- a/hw/net/rocker/rocker_of_dpa.c
+++ b/hw/net/rocker/rocker_of_dpa.c
@@ -1043,7 +1043,7 @@ static void of_dpa_flow_ig_tbl(OfDpaFlowContext *fc, uint32_t tbl_id)
static ssize_t of_dpa_ig(World *world, uint32_t pport,
const struct iovec *iov, int iovcnt)
{
- struct iovec iov_copy[iovcnt + 2];
+ g_autofree struct iovec *iov_copy = g_new(struct iovec, iovcnt + 2);
OfDpaFlowContext fc = {
.of_dpa = world_private(world),
.in_pport = pport,
diff --git a/net/dump.c b/net/dump.c
index 4d538d82a69..b830302e27d 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -68,7 +68,7 @@ static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int cnt)
int64_t ts;
int caplen;
size_t size = iov_size(iov, cnt);
- struct iovec dumpiov[cnt + 1];
+ g_autofree struct iovec *dumpiov = g_new(struct iovec, cnt + 1);
/* Early return in case of previous error. */
if (s->fd < 0) {
diff --git a/net/tap.c b/net/tap.c
index bae895e2874..2b9ed8a2cd8 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -120,7 +120,7 @@ static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov,
{
TAPState *s = DO_UPCAST(TAPState, nc, nc);
const struct iovec *iovp = iov;
- struct iovec iov_copy[iovcnt + 1];
+ g_autofree struct iovec *iov_copy = g_new(struct iovec, iovcnt + 1);
struct virtio_net_hdr_mrg_rxbuf hdr = { };
if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
--
2.26.3
next prev parent reply other threads:[~2021-05-05 21:42 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-05 21:10 [PATCH 00/23] misc: Remove variable-length arrays on the stack Philippe Mathieu-Daudé
2021-05-05 21:10 ` [PATCH 01/23] block/vpc: Avoid dynamic stack allocation Philippe Mathieu-Daudé
2021-05-05 21:10 ` [PATCH 02/23] chardev/baum: Replace magic values by X_MAX / Y_MAX definitions Philippe Mathieu-Daudé
2021-05-05 21:12 ` Samuel Thibault
2021-05-05 21:24 ` Marc-André Lureau
2021-05-05 21:10 ` [PATCH 03/23] chardev/baum: Use definitions to avoid dynamic stack allocation Philippe Mathieu-Daudé
2021-05-05 21:14 ` Samuel Thibault
2021-05-05 21:27 ` Marc-André Lureau
2021-05-05 21:39 ` Samuel Thibault
2021-05-05 21:10 ` [PATCH 04/23] chardev/baum: Avoid " Philippe Mathieu-Daudé
2021-05-05 21:15 ` Samuel Thibault
2021-05-05 21:29 ` Marc-André Lureau
2021-05-05 21:10 ` [PATCH 05/23] io/channel-websock: Replace strlen(const_str) by sizeof(const_str) - 1 Philippe Mathieu-Daudé
2021-05-06 8:36 ` Daniel P. Berrangé
2021-05-05 21:10 ` [PATCH 06/23] hw/block/dataplane/virtio-blk: Avoid dynamic stack allocation Philippe Mathieu-Daudé
2021-05-06 8:53 ` Stefan Hajnoczi
2021-05-06 9:01 ` Philippe Mathieu-Daudé
2021-05-06 14:47 ` Stefan Hajnoczi
2021-05-06 15:19 ` Philippe Mathieu-Daudé
2021-05-10 9:09 ` Stefan Hajnoczi
2021-05-05 21:10 ` [PATCH 07/23] hw/block/nvme: Use definition to avoid " Philippe Mathieu-Daudé
2021-05-05 21:22 ` Keith Busch
2021-05-05 22:07 ` Philippe Mathieu-Daudé
2021-05-05 23:09 ` Eric Blake
2021-05-06 0:14 ` Warner Losh
2021-05-06 2:15 ` Keith Busch
2021-05-06 6:42 ` Philippe Mathieu-Daudé
2021-05-07 16:22 ` Richard Henderson
2021-05-06 6:27 ` Klaus Jensen
2021-05-07 15:59 ` Richard Henderson
2021-05-05 21:10 ` [PATCH 08/23] hw/block/nvme: Avoid " Philippe Mathieu-Daudé
2021-05-06 6:43 ` Klaus Jensen
2021-05-05 21:10 ` [PATCH 09/23] hw/net/e1000e_core: Use definition to avoid " Philippe Mathieu-Daudé
2021-05-06 3:35 ` Jason Wang
2021-05-07 16:29 ` Richard Henderson
2021-05-05 21:10 ` [PATCH 10/23] hw/ppc/pnv: Avoid " Philippe Mathieu-Daudé
2021-05-06 2:12 ` David Gibson
2021-05-05 21:10 ` [PATCH 11/23] hw/intc/xics: " Philippe Mathieu-Daudé
2021-05-06 2:13 ` David Gibson
2021-05-06 8:22 ` Greg Kurz
2021-05-06 13:52 ` Philippe Mathieu-Daudé
2021-05-05 21:10 ` [PATCH 12/23] hw/i386/multiboot: " Philippe Mathieu-Daudé
2021-05-07 16:27 ` Richard Henderson
2021-05-05 21:10 ` [PATCH 13/23] hw/usb/hcd-xhci: " Philippe Mathieu-Daudé
2021-05-07 16:34 ` Richard Henderson
2021-05-05 21:10 ` [PATCH 14/23] hw/usb/hcd-ohci: Use definition to avoid " Philippe Mathieu-Daudé
2021-05-07 16:39 ` Richard Henderson
2021-05-05 21:10 ` Philippe Mathieu-Daudé [this message]
2021-05-06 2:15 ` [PATCH 15/23] net: Avoid " David Gibson
2021-05-06 7:09 ` Jason Wang
2021-05-05 21:10 ` [PATCH 16/23] ui/curses: " Philippe Mathieu-Daudé
2021-05-07 16:42 ` Richard Henderson
2021-05-05 21:10 ` [PATCH 17/23] ui/spice-display: " Philippe Mathieu-Daudé
2021-05-05 21:10 ` [PATCH 18/23] ui/vnc-enc-hextile: Use definitions to avoid " Philippe Mathieu-Daudé
2021-05-07 16:46 ` Richard Henderson
2021-05-05 21:10 ` [PATCH 19/23] ui/vnc-enc-tight: Avoid " Philippe Mathieu-Daudé
2021-05-05 21:10 ` [PATCH 20/23] util/iov: " Philippe Mathieu-Daudé
2021-05-05 21:10 ` [PATCH 21/23] target/ppc/kvm: " Philippe Mathieu-Daudé
2021-05-06 2:16 ` David Gibson
2021-05-05 21:10 ` [PATCH 22/23] tests/unit/test-vmstate: " Philippe Mathieu-Daudé
2021-05-07 16:52 ` Richard Henderson
2021-05-05 21:10 ` [PATCH 23/23] configure: Prohibit variable-length allocations by using -Wvla CPPFLAG Philippe Mathieu-Daudé
2021-05-07 16:56 ` Richard Henderson
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=20210505211047.1496765-16-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=berrange@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=groug@kaod.org \
--cc=jasowang@redhat.com \
--cc=jiri@resnulli.us \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.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;
as well as URLs for NNTP newsgroup(s).