[libvirt PATCH 00/15] Use g_auto* in src/cpu/*.

Mostly mechanical changes, the most "interesting" patches are the first (wher= e should the `G_DEFINE_AUTOPTR_CLEANUP_FUN` go?) and the last (removing call to `g_str= freev`, as it should not be necessary). As an added benefit, this removes all `goto` usage in this directory. Tim Wiederhake (15): cpu_map: Use g_auto* in loadData cpu_map: Use g_auto* in cpuMapLoadInclude cpu_map: Use g_auto* in loadIncludes cpu: Use g_auto* in virCPUCompareXML cpu: Use g_auto* in virCPUGetHost cpu_ppc64: Turn structs ppc64_{vendor,model,map} into typedefs cpu_ppc64: Use g_auto* in ppc64ModelCopy cpu_ppc64: Use g_auto* in ppc64VendorParse cpu_ppc64: Use g_auto* in ppc64ModelParse cpu_ppc64: Use g_auto* in ppc64LoadMap cpu_ppc64: Use g_auto* in ppc64Compute cpu_ppc64: Use g_auto* in ppc64DriverDecode cpu_ppc64: Use g_auto* in virCPUppc64GetHost cpu_ppc64: Use g_auto* in virCPUppc64Baseline cpu_ppc64: Use g_auto* in virCPUppc64DriverGetModels src/cpu/cpu.c | 31 ++---- src/cpu/cpu_map.c | 60 ++++------ src/cpu/cpu_ppc64.c | 260 +++++++++++++++++--------------------------- 3 files changed, 133 insertions(+), 218 deletions(-) --=20 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index cbf90d1395..c315ab32b2 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -32,6 +32,8 @@ VIR_LOG_INIT("cpu.cpu_map"); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlNodePtr, g_free); + static int loadData(const char *mapfile, xmlXPathContextPtr ctxt, @@ -39,20 +41,19 @@ loadData(const char *mapfile, cpuMapLoadCallback callback, void *data) { - int ret = -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes = NULL; + g_autoptr(xmlNodePtr) nodes = NULL; int n; size_t i; int rv; if ((n = virXPathNodeSet(element, ctxt, &nodes)) < 0) - goto cleanup; + return -1; if (n > 0 && !callback) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected element '%s' in CPU map '%s'"), element, mapfile); - goto cleanup; + return -1; } for (i = 0; i < n; i++) { @@ -60,22 +61,17 @@ loadData(const char *mapfile, if (!name) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find %s name in CPU map '%s'"), element, mapfile); - goto cleanup; + return -1; } VIR_DEBUG("Load %s name %s", element, name); ctxt->node = nodes[i]; rv = callback(ctxt, name, data); VIR_FREE(name); if (rv < 0) - goto cleanup; + return -1; } - ret = 0; - - cleanup: - VIR_FREE(nodes); - - return ret; + return 0; } static int -- 2.26.2

On a Monday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index cbf90d1395..c315ab32b2 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -32,6 +32,8 @@
VIR_LOG_INIT("cpu.cpu_map");
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlNodePtr, g_free); +
To answer the question from the cover letter: For internal types, we put the G_DEFINE_AUTO in the header files introducing the particular type. For types from external libraries (like libxml2), we put them into the header file with our wrappers over it. For public libvirt types, IIRC we only have defined the cleanup functions privately in virsh (tools/virsh-util.h) And this one does not need the define, we simply use g_autofree for types that are freed by g_free. Jano
static int loadData(const char *mapfile, xmlXPathContextPtr ctxt, @@ -39,20 +41,19 @@ loadData(const char *mapfile, cpuMapLoadCallback callback, void *data) { - int ret = -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes = NULL; + g_autoptr(xmlNodePtr) nodes = NULL; int n; size_t i; int rv;
if ((n = virXPathNodeSet(element, ctxt, &nodes)) < 0) - goto cleanup; + return -1;
if (n > 0 && !callback) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected element '%s' in CPU map '%s'"), element, mapfile); - goto cleanup; + return -1; }
for (i = 0; i < n; i++) { @@ -60,22 +61,17 @@ loadData(const char *mapfile, if (!name) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find %s name in CPU map '%s'"), element, mapfile); - goto cleanup; + return -1; } VIR_DEBUG("Load %s name %s", element, name); ctxt->node = nodes[i]; rv = callback(ctxt, name, data); VIR_FREE(name); if (rv < 0) - goto cleanup; + return -1; }
- ret = 0; - - cleanup: - VIR_FREE(nodes); - - return ret; + return 0; }
static int -- 2.26.2

Hi Ján! Am Montag, den 07.09.2020, 17:10 +0200 schrieb Ján Tomko:
On a Monday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index cbf90d1395..c315ab32b2 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -32,6 +32,8 @@
VIR_LOG_INIT("cpu.cpu_map");
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlNodePtr, g_free); +
To answer the question from the cover letter:
For internal types, we put the G_DEFINE_AUTO in the header files introducing the particular type.
For types from external libraries (like libxml2), we put them into the header file with our wrappers over it.
For public libvirt types, IIRC we only have defined the cleanup functions privately in virsh (tools/virsh-util.h)
And this one does not need the define, we simply use g_autofree for types that are freed by g_free.
Jano
Thanks for the explanation! And you are absolutely right about the define. I did use g_autofree in a later patch, so I cannot really tell why I thought the define was necessary here. Fixed (locally). Tim
static int loadData(const char *mapfile, xmlXPathContextPtr ctxt, @@ -39,20 +41,19 @@ loadData(const char *mapfile, cpuMapLoadCallback callback, void *data) { - int ret = -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes = NULL; + g_autoptr(xmlNodePtr) nodes = NULL; int n; size_t i; int rv;
if ((n = virXPathNodeSet(element, ctxt, &nodes)) < 0) - goto cleanup; + return -1;
if (n > 0 && !callback) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected element '%s' in CPU map '%s'"), element, mapfile); - goto cleanup; + return -1; }
for (i = 0; i < n; i++) { @@ -60,22 +61,17 @@ loadData(const char *mapfile, if (!name) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find %s name in CPU map '%s'"), element, mapfile); - goto cleanup; + return -1; } VIR_DEBUG("Load %s name %s", element, name); ctxt->node = nodes[i]; rv = callback(ctxt, name, data); VIR_FREE(name); if (rv < 0) - goto cleanup; + return -1; }
- ret = 0; - - cleanup: - VIR_FREE(nodes); - - return ret; + return 0; }
static int -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index c315ab32b2..1b73249649 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -81,10 +81,9 @@ cpuMapLoadInclude(const char *filename, cpuMapLoadCallback modelCB, void *data) { - xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; - int ret = -1; - char *mapfile; + g_autoptr(xmlDoc) xml = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; + g_autofree char *mapfile = NULL; if (!(mapfile = virFileFindResource(filename, abs_top_srcdir "/src/cpu_map", @@ -94,27 +93,20 @@ cpuMapLoadInclude(const char *filename, VIR_DEBUG("Loading CPU map include from %s", mapfile); if (!(xml = virXMLParseFileCtxt(mapfile, &ctxt))) - goto cleanup; + return -1; ctxt->node = xmlDocGetRootElement(xml); if (loadData(mapfile, ctxt, "vendor", vendorCB, data) < 0) - goto cleanup; + return -1; if (loadData(mapfile, ctxt, "feature", featureCB, data) < 0) - goto cleanup; + return -1; if (loadData(mapfile, ctxt, "model", modelCB, data) < 0) - goto cleanup; - - ret = 0; - - cleanup: - xmlXPathFreeContext(ctxt); - xmlFreeDoc(xml); - VIR_FREE(mapfile); + return -1; - return ret; + return 0; } -- 2.26.2

On a Monday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index 1b73249649..372c00a1cd 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -117,37 +117,31 @@ loadIncludes(xmlXPathContextPtr ctxt, cpuMapLoadCallback modelCB, void *data) { - int ret = -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes = NULL; + g_autofree xmlNodePtr *nodes = NULL; int n; size_t i; n = virXPathNodeSet("include", ctxt, &nodes); if (n < 0) - goto cleanup; + return -1; for (i = 0; i < n; i++) { char *filename = virXMLPropString(nodes[i], "filename"); if (!filename) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing 'filename' in CPU map include")); - goto cleanup; + return -1; } VIR_DEBUG("Finding CPU map include '%s'", filename); if (cpuMapLoadInclude(filename, vendorCB, featureCB, modelCB, data) < 0) { VIR_FREE(filename); - goto cleanup; + return -1; } VIR_FREE(filename); } - ret = 0; - - cleanup: - VIR_FREE(nodes); - - return ret; + return 0; } -- 2.26.2

On a Monday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index d502c02f51..a84eb10cc4 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -111,21 +111,15 @@ virCPUCompareXML(virArch arch, const char *xml, bool failIncompatible) { - virCPUDefPtr cpu = NULL; - virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; + g_autoptr(virCPUDef) cpu = NULL; VIR_DEBUG("arch=%s, host=%p, xml=%s", virArchToString(arch), host, NULLSTR(xml)); if (virCPUDefParseXMLString(xml, VIR_CPU_TYPE_AUTO, &cpu) < 0) - goto cleanup; - - ret = virCPUCompare(arch, host, cpu, failIncompatible); - - cleanup: - virCPUDefFree(cpu); + return VIR_CPU_COMPARE_ERROR; - return ret; + return virCPUCompare(arch, host, cpu, failIncompatible); } -- 2.26.2

On a Monday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index a84eb10cc4..69e4205e4b 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -378,7 +378,7 @@ virCPUGetHost(virArch arch, virDomainCapsCPUModelsPtr models) { struct cpuArchDriver *driver; - virCPUDefPtr cpu = NULL; + g_autoptr(virCPUDef) cpu = NULL; VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p, models=%p", virArchToString(arch), virCPUTypeToString(type), nodeInfo, @@ -400,7 +400,7 @@ virCPUGetHost(virArch arch, virReportError(VIR_ERR_INVALID_ARG, _("cannot set topology for CPU type '%s'"), virCPUTypeToString(type)); - goto error; + return NULL; } cpu->type = type; break; @@ -410,7 +410,7 @@ virCPUGetHost(virArch arch, virReportError(VIR_ERR_INVALID_ARG, _("unsupported CPU type: %s"), virCPUTypeToString(type)); - goto error; + return NULL; } if (nodeInfo) { @@ -424,9 +424,8 @@ virCPUGetHost(virArch arch, * filled in. */ if (driver->getHost) { - if (driver->getHost(cpu, models) < 0 && - !nodeInfo) - goto error; + if (driver->getHost(cpu, models) < 0 && !nodeInfo) + return NULL; } else if (nodeInfo) { VIR_DEBUG("cannot detect host CPU model for %s architecture", virArchToString(arch)); @@ -434,14 +433,10 @@ virCPUGetHost(virArch arch, virReportError(VIR_ERR_NO_SUPPORT, _("cannot detect host CPU model for %s architecture"), virArchToString(arch)); - goto error; + return NULL; } - return cpu; - - error: - virCPUDefFree(cpu); - return NULL; + return g_steal_pointer(&cpu); } -- 2.26.2

