[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 10/23] hw/ppc/pnv: Avoid dynamic stack allocation
From: |
David Gibson |
Subject: |
Re: [PATCH 10/23] hw/ppc/pnv: Avoid dynamic stack allocation |
Date: |
Thu, 6 May 2021 12:12:25 +1000 |
On Wed, May 05, 2021 at 11:10:34PM +0200, Philippe Mathieu-Daudé wrote:
> 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>
> ---
> 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 77af846cdfe..f6e3d37b751 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -141,7 +141,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};
> @@ -244,7 +244,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 529ff056dd2..31c2c0d97bf 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -176,8 +176,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) {
> @@ -195,12 +195,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 8ef9b40a18d..bb61adb114c 100644
> --- a/hw/ppc/spapr_pci_nvlink2.c
> +++ b/hw/ppc/spapr_pci_nvlink2.c
> @@ -401,7 +401,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;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
signature.asc
Description: PGP signature
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, (continued)
- [PATCH 08/23] hw/block/nvme: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 09/23] hw/net/e1000e_core: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 10/23] hw/ppc/pnv: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- Re: [PATCH 10/23] hw/ppc/pnv: Avoid dynamic stack allocation,
David Gibson <=
- [PATCH 11/23] hw/intc/xics: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 12/23] hw/i386/multiboot: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 13/23] hw/usb/hcd-xhci: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 14/23] hw/usb/hcd-ohci: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05