[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_looku
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays() |
Date: |
Mon, 28 Feb 2022 14:50:01 -0300 |
We can get the job done in spapr_numa_write_assoc_lookup_arrays() a bit
cleaner:
- 'cur_index = int_buf = g_malloc0(..)' is doing a g_malloc0() in the
'int_buf' pointer and making 'cur_index' point to 'int_buf' all in a
single line. No problem with that, but splitting into 2 lines is clearer
to follow
- use g_autofree in 'int_buf' to avoid a g_free() call later on
- 'buf_len' is only being used to store the size of 'int_buf' malloc.
Remove the var and just use the value in g_malloc0() directly
- remove the 'ret' var and just return the result of fdt_setprop()
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_numa.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c
index e9ef7e7646..4f93bdefec 100644
--- a/hw/ppc/spapr_numa.c
+++ b/hw/ppc/spapr_numa.c
@@ -431,12 +431,14 @@ int
spapr_numa_write_assoc_lookup_arrays(SpaprMachineState *spapr, void *fdt,
int max_distance_ref_points = get_max_dist_ref_points(spapr);
int nb_numa_nodes = machine->numa_state->num_nodes;
int nr_nodes = nb_numa_nodes ? nb_numa_nodes : 1;
- uint32_t *int_buf, *cur_index, buf_len;
- int ret, i;
+ g_autofree uint32_t *int_buf = NULL;
+ uint32_t *cur_index;
+ int i;
/* ibm,associativity-lookup-arrays */
- buf_len = (nr_nodes * max_distance_ref_points + 2) * sizeof(uint32_t);
- cur_index = int_buf = g_malloc0(buf_len);
+ int_buf = g_malloc0((nr_nodes * max_distance_ref_points + 2) *
+ sizeof(uint32_t));
+ cur_index = int_buf;
int_buf[0] = cpu_to_be32(nr_nodes);
/* Number of entries per associativity list */
int_buf[1] = cpu_to_be32(max_distance_ref_points);
@@ -451,11 +453,9 @@ int spapr_numa_write_assoc_lookup_arrays(SpaprMachineState
*spapr, void *fdt,
sizeof(uint32_t) * max_distance_ref_points);
cur_index += max_distance_ref_points;
}
- ret = fdt_setprop(fdt, offset, "ibm,associativity-lookup-arrays", int_buf,
- (cur_index - int_buf) * sizeof(uint32_t));
- g_free(int_buf);
- return ret;
+ return fdt_setprop(fdt, offset, "ibm,associativity-lookup-arrays",
+ int_buf, (cur_index - int_buf) * sizeof(uint32_t));
}
static void spapr_numa_FORM1_write_rtas_dt(SpaprMachineState *spapr,
--
2.35.1
- [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string(), (continued)
- [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 06/14] hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 07/14] hw/ppc/spapr_drc.c: use g_autofree in drc_realize(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 08/14] hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 09/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 10/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 13/14] hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 14/14] hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 12/14] spapr_pci_nvlink2.c: use g_autofree in spapr_phb_nvgpu_ram_populate_dt(), Daniel Henrique Barboza, 2022/02/28
- [PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays(),
Daniel Henrique Barboza <=
- Re: [PATCH 00/14] simple cleanups in spapr files, Philippe Mathieu-Daudé, 2022/02/28