From nobody Thu Dec 18 13:19:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620249130; cv=none; d=zohomail.com; s=zohoarc; b=XTIXBzqt8RSdt3iQ7V86t/zQk1jlRimHlk12FK1M6GNY5zxmfFrLxxzpkn+LVJy3d569gdI5WNTbrHQBC1/sH71XuSKzNQqrlqu4z7flzhGsinI+nyUZmWEPN58d78Mc+ypcfrBjqDK+ACyZfSQa7MswDQMr8+/IFL5vSloskvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620249130; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=kucBjQtcgLplpmt/EdeRDcsm9+gP7+suZYQbhaTK3U8=; b=jMTp67yLj9wjtpexE1QA/WaHGH9olTro5ax8kPa/ssk7Sg3HyrIylE5KaetiDo9XBMswWSTOLqdP0ctTRJV0aZO43WOx8M4UOccnjhE98dfIytLVMIKOmyYfGBxoGB0fS5iSMjh2mJESGMVRoxd8irNrn39dJw5Fv9L4+bHtlAI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620249130508809.7114933232485; Wed, 5 May 2021 14:12:10 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-91-iWheM1kEPUO3u-JhlsEgzw-1; Wed, 05 May 2021 17:12:07 -0400 Received: by mail-wr1-f71.google.com with SMTP id s7-20020adfc5470000b0290106eef17cbdso1206691wrf.11 for ; Wed, 05 May 2021 14:12:06 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (astrasbourg-653-1-188-220.w90-13.abo.wanadoo.fr. [90.13.127.220]) by smtp.gmail.com with ESMTPSA id t17sm587584wmq.12.2021.05.05.14.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 14:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620249129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kucBjQtcgLplpmt/EdeRDcsm9+gP7+suZYQbhaTK3U8=; b=ekQE0RpJlA5PyDOfJV1TUmNycMqCWxlMLAdAb6VjyM2jr7h1Jl98S/S8RzpyfK2jhYP3/U gWH44W2+7kvl3djb1Vtq7Jw7/JPme9KYuz/SUoPCiPpiJsghNrLXhNbEIRTo8ktEjnougO lqEQDaXsocmsReuF1cR76Zq58tWUKG8= X-MC-Unique: iWheM1kEPUO3u-JhlsEgzw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kucBjQtcgLplpmt/EdeRDcsm9+gP7+suZYQbhaTK3U8=; b=s42T2fgNblvWjZ2W/yGCQYd1C5P6aqqD8WR9ZueCUuJirarJ+MCOtujAcCCJvGrvcX Uei2vrE4RsE0ihcTkO5i+Oc92hvTkPmE3SdCYAXzZsLlu9ZCXz3LW0c7QRS/1NFQH0zn 1qFAsrB7YStu2Zlyem/e3sd0paAizSdW07juVLiTO8oYcVggJlxkJjsKn40AkuLLC7tv Ot9V1J7SZ1n4suMF1kjWFPs5VYUUVX2lxB/n50FfyIwDV7eectzCSwteTOS3joJA7it/ Yecaja7+KbdMDEKl4q3WjZYugH2mGYpZZZ8YGsBhYeW8dG9ffvdO0ViS+QgcTHM0m3hv Somg== X-Gm-Message-State: AOAM533LN9ML/e6sI2wBwj73uUUHeZmB93XVQcOR+e+yLyh0iljapFO3 hp8snKIBtgmj7GHEgm8SpXoBe3uBp/cvUhPzQ/iKaMmFy5d7Jx8GktfnWwpX25cAxEnd4u3lsy5 94585mZxFtp7t1Q== X-Received: by 2002:adf:d223:: with SMTP id k3mr1026867wrh.99.1620249125973; Wed, 05 May 2021 14:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5tRHEWhSo/5j9x6U8ZvggnSDes7sXlgotB44kpOwkYnlPv+XFtbzO9ez7Pk5cj5Bxs9resA== X-Received: by 2002:adf:d223:: with SMTP id k3mr1026853wrh.99.1620249125784; Wed, 05 May 2021 14:12:05 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-ppc@nongnu.org, Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Gibson , Greg Kurz , Jason Wang , Jiri Pirko Subject: [PATCH 15/23] net: Avoid dynamic stack allocation Date: Wed, 5 May 2021 23:10:39 +0200 Message-Id: <20210505211047.1496765-16-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210505211047.1496765-1-philmd@redhat.com> References: <20210505211047.1496765-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Use autofree heap allocation instead of variable-length array on the stack. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Jason Wang --- 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 =3D bd->bufptr + ((hwaddr)(etsec->regs[TBDBPH].value & 0xF) << 32); - uint8_t padd[etsec->rx_padding]; - uint8_t rem; =20 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 =3D MIN(etsec->regs[MRBLR].value - bd->length, etsec->rx_paddi= ng); + uint8_t rem =3D MIN(etsec->regs[MRBLR].value - bd->length, + etsec->rx_padding); =20 if (rem > 0) { - memset(padd, 0x0, sizeof(padd)); + g_autofree uint8_t *padd =3D g_malloc0(etsec->rx_padding); + etsec->rx_padding -=3D rem; *size -=3D rem; bd->length +=3D 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 =3D g_new(struct iovec, iovcnt + 2); OfDpaFlowContext fc =3D { .of_dpa =3D world_private(world), .in_pport =3D 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 struc= t iovec *iov, int cnt) int64_t ts; int caplen; size_t size =3D iov_size(iov, cnt); - struct iovec dumpiov[cnt + 1]; + g_autofree struct iovec *dumpiov =3D g_new(struct iovec, cnt + 1); =20 /* 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, cons= t struct iovec *iov, { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); const struct iovec *iovp =3D iov; - struct iovec iov_copy[iovcnt + 1]; + g_autofree struct iovec *iov_copy =3D g_new(struct iovec, iovcnt + 1); struct virtio_net_hdr_mrg_rxbuf hdr =3D { }; =20 if (s->host_vnet_hdr_len && !s->using_vnet_hdr) { --=20 2.26.3