* [PATCH 00/14] simple cleanups in spapr files
@ 2022-02-28 17:49 Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen() Daniel Henrique Barboza
` (14 more replies)
0 siblings, 15 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Hi,
These are some cleanups in spapr files I decided to make after seeing
Greg adding g_auto* in virtio-9p files.
I also took the opportunity to simplify the logic in some places where I
found it to be more complex than needed.
Aside from patch 02, no functional change was made in this series.
Daniel Henrique Barboza (14):
hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen()
hw/ppc/spapr.c: fail early if no firmware found in machine_init()
hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string()
hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string()
hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties()
hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc()
hw/ppc/spapr_drc.c: use g_autofree in drc_realize()
hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize()
hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new()
hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index()
hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays()
spapr_pci_nvlink2.c: use g_autofree in
spapr_phb_nvgpu_ram_populate_dt()
hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter()
hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice()
hw/ppc/spapr.c | 31 +++++++++++--------------
hw/ppc/spapr_caps.c | 22 +++++++-----------
hw/ppc/spapr_drc.c | 47 ++++++++++++++------------------------
hw/ppc/spapr_numa.c | 16 ++++++-------
hw/ppc/spapr_pci_nvlink2.c | 10 ++++----
hw/ppc/spapr_rtas.c | 25 ++++++++++----------
hw/ppc/spapr_vio.c | 6 ++---
7 files changed, 64 insertions(+), 93 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-03-01 0:58 ` David Gibson
2022-02-28 17:49 ` [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init() Daniel Henrique Barboza
` (13 subsequent siblings)
14 siblings, 1 reply; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index f0b75b22bb..c74543ace3 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1018,9 +1018,9 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
if (reset) {
const char *boot_device = spapr->boot_device;
- char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
+ g_autofree char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
size_t cb = 0;
- char *bootlist = get_boot_devices_list(&cb);
+ g_autofree char *bootlist = get_boot_devices_list(&cb);
if (machine->kernel_cmdline && machine->kernel_cmdline[0]) {
_FDT(fdt_setprop_string(fdt, chosen, "bootargs",
@@ -1087,9 +1087,6 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
}
spapr_dt_ov5_platform_support(spapr, fdt, chosen);
-
- g_free(stdout_path);
- g_free(bootlist);
}
_FDT(spapr_dt_ovec(fdt, chosen, spapr->ov5_cas, "ibm,architecture-vec-5"));
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-02-28 19:28 ` BALATON Zoltan
2022-03-01 2:24 ` David Gibson
2022-02-28 17:49 ` [PATCH 03/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string() Daniel Henrique Barboza
` (12 subsequent siblings)
14 siblings, 2 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
The firmware check consists on a file search (qemu_find_file) and load
it via load_imag_targphys(). This validation is not dependent on any
other machine state but it currently being done at the end of
spapr_machine_init(). This means that we can do a lot of stuff and end
up failing at the end for something that we can verify right out of the
gate.
Move this validation to the start of spapr_machine_init() to fail
earlier. While we're at it, use g_autofree in the 'filename' pointer.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index c74543ace3..4cc204f90d 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2707,15 +2707,25 @@ static void spapr_machine_init(MachineState *machine)
MachineClass *mc = MACHINE_GET_CLASS(machine);
const char *bios_default = spapr->vof ? FW_FILE_NAME_VOF : FW_FILE_NAME;
const char *bios_name = machine->firmware ?: bios_default;
+ g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
const char *kernel_filename = machine->kernel_filename;
const char *initrd_filename = machine->initrd_filename;
PCIHostState *phb;
int i;
MemoryRegion *sysmem = get_system_memory();
long load_limit, fw_size;
- char *filename;
Error *resize_hpt_err = NULL;
+ if (!filename) {
+ error_report("Could not find LPAR firmware '%s'", bios_name);
+ exit(1);
+ }
+ fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
+ if (fw_size <= 0) {
+ error_report("Could not load LPAR firmware '%s'", filename);
+ exit(1);
+ }
+
/*
* if Secure VM (PEF) support is configured, then initialize it
*/
@@ -2996,18 +3006,6 @@ static void spapr_machine_init(MachineState *machine)
}
}
- filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
- if (!filename) {
- error_report("Could not find LPAR firmware '%s'", bios_name);
- exit(1);
- }
- fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
- if (fw_size <= 0) {
- error_report("Could not load LPAR firmware '%s'", filename);
- exit(1);
- }
- g_free(filename);
-
/* FIXME: Should register things through the MachineState's qdev
* interface, this is a legacy from the sPAPREnvironment structure
* which predated MachineState but had a similar function */
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 03/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen() Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-03-01 3:14 ` David Gibson
2022-02-28 17:49 ` [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string() Daniel Henrique Barboza
` (11 subsequent siblings)
14 siblings, 1 reply; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
And get rid of the 'out' label since it's now used.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_caps.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index 6167431271..aab313ffb1 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -120,7 +120,7 @@ static void spapr_cap_set_string(Object *obj, Visitor *v, const char *name,
SpaprCapabilityInfo *cap = opaque;
SpaprMachineState *spapr = SPAPR_MACHINE(obj);
uint8_t i;
- char *val;
+ g_autofree char *val = NULL;
if (!visit_type_str(v, name, &val, errp)) {
return;
@@ -128,20 +128,18 @@ static void spapr_cap_set_string(Object *obj, Visitor *v, const char *name,
if (!strcmp(val, "?")) {
error_setg(errp, "%s", cap->possible->help);
- goto out;
+ return;
}
for (i = 0; i < cap->possible->num; i++) {
if (!strcasecmp(val, cap->possible->vals[i])) {
spapr->cmd_line_caps[cap->index] = true;
spapr->eff.caps[cap->index] = i;
- goto out;
+ return;
}
}
error_setg(errp, "Invalid capability mode \"%s\" for cap-%s", val,
cap->name);
-out:
- g_free(val);
}
static void spapr_cap_get_pagesize(Object *obj, Visitor *v, const char *name,
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (2 preceding siblings ...)
2022-02-28 17:49 ` [PATCH 03/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-03-01 3:15 ` David Gibson
2022-02-28 17:49 ` [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties() Daniel Henrique Barboza
` (10 subsequent siblings)
14 siblings, 1 reply; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_caps.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index aab313ffb1..2773f9db9e 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -95,12 +95,12 @@ static void spapr_cap_set_bool(Object *obj, Visitor *v, const char *name,
}
-static void spapr_cap_get_string(Object *obj, Visitor *v, const char *name,
- void *opaque, Error **errp)
+static void spapr_cap_get_string(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
{
SpaprCapabilityInfo *cap = opaque;
SpaprMachineState *spapr = SPAPR_MACHINE(obj);
- char *val = NULL;
+ g_autofree char *val = NULL;
uint8_t value = spapr_get_cap(spapr, cap->index);
if (value >= cap->possible->num) {
@@ -111,7 +111,6 @@ static void spapr_cap_get_string(Object *obj, Visitor *v, const char *name,
val = g_strdup(cap->possible->vals[value]);
visit_type_str(v, name, &val, errp);
- g_free(val);
}
static void spapr_cap_set_string(Object *obj, Visitor *v, const char *name,
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (3 preceding siblings ...)
2022-02-28 17:49 ` [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-03-01 3:15 ` David Gibson
2022-02-28 17:49 ` [PATCH 06/14] hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc() Daniel Henrique Barboza
` (9 subsequent siblings)
14 siblings, 1 reply; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_caps.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index 2773f9db9e..655ab856a0 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -930,16 +930,13 @@ void spapr_caps_add_properties(SpaprMachineClass *smc)
for (i = 0; i < ARRAY_SIZE(capability_table); i++) {
SpaprCapabilityInfo *cap = &capability_table[i];
- char *name = g_strdup_printf("cap-%s", cap->name);
- char *desc;
+ g_autofree char *name = g_strdup_printf("cap-%s", cap->name);
+ g_autofree char *desc = g_strdup_printf("%s", cap->description);
object_class_property_add(klass, name, cap->type,
cap->get, cap->set,
NULL, cap);
- desc = g_strdup_printf("%s", cap->description);
object_class_property_set_description(klass, name, desc);
- g_free(name);
- g_free(desc);
}
}
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 06/14] hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (4 preceding siblings ...)
2022-02-28 17:49 ` [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 07/14] hw/ppc/spapr_drc.c: use g_autofree in drc_realize() Daniel Henrique Barboza
` (8 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Use g_autoptr() with GArray* and GString* pointers to avoid calling
g_free() and the need for the 'out' label.
'drc_name' can also be g_autofreed to avoid a g_free() call at the end
of the while() loop.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_drc.c | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index f8ac0a10df..0ba84063aa 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -841,8 +841,14 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask)
ObjectProperty *prop;
ObjectPropertyIterator iter;
uint32_t drc_count = 0;
- GArray *drc_indexes, *drc_power_domains;
- GString *drc_names, *drc_types;
+ g_autoptr(GArray) drc_indexes = g_array_new(false, true,
+ sizeof(uint32_t));
+ g_autoptr(GArray) drc_power_domains = g_array_new(false, true,
+ sizeof(uint32_t));
+ g_autoptr(GString) drc_names = g_string_set_size(g_string_new(NULL),
+ sizeof(uint32_t));
+ g_autoptr(GString) drc_types = g_string_set_size(g_string_new(NULL),
+ sizeof(uint32_t));
int ret;
/*
@@ -857,12 +863,8 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask)
* reserve the space now and set the offsets accordingly so we
* can fill them in later.
*/
- drc_indexes = g_array_new(false, true, sizeof(uint32_t));
drc_indexes = g_array_set_size(drc_indexes, 1);
- drc_power_domains = g_array_new(false, true, sizeof(uint32_t));
drc_power_domains = g_array_set_size(drc_power_domains, 1);
- drc_names = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
- drc_types = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
/* aliases for all DRConnector objects will be rooted in QOM
* composition tree at DRC_CONTAINER_PATH
@@ -874,7 +876,7 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask)
Object *obj;
SpaprDrc *drc;
SpaprDrcClass *drck;
- char *drc_name = NULL;
+ g_autofree char *drc_name = NULL;
uint32_t drc_index, drc_power_domain;
if (!strstart(prop->type, "link<", NULL)) {
@@ -908,7 +910,6 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask)
drc_name = spapr_drc_name(drc);
drc_names = g_string_append(drc_names, drc_name);
drc_names = g_string_insert_len(drc_names, -1, "\0", 1);
- g_free(drc_name);
/* ibm,drc-types */
drc_types = g_string_append(drc_types, drck->typename);
@@ -928,7 +929,7 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask)
drc_indexes->len * sizeof(uint32_t));
if (ret) {
error_report("Couldn't create ibm,drc-indexes property");
- goto out;
+ return ret;
}
ret = fdt_setprop(fdt, offset, "ibm,drc-power-domains",
@@ -936,29 +937,22 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask)
drc_power_domains->len * sizeof(uint32_t));
if (ret) {
error_report("Couldn't finalize ibm,drc-power-domains property");
- goto out;
+ return ret;
}
ret = fdt_setprop(fdt, offset, "ibm,drc-names",
drc_names->str, drc_names->len);
if (ret) {
error_report("Couldn't finalize ibm,drc-names property");
- goto out;
+ return ret;
}
ret = fdt_setprop(fdt, offset, "ibm,drc-types",
drc_types->str, drc_types->len);
if (ret) {
error_report("Couldn't finalize ibm,drc-types property");
- goto out;
}
-out:
- g_array_free(drc_indexes, true);
- g_array_free(drc_power_domains, true);
- g_string_free(drc_names, true);
- g_string_free(drc_types, true);
-
return ret;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 07/14] hw/ppc/spapr_drc.c: use g_autofree in drc_realize()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (5 preceding siblings ...)
2022-02-28 17:49 ` [PATCH 06/14] hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 08/14] hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize() Daniel Henrique Barboza
` (7 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_drc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 0ba84063aa..251201fab3 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -519,8 +519,8 @@ static const VMStateDescription vmstate_spapr_drc = {
static void drc_realize(DeviceState *d, Error **errp)
{
SpaprDrc *drc = SPAPR_DR_CONNECTOR(d);
+ g_autofree gchar *link_name = g_strdup_printf("%x", spapr_drc_index(drc));
Object *root_container;
- gchar *link_name;
const char *child_name;
trace_spapr_drc_realize(spapr_drc_index(drc));
@@ -532,12 +532,10 @@ static void drc_realize(DeviceState *d, Error **errp)
* existing in the composition tree
*/
root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
- link_name = g_strdup_printf("%x", spapr_drc_index(drc));
child_name = object_get_canonical_path_component(OBJECT(drc));
trace_spapr_drc_realize_child(spapr_drc_index(drc), child_name);
object_property_add_alias(root_container, link_name,
drc->owner, child_name);
- g_free(link_name);
vmstate_register(VMSTATE_IF(drc), spapr_drc_index(drc), &vmstate_spapr_drc,
drc);
trace_spapr_drc_realize_complete(spapr_drc_index(drc));
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 08/14] hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (6 preceding siblings ...)
2022-02-28 17:49 ` [PATCH 07/14] hw/ppc/spapr_drc.c: use g_autofree in drc_realize() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 09/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new() Daniel Henrique Barboza
` (6 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_drc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 251201fab3..b2a365baf1 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -544,15 +544,13 @@ static void drc_realize(DeviceState *d, Error **errp)
static void drc_unrealize(DeviceState *d)
{
SpaprDrc *drc = SPAPR_DR_CONNECTOR(d);
+ g_autofree gchar *name = g_strdup_printf("%x", spapr_drc_index(drc));
Object *root_container;
- gchar *name;
trace_spapr_drc_unrealize(spapr_drc_index(drc));
vmstate_unregister(VMSTATE_IF(drc), &vmstate_spapr_drc, drc);
root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
- name = g_strdup_printf("%x", spapr_drc_index(drc));
object_property_del(root_container, name);
- g_free(name);
}
SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 09/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (7 preceding siblings ...)
2022-02-28 17:49 ` [PATCH 08/14] hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize() Daniel Henrique Barboza
@ 2022-02-28 17:49 ` Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 10/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index() Daniel Henrique Barboza
` (5 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_drc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index b2a365baf1..ac4067625e 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -557,7 +557,7 @@ SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
uint32_t id)
{
SpaprDrc *drc = SPAPR_DR_CONNECTOR(object_new(type));
- char *prop_name;
+ g_autofree char *prop_name = NULL;
drc->id = id;
drc->owner = owner;
@@ -566,7 +566,6 @@ SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
object_property_add_child(owner, prop_name, OBJECT(drc));
object_unref(OBJECT(drc));
qdev_realize(DEVICE(drc), NULL, NULL);
- g_free(prop_name);
return drc;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 10/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (8 preceding siblings ...)
2022-02-28 17:49 ` [PATCH 09/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new() Daniel Henrique Barboza
@ 2022-02-28 17:50 ` Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays() Daniel Henrique Barboza
` (4 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_drc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index ac4067625e..76bc5d42a0 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -798,11 +798,9 @@ static const TypeInfo spapr_drc_pmem_info = {
SpaprDrc *spapr_drc_by_index(uint32_t index)
{
Object *obj;
- gchar *name;
-
- name = g_strdup_printf("%s/%x", DRC_CONTAINER_PATH, index);
+ g_autofree gchar *name = g_strdup_printf("%s/%x", DRC_CONTAINER_PATH,
+ index);
obj = object_resolve_path(name, NULL);
- g_free(name);
return !obj ? NULL : SPAPR_DR_CONNECTOR(obj);
}
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (9 preceding siblings ...)
2022-02-28 17:50 ` [PATCH 10/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index() Daniel Henrique Barboza
@ 2022-02-28 17:50 ` Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 12/14] spapr_pci_nvlink2.c: use g_autofree in spapr_phb_nvgpu_ram_populate_dt() Daniel Henrique Barboza
` (3 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
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
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 12/14] spapr_pci_nvlink2.c: use g_autofree in spapr_phb_nvgpu_ram_populate_dt()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (10 preceding siblings ...)
2022-02-28 17:50 ` [PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays() Daniel Henrique Barboza
@ 2022-02-28 17:50 ` Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 13/14] hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter() Daniel Henrique Barboza
` (2 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_pci_nvlink2.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/hw/ppc/spapr_pci_nvlink2.c b/hw/ppc/spapr_pci_nvlink2.c
index 7fb0cf4d04..4678c79235 100644
--- a/hw/ppc/spapr_pci_nvlink2.c
+++ b/hw/ppc/spapr_pci_nvlink2.c
@@ -320,7 +320,7 @@ void spapr_phb_nvgpu_populate_dt(SpaprPhbState *sphb, void *fdt, int bus_off,
void spapr_phb_nvgpu_ram_populate_dt(SpaprPhbState *sphb, void *fdt)
{
int i, j, linkidx, npuoff;
- char *npuname;
+ g_autofree char *npuname = NULL;
if (!sphb->nvgpus) {
return;
@@ -333,11 +333,10 @@ void spapr_phb_nvgpu_ram_populate_dt(SpaprPhbState *sphb, void *fdt)
_FDT(fdt_setprop_cell(fdt, npuoff, "#size-cells", 0));
/* Advertise NPU as POWER9 so the guest can enable NPU2 contexts */
_FDT((fdt_setprop_string(fdt, npuoff, "compatible", "ibm,power9-npu")));
- g_free(npuname);
for (i = 0, linkidx = 0; i < sphb->nvgpus->num; ++i) {
for (j = 0; j < sphb->nvgpus->slots[i].linknum; ++j) {
- char *linkname = g_strdup_printf("link@%d", linkidx);
+ g_autofree char *linkname = g_strdup_printf("link@%d", linkidx);
int off = fdt_add_subnode(fdt, npuoff, linkname);
_FDT(off);
@@ -347,7 +346,6 @@ void spapr_phb_nvgpu_ram_populate_dt(SpaprPhbState *sphb, void *fdt)
_FDT((fdt_setprop_cell(fdt, off, "phandle",
PHANDLE_NVLINK(sphb, i, j))));
_FDT((fdt_setprop_cell(fdt, off, "ibm,npu-link-index", linkidx)));
- g_free(linkname);
++linkidx;
}
}
@@ -360,7 +358,8 @@ void spapr_phb_nvgpu_ram_populate_dt(SpaprPhbState *sphb, void *fdt)
&error_abort);
uint64_t size = object_property_get_uint(nv_mrobj, "size", NULL);
uint64_t mem_reg[2] = { cpu_to_be64(nvslot->gpa), cpu_to_be64(size) };
- char *mem_name = g_strdup_printf("memory@%"PRIx64, nvslot->gpa);
+ g_autofree char *mem_name = g_strdup_printf("memory@%"PRIx64,
+ nvslot->gpa);
int off = fdt_add_subnode(fdt, 0, mem_name);
_FDT(off);
@@ -378,7 +377,6 @@ void spapr_phb_nvgpu_ram_populate_dt(SpaprPhbState *sphb, void *fdt)
sizeof(mem_reg))));
_FDT((fdt_setprop_cell(fdt, off, "phandle",
PHANDLE_GPURAM(sphb, i))));
- g_free(mem_name);
}
}
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 13/14] hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (11 preceding siblings ...)
2022-02-28 17:50 ` [PATCH 12/14] spapr_pci_nvlink2.c: use g_autofree in spapr_phb_nvgpu_ram_populate_dt() Daniel Henrique Barboza
@ 2022-02-28 17:50 ` Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 14/14] hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice() Daniel Henrique Barboza
2022-02-28 18:13 ` [PATCH 00/14] simple cleanups in spapr files Philippe Mathieu-Daudé
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_rtas.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index b476382ae6..d7c04237fe 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -279,30 +279,29 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
switch (parameter) {
case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS: {
- char *param_val = g_strdup_printf("MaxEntCap=%d,"
- "DesMem=%" PRIu64 ","
- "DesProcs=%d,"
- "MaxPlatProcs=%d",
- ms->smp.max_cpus,
- ms->ram_size / MiB,
- ms->smp.cpus,
- ms->smp.max_cpus);
+ g_autofree char *param_val = g_strdup_printf("MaxEntCap=%d,"
+ "DesMem=%" PRIu64 ","
+ "DesProcs=%d,"
+ "MaxPlatProcs=%d",
+ ms->smp.max_cpus,
+ ms->ram_size / MiB,
+ ms->smp.cpus,
+ ms->smp.max_cpus);
if (pcc->n_host_threads > 0) {
- char *hostthr_val, *old = param_val;
-
/*
* Add HostThrs property. This property is not present in PAPR but
* is expected by some guests to communicate the number of physical
* host threads per core on the system so that they can scale
* information which varies based on the thread configuration.
*/
- hostthr_val = g_strdup_printf(",HostThrs=%d", pcc->n_host_threads);
+ g_autofree char *hostthr_val = g_strdup_printf(",HostThrs=%d",
+ pcc->n_host_threads);
+ char *old = param_val;
+
param_val = g_strconcat(param_val, hostthr_val, NULL);
- g_free(hostthr_val);
g_free(old);
}
ret = sysparm_st(buffer, length, param_val, strlen(param_val) + 1);
- g_free(param_val);
break;
}
case RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE: {
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 14/14] hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice()
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (12 preceding siblings ...)
2022-02-28 17:50 ` [PATCH 13/14] hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter() Daniel Henrique Barboza
@ 2022-02-28 17:50 ` Daniel Henrique Barboza
2022-02-28 18:13 ` [PATCH 00/14] simple cleanups in spapr files Philippe Mathieu-Daudé
14 siblings, 0 replies; 22+ messages in thread
From: Daniel Henrique Barboza @ 2022-02-28 17:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david
And return the result of g_strdup_printf() directly instead of using the
'path' var.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/ppc/spapr_vio.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index b975ed29ca..9d4fec2c04 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -726,7 +726,7 @@ void spapr_dt_vdevice(SpaprVioBus *bus, void *fdt)
gchar *spapr_vio_stdout_path(SpaprVioBus *bus)
{
SpaprVioDevice *dev;
- char *name, *path;
+ g_autofree char *name = NULL;
dev = spapr_vty_get_default(bus);
if (!dev) {
@@ -734,8 +734,6 @@ gchar *spapr_vio_stdout_path(SpaprVioBus *bus)
}
name = spapr_vio_get_dev_name(DEVICE(dev));
- path = g_strdup_printf("/vdevice/%s", name);
- g_free(name);
- return path;
+ return g_strdup_printf("/vdevice/%s", name);
}
--
2.35.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH 00/14] simple cleanups in spapr files
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
` (13 preceding siblings ...)
2022-02-28 17:50 ` [PATCH 14/14] hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice() Daniel Henrique Barboza
@ 2022-02-28 18:13 ` Philippe Mathieu-Daudé
14 siblings, 0 replies; 22+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-02-28 18:13 UTC (permalink / raw)
To: Daniel Henrique Barboza, qemu-devel; +Cc: qemu-ppc, clg, david
On 28/2/22 18:49, Daniel Henrique Barboza wrote:
> Hi,
>
> These are some cleanups in spapr files I decided to make after seeing
> Greg adding g_auto* in virtio-9p files.
>
> I also took the opportunity to simplify the logic in some places where I
> found it to be more complex than needed.
>
> Aside from patch 02, no functional change was made in this series.
>
> Daniel Henrique Barboza (14):
> hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen()
> hw/ppc/spapr.c: fail early if no firmware found in machine_init()
> hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string()
> hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string()
> hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties()
> hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc()
> hw/ppc/spapr_drc.c: use g_autofree in drc_realize()
> hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize()
> hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new()
> hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index()
> hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays()
> spapr_pci_nvlink2.c: use g_autofree in
> spapr_phb_nvgpu_ram_populate_dt()
> hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter()
> hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice()
Series:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init()
2022-02-28 17:49 ` [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init() Daniel Henrique Barboza
@ 2022-02-28 19:28 ` BALATON Zoltan
2022-03-01 2:24 ` David Gibson
1 sibling, 0 replies; 22+ messages in thread
From: BALATON Zoltan @ 2022-02-28 19:28 UTC (permalink / raw)
To: Daniel Henrique Barboza; +Cc: david, qemu-ppc, qemu-devel, clg
On Mon, 28 Feb 2022, Daniel Henrique Barboza wrote:
> The firmware check consists on a file search (qemu_find_file) and load
> it via load_imag_targphys(). This validation is not dependent on any
> other machine state but it currently being done at the end of
> spapr_machine_init(). This means that we can do a lot of stuff and end
> up failing at the end for something that we can verify right out of the
> gate.
>
> Move this validation to the start of spapr_machine_init() to fail
> earlier. While we're at it, use g_autofree in the 'filename' pointer.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---
> hw/ppc/spapr.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index c74543ace3..4cc204f90d 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -2707,15 +2707,25 @@ static void spapr_machine_init(MachineState *machine)
> MachineClass *mc = MACHINE_GET_CLASS(machine);
> const char *bios_default = spapr->vof ? FW_FILE_NAME_VOF : FW_FILE_NAME;
> const char *bios_name = machine->firmware ?: bios_default;
> + g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> const char *kernel_filename = machine->kernel_filename;
> const char *initrd_filename = machine->initrd_filename;
> PCIHostState *phb;
> int i;
> MemoryRegion *sysmem = get_system_memory();
> long load_limit, fw_size;
> - char *filename;
> Error *resize_hpt_err = NULL;
Keeping it close to where it's used, i.e. right here at the end of the
declarations would be easier to read, considering that it also inits it
right away so checking the value in the next line is more straight
forward.
Grouping with the simliar filename variables is also reasonable but unless
the value of those change later just removing them and using the
machine->{kernel,initrd}_filename directly may be simpler. I did that
before to mac machines to simplify code.
By the way those are declared const char *, does this filename needs to be
const too? Maybe moving the bios_* vars here too makes more sense to keep
them together.
Regards,
BALATON Zoltan
> + if (!filename) {
> + error_report("Could not find LPAR firmware '%s'", bios_name);
> + exit(1);
> + }
> + fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
> + if (fw_size <= 0) {
> + error_report("Could not load LPAR firmware '%s'", filename);
> + exit(1);
> + }
> +
> /*
> * if Secure VM (PEF) support is configured, then initialize it
> */
> @@ -2996,18 +3006,6 @@ static void spapr_machine_init(MachineState *machine)
> }
> }
>
> - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> - if (!filename) {
> - error_report("Could not find LPAR firmware '%s'", bios_name);
> - exit(1);
> - }
> - fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
> - if (fw_size <= 0) {
> - error_report("Could not load LPAR firmware '%s'", filename);
> - exit(1);
> - }
> - g_free(filename);
> -
> /* FIXME: Should register things through the MachineState's qdev
> * interface, this is a legacy from the sPAPREnvironment structure
> * which predated MachineState but had a similar function */
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen()
2022-02-28 17:49 ` [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen() Daniel Henrique Barboza
@ 2022-03-01 0:58 ` David Gibson
0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2022-03-01 0:58 UTC (permalink / raw)
To: Daniel Henrique Barboza; +Cc: qemu-ppc, qemu-devel, clg
[-- Attachment #1: Type: text/plain, Size: 1611 bytes --]
On Mon, Feb 28, 2022 at 02:49:51PM -0300, Daniel Henrique Barboza wrote:
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> hw/ppc/spapr.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index f0b75b22bb..c74543ace3 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1018,9 +1018,9 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
>
> if (reset) {
> const char *boot_device = spapr->boot_device;
> - char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
> + g_autofree char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
> size_t cb = 0;
> - char *bootlist = get_boot_devices_list(&cb);
> + g_autofree char *bootlist = get_boot_devices_list(&cb);
>
> if (machine->kernel_cmdline && machine->kernel_cmdline[0]) {
> _FDT(fdt_setprop_string(fdt, chosen, "bootargs",
> @@ -1087,9 +1087,6 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
> }
>
> spapr_dt_ov5_platform_support(spapr, fdt, chosen);
> -
> - g_free(stdout_path);
> - g_free(bootlist);
> }
>
> _FDT(spapr_dt_ovec(fdt, chosen, spapr->ov5_cas, "ibm,architecture-vec-5"));
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init()
2022-02-28 17:49 ` [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init() Daniel Henrique Barboza
2022-02-28 19:28 ` BALATON Zoltan
@ 2022-03-01 2:24 ` David Gibson
1 sibling, 0 replies; 22+ messages in thread
From: David Gibson @ 2022-03-01 2:24 UTC (permalink / raw)
To: Daniel Henrique Barboza; +Cc: qemu-ppc, qemu-devel, clg
[-- Attachment #1: Type: text/plain, Size: 3035 bytes --]
On Mon, Feb 28, 2022 at 02:49:52PM -0300, Daniel Henrique Barboza wrote:
> The firmware check consists on a file search (qemu_find_file) and load
> it via load_imag_targphys(). This validation is not dependent on any
> other machine state but it currently being done at the end of
> spapr_machine_init(). This means that we can do a lot of stuff and end
> up failing at the end for something that we can verify right out of the
> gate.
>
> Move this validation to the start of spapr_machine_init() to fail
> earlier. While we're at it, use g_autofree in the 'filename' pointer.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> hw/ppc/spapr.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index c74543ace3..4cc204f90d 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -2707,15 +2707,25 @@ static void spapr_machine_init(MachineState *machine)
> MachineClass *mc = MACHINE_GET_CLASS(machine);
> const char *bios_default = spapr->vof ? FW_FILE_NAME_VOF : FW_FILE_NAME;
> const char *bios_name = machine->firmware ?: bios_default;
> + g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> const char *kernel_filename = machine->kernel_filename;
> const char *initrd_filename = machine->initrd_filename;
> PCIHostState *phb;
> int i;
> MemoryRegion *sysmem = get_system_memory();
> long load_limit, fw_size;
> - char *filename;
> Error *resize_hpt_err = NULL;
>
> + if (!filename) {
> + error_report("Could not find LPAR firmware '%s'", bios_name);
> + exit(1);
> + }
> + fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
> + if (fw_size <= 0) {
> + error_report("Could not load LPAR firmware '%s'", filename);
> + exit(1);
> + }
> +
> /*
> * if Secure VM (PEF) support is configured, then initialize it
> */
> @@ -2996,18 +3006,6 @@ static void spapr_machine_init(MachineState *machine)
> }
> }
>
> - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> - if (!filename) {
> - error_report("Could not find LPAR firmware '%s'", bios_name);
> - exit(1);
> - }
> - fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
> - if (fw_size <= 0) {
> - error_report("Could not load LPAR firmware '%s'", filename);
> - exit(1);
> - }
> - g_free(filename);
> -
> /* FIXME: Should register things through the MachineState's qdev
> * interface, this is a legacy from the sPAPREnvironment structure
> * which predated MachineState but had a similar function */
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 03/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string()
2022-02-28 17:49 ` [PATCH 03/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string() Daniel Henrique Barboza
@ 2022-03-01 3:14 ` David Gibson
0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2022-03-01 3:14 UTC (permalink / raw)
To: Daniel Henrique Barboza; +Cc: qemu-ppc, qemu-devel, clg
[-- Attachment #1: Type: text/plain, Size: 1851 bytes --]
On Mon, Feb 28, 2022 at 02:49:53PM -0300, Daniel Henrique Barboza wrote:
> And get rid of the 'out' label since it's now used.
s/used/unused/
>
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> hw/ppc/spapr_caps.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
> index 6167431271..aab313ffb1 100644
> --- a/hw/ppc/spapr_caps.c
> +++ b/hw/ppc/spapr_caps.c
> @@ -120,7 +120,7 @@ static void spapr_cap_set_string(Object *obj, Visitor *v, const char *name,
> SpaprCapabilityInfo *cap = opaque;
> SpaprMachineState *spapr = SPAPR_MACHINE(obj);
> uint8_t i;
> - char *val;
> + g_autofree char *val = NULL;
>
> if (!visit_type_str(v, name, &val, errp)) {
> return;
> @@ -128,20 +128,18 @@ static void spapr_cap_set_string(Object *obj, Visitor *v, const char *name,
>
> if (!strcmp(val, "?")) {
> error_setg(errp, "%s", cap->possible->help);
> - goto out;
> + return;
> }
> for (i = 0; i < cap->possible->num; i++) {
> if (!strcasecmp(val, cap->possible->vals[i])) {
> spapr->cmd_line_caps[cap->index] = true;
> spapr->eff.caps[cap->index] = i;
> - goto out;
> + return;
> }
> }
>
> error_setg(errp, "Invalid capability mode \"%s\" for cap-%s", val,
> cap->name);
> -out:
> - g_free(val);
> }
>
> static void spapr_cap_get_pagesize(Object *obj, Visitor *v, const char *name,
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string()
2022-02-28 17:49 ` [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string() Daniel Henrique Barboza
@ 2022-03-01 3:15 ` David Gibson
0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2022-03-01 3:15 UTC (permalink / raw)
To: Daniel Henrique Barboza; +Cc: qemu-ppc, qemu-devel, clg
[-- Attachment #1: Type: text/plain, Size: 1643 bytes --]
On Mon, Feb 28, 2022 at 02:49:54PM -0300, Daniel Henrique Barboza wrote:
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> hw/ppc/spapr_caps.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
> index aab313ffb1..2773f9db9e 100644
> --- a/hw/ppc/spapr_caps.c
> +++ b/hw/ppc/spapr_caps.c
> @@ -95,12 +95,12 @@ static void spapr_cap_set_bool(Object *obj, Visitor *v, const char *name,
> }
>
>
> -static void spapr_cap_get_string(Object *obj, Visitor *v, const char *name,
> - void *opaque, Error **errp)
> +static void spapr_cap_get_string(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> {
> SpaprCapabilityInfo *cap = opaque;
> SpaprMachineState *spapr = SPAPR_MACHINE(obj);
> - char *val = NULL;
> + g_autofree char *val = NULL;
> uint8_t value = spapr_get_cap(spapr, cap->index);
>
> if (value >= cap->possible->num) {
> @@ -111,7 +111,6 @@ static void spapr_cap_get_string(Object *obj, Visitor *v, const char *name,
> val = g_strdup(cap->possible->vals[value]);
>
> visit_type_str(v, name, &val, errp);
> - g_free(val);
> }
>
> static void spapr_cap_set_string(Object *obj, Visitor *v, const char *name,
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties()
2022-02-28 17:49 ` [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties() Daniel Henrique Barboza
@ 2022-03-01 3:15 ` David Gibson
0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2022-03-01 3:15 UTC (permalink / raw)
To: Daniel Henrique Barboza; +Cc: qemu-ppc, qemu-devel, clg
[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]
On Mon, Feb 28, 2022 at 02:49:55PM -0300, Daniel Henrique Barboza wrote:
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> hw/ppc/spapr_caps.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
> index 2773f9db9e..655ab856a0 100644
> --- a/hw/ppc/spapr_caps.c
> +++ b/hw/ppc/spapr_caps.c
> @@ -930,16 +930,13 @@ void spapr_caps_add_properties(SpaprMachineClass *smc)
>
> for (i = 0; i < ARRAY_SIZE(capability_table); i++) {
> SpaprCapabilityInfo *cap = &capability_table[i];
> - char *name = g_strdup_printf("cap-%s", cap->name);
> - char *desc;
> + g_autofree char *name = g_strdup_printf("cap-%s", cap->name);
> + g_autofree char *desc = g_strdup_printf("%s", cap->description);
>
> object_class_property_add(klass, name, cap->type,
> cap->get, cap->set,
> NULL, cap);
>
> - desc = g_strdup_printf("%s", cap->description);
> object_class_property_set_description(klass, name, desc);
> - g_free(name);
> - g_free(desc);
> }
> }
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2022-03-01 3:49 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen() Daniel Henrique Barboza
2022-03-01 0:58 ` David Gibson
2022-02-28 17:49 ` [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init() Daniel Henrique Barboza
2022-02-28 19:28 ` BALATON Zoltan
2022-03-01 2:24 ` David Gibson
2022-02-28 17:49 ` [PATCH 03/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string() Daniel Henrique Barboza
2022-03-01 3:14 ` David Gibson
2022-02-28 17:49 ` [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string() Daniel Henrique Barboza
2022-03-01 3:15 ` David Gibson
2022-02-28 17:49 ` [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties() Daniel Henrique Barboza
2022-03-01 3:15 ` David Gibson
2022-02-28 17:49 ` [PATCH 06/14] hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc() Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 07/14] hw/ppc/spapr_drc.c: use g_autofree in drc_realize() Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 08/14] hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize() Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 09/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 10/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 12/14] spapr_pci_nvlink2.c: use g_autofree in spapr_phb_nvgpu_ram_populate_dt() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 13/14] hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 14/14] hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice() Daniel Henrique Barboza
2022-02-28 18:13 ` [PATCH 00/14] simple cleanups in spapr files Philippe Mathieu-Daudé
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).