From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Samuel Thibault" <samuel.thibault@ens-lyon.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Cédric Le Goater" <clg@kaod.org>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Greg Kurz" <groug@kaod.org>,
"Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
qemu-ppc@nongnu.org
Subject: Re: [PATCH v2 06/11] hw/ppc/pnv: Avoid dynamic stack allocation
Date: Fri, 19 Aug 2022 14:22:07 -0300 [thread overview]
Message-ID: <67d7080b-e854-d1f4-e1c6-db420f0df450@gmail.com> (raw)
In-Reply-To: <20220819153931.3147384-7-peter.maydell@linaro.org>
On 8/19/22 12:39, Peter Maydell wrote:
> From: Philippe Mathieu-Daudé <philmd@redhat.com>
>
> Use autofree heap allocation instead of variable-length
> array on the stack.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Acked-by: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Feel free to take it via target-arm.next.
Thanks,
Daniel
> ---
> hw/ppc/pnv.c | 4 ++--
> hw/ppc/spapr.c | 8 ++++----
> hw/ppc/spapr_pci_nvlink2.c | 2 +-
> 3 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> index d3f77c83672..dd4101e5b65 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -137,7 +137,7 @@ static void pnv_dt_core(PnvChip *chip, PnvCore *pc, void *fdt)
> int smt_threads = CPU_CORE(pc)->nr_threads;
> CPUPPCState *env = &cpu->env;
> PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs);
> - uint32_t servers_prop[smt_threads];
> + g_autofree uint32_t *servers_prop = g_new(uint32_t, smt_threads);
> int i;
> uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40),
> 0xffffffff, 0xffffffff};
> @@ -240,7 +240,7 @@ static void pnv_dt_core(PnvChip *chip, PnvCore *pc, void *fdt)
> servers_prop[i] = cpu_to_be32(pc->pir + i);
> }
> _FDT((fdt_setprop(fdt, offset, "ibm,ppc-interrupt-server#s",
> - servers_prop, sizeof(servers_prop))));
> + servers_prop, sizeof(*servers_prop) * smt_threads)));
> }
>
> static void pnv_dt_icp(PnvChip *chip, void *fdt, uint32_t pir,
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index bc9ba6e6dcf..28626efd479 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -177,8 +177,8 @@ static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
> int smt_threads)
> {
> int i, ret = 0;
> - uint32_t servers_prop[smt_threads];
> - uint32_t gservers_prop[smt_threads * 2];
> + g_autofree uint32_t *servers_prop = g_new(uint32_t, smt_threads);
> + g_autofree uint32_t *gservers_prop = g_new(uint32_t, smt_threads * 2);
> int index = spapr_get_vcpu_id(cpu);
>
> if (cpu->compat_pvr) {
> @@ -196,12 +196,12 @@ static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
> gservers_prop[i*2 + 1] = 0;
> }
> ret = fdt_setprop(fdt, offset, "ibm,ppc-interrupt-server#s",
> - servers_prop, sizeof(servers_prop));
> + servers_prop, sizeof(*servers_prop) * smt_threads);
> if (ret < 0) {
> return ret;
> }
> ret = fdt_setprop(fdt, offset, "ibm,ppc-interrupt-gserver#s",
> - gservers_prop, sizeof(gservers_prop));
> + gservers_prop, sizeof(*gservers_prop) * smt_threads * 2);
>
> return ret;
> }
> diff --git a/hw/ppc/spapr_pci_nvlink2.c b/hw/ppc/spapr_pci_nvlink2.c
> index 63b476c8f72..2a8a11be1d6 100644
> --- a/hw/ppc/spapr_pci_nvlink2.c
> +++ b/hw/ppc/spapr_pci_nvlink2.c
> @@ -397,7 +397,7 @@ void spapr_phb_nvgpu_populate_pcidev_dt(PCIDevice *dev, void *fdt, int offset,
> continue;
> }
> if (dev == nvslot->gpdev) {
> - uint32_t npus[nvslot->linknum];
> + g_autofree uint32_t *npus = g_new(uint32_t, nvslot->linknum);
>
> for (j = 0; j < nvslot->linknum; ++j) {
> PCIDevice *npdev = nvslot->links[j].npdev;
next prev parent reply other threads:[~2022-08-19 17:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-19 15:39 [PATCH v2 00/11] misc: Remove variable-length arrays on the stack Peter Maydell
2022-08-19 15:39 ` [PATCH v2 01/11] chardev/baum: Replace magic values by X_MAX / Y_MAX definitions Peter Maydell
2022-10-24 23:11 ` Richard Henderson
2022-08-19 15:39 ` [PATCH v2 02/11] chardev/baum: Use definitions to avoid dynamic stack allocation Peter Maydell
2022-10-24 23:12 ` Richard Henderson
2022-08-19 15:39 ` [PATCH v2 03/11] chardev/baum: Avoid " Peter Maydell
2022-10-24 23:13 ` Richard Henderson
2022-08-19 15:39 ` [PATCH v2 04/11] io/channel-websock: Replace strlen(const_str) by sizeof(const_str) - 1 Peter Maydell
2022-10-24 23:13 ` Richard Henderson
2022-08-19 15:39 ` [PATCH v2 05/11] hw/net/e1000e_core: Use definition to avoid dynamic stack allocation Peter Maydell
2022-08-19 15:39 ` [PATCH v2 06/11] hw/ppc/pnv: Avoid " Peter Maydell
2022-08-19 17:22 ` Daniel Henrique Barboza [this message]
2022-10-24 23:15 ` Richard Henderson
2022-08-19 15:39 ` [PATCH v2 07/11] hw/intc/xics: " Peter Maydell
2022-10-24 23:16 ` Richard Henderson
2022-08-19 15:39 ` [PATCH v2 08/11] hw/i386/multiboot: " Peter Maydell
2022-08-19 15:39 ` [PATCH v2 09/11] hw/usb/hcd-ohci: Use definition to avoid " Peter Maydell
2022-08-19 15:39 ` [PATCH v2 10/11] ui/curses: Avoid " Peter Maydell
2022-08-19 15:39 ` [PATCH v2 11/11] tests/unit/test-vmstate: " Peter Maydell
2022-08-25 14:14 ` [PATCH v2 00/11] misc: Remove variable-length arrays on the stack Philippe Mathieu-Daudé via
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=67d7080b-e854-d1f4-e1c6-db420f0df450@gmail.com \
--to=danielhb413@gmail.com \
--cc=berrange@redhat.com \
--cc=clg@kaod.org \
--cc=david@gibson.dropbear.id.au \
--cc=dmitry.fleytman@gmail.com \
--cc=eduardo@habkost.net \
--cc=f4bug@amsat.org \
--cc=groug@kaod.org \
--cc=marcandre.lureau@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=samuel.thibault@ens-lyon.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).