On a Monday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> And I went ahead and pushed patches 2~5, since they do not conflict with the cleanups posted earlier by Daniel. Jano

This enables us to use g_auto* macros on those types. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 91 +++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 5b34c00a18..c7860cb1b4 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -34,22 +34,31 @@ VIR_LOG_INIT("cpu.cpu_ppc64"); static const virArch archs[] = { VIR_ARCH_PPC64, VIR_ARCH_PPC64LE }; -struct ppc64_vendor { +typedef struct { char *name; -}; +} ppc64_vendor; + +static void ppc64VendorFree(ppc64_vendor *vendor); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(ppc64_vendor, ppc64VendorFree); -struct ppc64_model { +typedef struct { char *name; - const struct ppc64_vendor *vendor; + const ppc64_vendor *vendor; virCPUppc64Data data; -}; +} ppc64_model; -struct ppc64_map { +static void ppc64ModelFree(ppc64_model *model); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(ppc64_model, ppc64ModelFree); + +typedef struct { size_t nvendors; - struct ppc64_vendor **vendors; + ppc64_vendor **vendors; size_t nmodels; - struct ppc64_model **models; -}; + ppc64_model **models; +} ppc64_map; + +static void ppc64MapFree(ppc64_map *map); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(ppc64_map, ppc64MapFree); /* Convert a legacy CPU definition by transforming * model names to generation names: @@ -142,7 +151,7 @@ ppc64DataCopy(virCPUppc64Data *dst, const virCPUppc64Data *src) } static void -ppc64VendorFree(struct ppc64_vendor *vendor) +ppc64VendorFree(ppc64_vendor *vendor) { if (!vendor) return; @@ -151,8 +160,8 @@ ppc64VendorFree(struct ppc64_vendor *vendor) VIR_FREE(vendor); } -static struct ppc64_vendor * -ppc64VendorFind(const struct ppc64_map *map, +static ppc64_vendor * +ppc64VendorFind(const ppc64_map *map, const char *name) { size_t i; @@ -166,7 +175,7 @@ ppc64VendorFind(const struct ppc64_map *map, } static void -ppc64ModelFree(struct ppc64_model *model) +ppc64ModelFree(ppc64_model *model) { if (!model) return; @@ -176,10 +185,10 @@ ppc64ModelFree(struct ppc64_model *model) VIR_FREE(model); } -static struct ppc64_model * -ppc64ModelCopy(const struct ppc64_model *model) +static ppc64_model * +ppc64ModelCopy(const ppc64_model *model) { - struct ppc64_model *copy; + ppc64_model *copy; if (VIR_ALLOC(copy) < 0) goto error; @@ -198,8 +207,8 @@ ppc64ModelCopy(const struct ppc64_model *model) return NULL; } -static struct ppc64_model * -ppc64ModelFind(const struct ppc64_map *map, +static ppc64_model * +ppc64ModelFind(const ppc64_map *map, const char *name) { size_t i; @@ -212,15 +221,15 @@ ppc64ModelFind(const struct ppc64_map *map, return NULL; } -static struct ppc64_model * -ppc64ModelFindPVR(const struct ppc64_map *map, +static ppc64_model * +ppc64ModelFindPVR(const ppc64_map *map, uint32_t pvr) { size_t i; size_t j; for (i = 0; i < map->nmodels; i++) { - struct ppc64_model *model = map->models[i]; + ppc64_model *model = map->models[i]; for (j = 0; j < model->data.len; j++) { if ((pvr & model->data.pvr[j].mask) == model->data.pvr[j].value) return model; @@ -230,11 +239,11 @@ ppc64ModelFindPVR(const struct ppc64_map *map, return NULL; } -static struct ppc64_model * +static ppc64_model * ppc64ModelFromCPU(const virCPUDef *cpu, - const struct ppc64_map *map) + const ppc64_map *map) { - struct ppc64_model *model; + ppc64_model *model; if (!cpu->model) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -252,7 +261,7 @@ ppc64ModelFromCPU(const virCPUDef *cpu, } static void -ppc64MapFree(struct ppc64_map *map) +ppc64MapFree(ppc64_map *map) { size_t i; @@ -275,8 +284,8 @@ ppc64VendorParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED, const char *name, void *data) { - struct ppc64_map *map = data; - struct ppc64_vendor *vendor; + ppc64_map *map = data; + ppc64_vendor *vendor; int ret = -1; if (VIR_ALLOC(vendor) < 0) @@ -306,8 +315,8 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, const char *name, void *data) { - struct ppc64_map *map = data; - struct ppc64_model *model; + ppc64_map *map = data; + ppc64_model *model; xmlNodePtr *nodes = NULL; char *vendor = NULL; unsigned long pvr; @@ -388,10 +397,10 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, } -static struct ppc64_map * +static ppc64_map * ppc64LoadMap(void) { - struct ppc64_map *map; + ppc64_map *map; if (VIR_ALLOC(map) < 0) goto error; @@ -429,9 +438,9 @@ ppc64Compute(virCPUDefPtr host, virCPUDataPtr *guestData, char **message) { - struct ppc64_map *map = NULL; - struct ppc64_model *host_model = NULL; - struct ppc64_model *guest_model = NULL; + ppc64_map *map = NULL; + ppc64_model *host_model = NULL; + ppc64_model *guest_model = NULL; virCPUDefPtr cpu = NULL; virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; virArch arch; @@ -589,8 +598,8 @@ ppc64DriverDecode(virCPUDefPtr cpu, virDomainCapsCPUModelsPtr models) { int ret = -1; - struct ppc64_map *map; - const struct ppc64_model *model; + ppc64_map *map; + const ppc64_model *model; if (!data || !(map = ppc64LoadMap())) return -1; @@ -689,9 +698,9 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, const char **features G_GNUC_UNUSED, bool migratable G_GNUC_UNUSED) { - struct ppc64_map *map; - const struct ppc64_model *model; - const struct ppc64_vendor *vendor = NULL; + ppc64_map *map; + const ppc64_model *model; + const ppc64_vendor *vendor = NULL; virCPUDefPtr cpu = NULL; size_t i; @@ -705,7 +714,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, } for (i = 0; i < ncpus; i++) { - const struct ppc64_vendor *vnd; + const ppc64_vendor *vnd; /* Hosts running old (<= 1.2.18) versions of libvirt will report * strings like 'power7+' or 'power8e' instead of proper CPU model @@ -778,7 +787,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, static int virCPUppc64DriverGetModels(char ***models) { - struct ppc64_map *map; + ppc64_map *map; size_t i; int ret = -1; -- 2.26.2

On 9/7/20 10:58 AM, Tim Wiederhake wrote:
This enables us to use g_auto* macros on those types.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 91 +++++++++++++++++++++++++--------------------
danielhb had sent similar patches for this file last week, which I had planned to review, but didn't get around to before the weekend: https://www.redhat.com/archives/libvir-list/2020-September/msg00124.html
1 file changed, 50 insertions(+), 41 deletions(-)
diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 5b34c00a18..c7860cb1b4 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -34,22 +34,31 @@ VIR_LOG_INIT("cpu.cpu_ppc64");
static const virArch archs[] = { VIR_ARCH_PPC64, VIR_ARCH_PPC64LE };
-struct ppc64_vendor { +typedef struct { char *name; -}; +} ppc64_vendor; + +static void ppc64VendorFree(ppc64_vendor *vendor); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(ppc64_vendor, ppc64VendorFree);
-struct ppc64_model { +typedef struct { char *name; - const struct ppc64_vendor *vendor; + const ppc64_vendor *vendor; virCPUppc64Data data; -}; +} ppc64_model;
-struct ppc64_map { +static void ppc64ModelFree(ppc64_model *model); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(ppc64_model, ppc64ModelFree); + +typedef struct { size_t nvendors; - struct ppc64_vendor **vendors; + ppc64_vendor **vendors; size_t nmodels; - struct ppc64_model **models; -}; + ppc64_model **models; +} ppc64_map; + +static void ppc64MapFree(ppc64_map *map); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(ppc64_map, ppc64MapFree);
/* Convert a legacy CPU definition by transforming * model names to generation names: @@ -142,7 +151,7 @@ ppc64DataCopy(virCPUppc64Data *dst, const virCPUppc64Data *src) }
static void -ppc64VendorFree(struct ppc64_vendor *vendor) +ppc64VendorFree(ppc64_vendor *vendor) { if (!vendor) return; @@ -151,8 +160,8 @@ ppc64VendorFree(struct ppc64_vendor *vendor) VIR_FREE(vendor); }
-static struct ppc64_vendor * -ppc64VendorFind(const struct ppc64_map *map, +static ppc64_vendor * +ppc64VendorFind(const ppc64_map *map, const char *name) { size_t i; @@ -166,7 +175,7 @@ ppc64VendorFind(const struct ppc64_map *map, }
static void -ppc64ModelFree(struct ppc64_model *model) +ppc64ModelFree(ppc64_model *model) { if (!model) return; @@ -176,10 +185,10 @@ ppc64ModelFree(struct ppc64_model *model) VIR_FREE(model); }
-static struct ppc64_model * -ppc64ModelCopy(const struct ppc64_model *model) +static ppc64_model * +ppc64ModelCopy(const ppc64_model *model) { - struct ppc64_model *copy; + ppc64_model *copy;
if (VIR_ALLOC(copy) < 0) goto error; @@ -198,8 +207,8 @@ ppc64ModelCopy(const struct ppc64_model *model) return NULL; }
-static struct ppc64_model * -ppc64ModelFind(const struct ppc64_map *map, +static ppc64_model * +ppc64ModelFind(const ppc64_map *map, const char *name) { size_t i; @@ -212,15 +221,15 @@ ppc64ModelFind(const struct ppc64_map *map, return NULL; }
-static struct ppc64_model * -ppc64ModelFindPVR(const struct ppc64_map *map, +static ppc64_model * +ppc64ModelFindPVR(const ppc64_map *map, uint32_t pvr) { size_t i; size_t j;
for (i = 0; i < map->nmodels; i++) { - struct ppc64_model *model = map->models[i]; + ppc64_model *model = map->models[i]; for (j = 0; j < model->data.len; j++) { if ((pvr & model->data.pvr[j].mask) == model->data.pvr[j].value) return model; @@ -230,11 +239,11 @@ ppc64ModelFindPVR(const struct ppc64_map *map, return NULL; }
-static struct ppc64_model * +static ppc64_model * ppc64ModelFromCPU(const virCPUDef *cpu, - const struct ppc64_map *map) + const ppc64_map *map) { - struct ppc64_model *model; + ppc64_model *model;
if (!cpu->model) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -252,7 +261,7 @@ ppc64ModelFromCPU(const virCPUDef *cpu, }
static void -ppc64MapFree(struct ppc64_map *map) +ppc64MapFree(ppc64_map *map) { size_t i;
@@ -275,8 +284,8 @@ ppc64VendorParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED, const char *name, void *data) { - struct ppc64_map *map = data; - struct ppc64_vendor *vendor; + ppc64_map *map = data; + ppc64_vendor *vendor; int ret = -1;
if (VIR_ALLOC(vendor) < 0) @@ -306,8 +315,8 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, const char *name, void *data) { - struct ppc64_map *map = data; - struct ppc64_model *model; + ppc64_map *map = data; + ppc64_model *model; xmlNodePtr *nodes = NULL; char *vendor = NULL; unsigned long pvr; @@ -388,10 +397,10 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, }
-static struct ppc64_map * +static ppc64_map * ppc64LoadMap(void) { - struct ppc64_map *map; + ppc64_map *map;
if (VIR_ALLOC(map) < 0) goto error; @@ -429,9 +438,9 @@ ppc64Compute(virCPUDefPtr host, virCPUDataPtr *guestData, char **message) { - struct ppc64_map *map = NULL; - struct ppc64_model *host_model = NULL; - struct ppc64_model *guest_model = NULL; + ppc64_map *map = NULL; + ppc64_model *host_model = NULL; + ppc64_model *guest_model = NULL; virCPUDefPtr cpu = NULL; virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; virArch arch; @@ -589,8 +598,8 @@ ppc64DriverDecode(virCPUDefPtr cpu, virDomainCapsCPUModelsPtr models) { int ret = -1; - struct ppc64_map *map; - const struct ppc64_model *model; + ppc64_map *map; + const ppc64_model *model;
if (!data || !(map = ppc64LoadMap())) return -1; @@ -689,9 +698,9 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, const char **features G_GNUC_UNUSED, bool migratable G_GNUC_UNUSED) { - struct ppc64_map *map; - const struct ppc64_model *model; - const struct ppc64_vendor *vendor = NULL; + ppc64_map *map; + const ppc64_model *model; + const ppc64_vendor *vendor = NULL; virCPUDefPtr cpu = NULL; size_t i;
@@ -705,7 +714,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, }
for (i = 0; i < ncpus; i++) { - const struct ppc64_vendor *vnd; + const ppc64_vendor *vnd;
/* Hosts running old (<= 1.2.18) versions of libvirt will report * strings like 'power7+' or 'power8e' instead of proper CPU model @@ -778,7 +787,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, static int virCPUppc64DriverGetModels(char ***models) { - struct ppc64_map *map; + ppc64_map *map; size_t i; int ret = -1;

Am Montag, den 07.09.2020, 12:03 -0400 schrieb Laine Stump:
danielhb had sent similar patches for this file last week, which I had planned to review, but didn't get around to before the weekend:
https://www.redhat.com/archives/libvir-list/2020-September/msg00124.html
Thank you for pointing this out! These patches were sent before I joined the list, and I was not aware of them. I will wait until Daniel's patches are in and redo my patches on top of that. Regards, Tim

On a Tuesday in 2020, Tim Wiederhake wrote:
Am Montag, den 07.09.2020, 12:03 -0400 schrieb Laine Stump:
danielhb had sent similar patches for this file last week, which I had planned to review, but didn't get around to before the weekend:
https://www.redhat.com/archives/libvir-list/2020-September/msg00124.html
Thank you for pointing this out! These patches were sent before I joined the list, and I was not aware of them. I will wait until Daniel's patches are in and redo my patches on top of that.
I went through Daniel's patches and pushed those because his typedefs had the 'vir' prefix. Can you resend patch 1/15 with your local fix and a rebased version of 15/15? That g_strfreev removal was the only difference (apart from naming and splitting into commits) Jano

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index c7860cb1b4..9eaf9c6ae5 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -188,23 +188,19 @@ ppc64ModelFree(ppc64_model *model) static ppc64_model * ppc64ModelCopy(const ppc64_model *model) { - ppc64_model *copy; + g_autoptr(ppc64_model) copy = NULL; if (VIR_ALLOC(copy) < 0) - goto error; + return NULL; copy->name = g_strdup(model->name); if (ppc64DataCopy(©->data, &model->data) < 0) - goto error; + return NULL; copy->vendor = model->vendor; - return copy; - - error: - ppc64ModelFree(copy); - return NULL; + return g_steal_pointer(©); } static ppc64_model * -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 9eaf9c6ae5..81c3ce8319 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -281,8 +281,7 @@ ppc64VendorParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED, void *data) { ppc64_map *map = data; - ppc64_vendor *vendor; - int ret = -1; + g_autoptr(ppc64_vendor) vendor = NULL; if (VIR_ALLOC(vendor) < 0) return -1; @@ -292,17 +291,13 @@ ppc64VendorParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED, if (ppc64VendorFind(map, vendor->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("CPU vendor %s already defined"), vendor->name); - goto cleanup; + return -1; } if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0) - goto cleanup; - - ret = 0; + return -1; - cleanup: - ppc64VendorFree(vendor); - return ret; + return 0; } -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 81c3ce8319..44420c9cd5 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -307,23 +307,22 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, void *data) { ppc64_map *map = data; - ppc64_model *model; - xmlNodePtr *nodes = NULL; - char *vendor = NULL; + g_autoptr(ppc64_model) model = NULL; + g_autofree xmlNodePtr *nodes = NULL; + g_autofree char *vendor = NULL; unsigned long pvr; size_t i; int n; - int ret = -1; if (VIR_ALLOC(model) < 0) - goto cleanup; + return -1; model->name = g_strdup(name); if (ppc64ModelFind(map, model->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("CPU model %s already defined"), model->name); - goto cleanup; + return -1; } if (virXPathBoolean("boolean(./vendor)", ctxt)) { @@ -332,14 +331,14 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid vendor element in CPU model %s"), model->name); - goto cleanup; + return -1; } if (!(model->vendor = ppc64VendorFind(map, vendor))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown vendor %s referenced by CPU model %s"), vendor, model->name); - goto cleanup; + return -1; } } @@ -347,11 +346,11 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing PVR information for CPU model %s"), model->name); - goto cleanup; + return -1; } if (VIR_ALLOC_N(model->data.pvr, n) < 0) - goto cleanup; + return -1; model->data.len = n; @@ -362,7 +361,7 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing or invalid PVR value in CPU model %s"), model->name); - goto cleanup; + return -1; } model->data.pvr[i].value = pvr; @@ -370,21 +369,15 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing or invalid PVR mask in CPU model %s"), model->name); - goto cleanup; + return -1; } model->data.pvr[i].mask = pvr; } if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0) - goto cleanup; - - ret = 0; + return -1; - cleanup: - ppc64ModelFree(model); - VIR_FREE(vendor); - VIR_FREE(nodes); - return ret; + return 0; } -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 44420c9cd5..7b34fe6bbc 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -384,19 +384,15 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, static ppc64_map * ppc64LoadMap(void) { - ppc64_map *map; + g_autoptr(ppc64_map) map = NULL; if (VIR_ALLOC(map) < 0) - goto error; + return NULL; if (cpuMapLoad("ppc64", ppc64VendorParse, NULL, ppc64ModelParse, map) < 0) - goto error; - - return map; + return NULL; - error: - ppc64MapFree(map); - return NULL; + return g_steal_pointer(&map); } static virCPUDataPtr -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 46 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 7b34fe6bbc..aef1418872 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -418,18 +418,16 @@ ppc64Compute(virCPUDefPtr host, virCPUDataPtr *guestData, char **message) { - ppc64_map *map = NULL; - ppc64_model *host_model = NULL; - ppc64_model *guest_model = NULL; - virCPUDefPtr cpu = NULL; - virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; + g_autoptr(ppc64_map) map = NULL; + g_autoptr(ppc64_model) host_model = NULL; + g_autoptr(ppc64_model) guest_model = NULL; + g_autoptr(virCPUDef) cpu = NULL; virArch arch; size_t i; /* Ensure existing configurations are handled correctly */ - if (!(cpu = virCPUDefCopy(other)) || - virCPUppc64ConvertLegacy(cpu) < 0) - goto cleanup; + if (!(cpu = virCPUDefCopy(other)) || virCPUppc64ConvertLegacy(cpu) < 0) + return VIR_CPU_COMPARE_ERROR; if (cpu->arch != VIR_ARCH_NONE) { bool found = false; @@ -448,8 +446,7 @@ ppc64Compute(virCPUDefPtr host, *message = g_strdup_printf(_("CPU arch %s does not match host arch"), virArchToString(cpu->arch)); - ret = VIR_CPU_COMPARE_INCOMPATIBLE; - goto cleanup; + return VIR_CPU_COMPARE_INCOMPATIBLE; } arch = cpu->arch; } else { @@ -466,16 +463,15 @@ ppc64Compute(virCPUDefPtr host, cpu->vendor); } - ret = VIR_CPU_COMPARE_INCOMPATIBLE; - goto cleanup; + return VIR_CPU_COMPARE_INCOMPATIBLE; } if (!(map = ppc64LoadMap())) - goto cleanup; + return VIR_CPU_COMPARE_ERROR; /* Host CPU information */ if (!(host_model = ppc64ModelFromCPU(host, map))) - goto cleanup; + return VIR_CPU_COMPARE_ERROR; if (cpu->type == VIR_CPU_TYPE_GUEST) { /* Guest CPU information */ @@ -485,10 +481,8 @@ ppc64Compute(virCPUDefPtr host, /* host-model only: * we need to take compatibility modes into account */ tmp = ppc64CheckCompatibilityMode(host->model, cpu->model); - if (tmp != VIR_CPU_COMPARE_IDENTICAL) { - ret = tmp; - goto cleanup; - } + if (tmp != VIR_CPU_COMPARE_IDENTICAL) + return tmp; G_GNUC_FALLTHROUGH; case VIR_CPU_MODE_HOST_PASSTHROUGH: @@ -509,7 +503,7 @@ ppc64Compute(virCPUDefPtr host, } if (!guest_model) - goto cleanup; + return VIR_CPU_COMPARE_ERROR; if (STRNEQ(guest_model->name, host_model->name)) { VIR_DEBUG("host CPU model does not match required CPU model %s", @@ -520,22 +514,14 @@ ppc64Compute(virCPUDefPtr host, guest_model->name); } - ret = VIR_CPU_COMPARE_INCOMPATIBLE; - goto cleanup; + return VIR_CPU_COMPARE_INCOMPATIBLE; } if (guestData) if (!(*guestData = ppc64MakeCPUData(arch, &guest_model->data))) - goto cleanup; - - ret = VIR_CPU_COMPARE_IDENTICAL; + return VIR_CPU_COMPARE_ERROR; - cleanup: - virCPUDefFree(cpu); - ppc64MapFree(map); - ppc64ModelFree(host_model); - ppc64ModelFree(guest_model); - return ret; + return VIR_CPU_COMPARE_IDENTICAL; } static virCPUCompareResult -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index aef1418872..d7ccd506fb 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -563,8 +563,7 @@ ppc64DriverDecode(virCPUDefPtr cpu, const virCPUData *data, virDomainCapsCPUModelsPtr models) { - int ret = -1; - ppc64_map *map; + g_autoptr(ppc64_map) map = NULL; const ppc64_model *model; if (!data || !(map = ppc64LoadMap())) @@ -574,26 +573,21 @@ ppc64DriverDecode(virCPUDefPtr cpu, virReportError(VIR_ERR_OPERATION_FAILED, _("Cannot find CPU model with PVR 0x%08x"), data->data.ppc64.pvr[0].value); - goto cleanup; + return -1; } if (!virCPUModelIsAllowed(model->name, models)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("CPU model %s is not supported by hypervisor"), model->name); - goto cleanup; + return -1; } cpu->model = g_strdup(model->name); if (model->vendor) cpu->vendor = g_strdup(model->vendor->name); - ret = 0; - - cleanup: - ppc64MapFree(map); - - return ret; + return 0; } static void -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index d7ccd506fb..30dd5a48c5 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -605,17 +605,16 @@ static int virCPUppc64GetHost(virCPUDefPtr cpu, virDomainCapsCPUModelsPtr models) { - virCPUDataPtr cpuData = NULL; + g_autoptr(virCPUData) cpuData = NULL; virCPUppc64Data *data; - int ret = -1; if (!(cpuData = virCPUDataNew(archs[0]))) - goto cleanup; + return -1; data = &cpuData->data.ppc64; if (VIR_ALLOC_N(data->pvr, 1) < 0) - goto cleanup; + return -1; data->len = 1; @@ -625,11 +624,7 @@ virCPUppc64GetHost(virCPUDefPtr cpu, #endif data->pvr[0].mask = 0xfffffffful; - ret = ppc64DriverDecode(cpu, cpuData, models); - - cleanup: - virCPUppc64DataFree(cpuData); - return ret; + return ppc64DriverDecode(cpu, cpuData, models); } -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 30dd5a48c5..db59f5adbf 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -653,19 +653,19 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, const char **features G_GNUC_UNUSED, bool migratable G_GNUC_UNUSED) { - ppc64_map *map; + g_autoptr(ppc64_map) map = NULL; const ppc64_model *model; const ppc64_vendor *vendor = NULL; - virCPUDefPtr cpu = NULL; + g_autoptr(virCPUDef) cpu = NULL; size_t i; if (!(map = ppc64LoadMap())) - goto error; + return NULL; if (!(model = ppc64ModelFind(map, cpus[0]->model))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown CPU model %s"), cpus[0]->model); - goto error; + return NULL; } for (i = 0; i < ncpus; i++) { @@ -685,7 +685,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, if (STRNEQ(cpus[i]->model, model->name)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("CPUs are incompatible")); - goto error; + return NULL; } if (!cpus[i]->vendor) @@ -694,7 +694,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, if (!(vnd = ppc64VendorFind(map, cpus[i]->vendor))) { virReportError(VIR_ERR_OPERATION_FAILED, _("Unknown CPU vendor %s"), cpus[i]->vendor); - goto error; + return NULL; } if (model->vendor) { @@ -704,13 +704,13 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, "vendor %s"), model->vendor->name, model->name, vnd->name); - goto error; + return NULL; } } else if (vendor) { if (vendor != vnd) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("CPU vendors do not match")); - goto error; + return NULL; } } else { vendor = vnd; @@ -728,15 +728,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, cpu->match = VIR_CPU_MATCH_EXACT; cpu->fallback = VIR_CPU_FALLBACK_FORBID; - cleanup: - ppc64MapFree(map); - - return cpu; - - error: - virCPUDefFree(cpu); - cpu = NULL; - goto cleanup; + return g_steal_pointer(&cpu); } static int -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index db59f5adbf..860e959900 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -734,33 +734,21 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, static int virCPUppc64DriverGetModels(char ***models) { - ppc64_map *map; + g_autoptr(ppc64_map) map = NULL; size_t i; - int ret = -1; if (!(map = ppc64LoadMap())) - goto error; + return -1; if (models) { if (VIR_ALLOC_N(*models, map->nmodels + 1) < 0) - goto error; + return -1; for (i = 0; i < map->nmodels; i++) (*models)[i] = g_strdup(map->models[i]->name); } - ret = map->nmodels; - - cleanup: - ppc64MapFree(map); - return ret; - - error: - if (models) { - g_strfreev(*models); - *models = NULL; - } - goto cleanup; + return map->nmodels; } struct cpuArchDriver cpuDriverPPC64 = { -- 2.26.2
participants (3)
-
Ján Tomko
-
Laine Stump
-
Tim Wiederhake