qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: qemu-devel@nongnu.org
Cc: Daniel Henrique Barboza <danielhb413@gmail.com>,
	qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au
Subject: [PATCH 06/14] hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc()
Date: Mon, 28 Feb 2022 14:49:56 -0300	[thread overview]
Message-ID: <20220228175004.8862-7-danielhb413@gmail.com> (raw)
In-Reply-To: <20220228175004.8862-1-danielhb413@gmail.com>

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



  parent reply	other threads:[~2022-02-28 17:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Daniel Henrique Barboza [this message]
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é

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=20220228175004.8862-7-danielhb413@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.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).