[libvirt PATCH v2 0/2] Use g_auto* in src/cpu/*.

V1: https://www.redhat.com/archives/libvir-list/2020-September/msg00355.html Changes since V1: * Most patches already commited, this is the remainder. * Incorporated comment from Ján into patch #1. * Rebased on top of Daniels patches. With these patches, src/cpu/ becomes `goto` free. Tim Wiederhake (2): cpu_map: Use g_auto* in loadData cpu_ppc64: Remove error path in virCPUppc64DriverGetModels src/cpu/cpu_map.c | 18 ++++++------------ src/cpu/cpu_ppc64.c | 11 ++--------- 2 files changed, 8 insertions(+), 21 deletions(-) -- 2.26.2

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_map.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index 3abec68c60..65d244e011 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -39,20 +39,19 @@ loadData(const char *mapfile, cpuMapLoadCallback callback, void *data) { - int ret = -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes = NULL; + g_autofree 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 +59,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

The call to `g_strfreev` is not required, as in both cases no memory has been allocated. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/cpu/cpu_ppc64.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 9e6f1e856e..28fbfea9ae 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -738,24 +738,17 @@ virCPUppc64DriverGetModels(char ***models) size_t i; 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); } return map->nmodels; - - error: - if (models) { - g_strfreev(*models); - *models = NULL; - } - return -1; } struct cpuArchDriver cpuDriverPPC64 = { -- 2.26.2

On a Wednesday in 2020, Tim Wiederhake wrote:
V1: https://www.redhat.com/archives/libvir-list/2020-September/msg00355.html
Changes since V1: * Most patches already commited, this is the remainder. * Incorporated comment from Ján into patch #1. * Rebased on top of Daniels patches.
With these patches, src/cpu/ becomes `goto` free.
Tim Wiederhake (2): cpu_map: Use g_auto* in loadData cpu_ppc64: Remove error path in virCPUppc64DriverGetModels
src/cpu/cpu_map.c | 18 ++++++------------ src/cpu/cpu_ppc64.c | 11 ++--------- 2 files changed, 8 insertions(+), 21 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Tim Wiederhake