diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 7c5bf69a377443043e6a9223592be56b0cb3fa39..28823893c4c79d0da60aa52a1346ea3e871612a2 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -311,42 +311,32 @@ virCPUDefParseXML(const xmlNodePtr node, def->ncells = n; for (i = 0 ; i < n ; i++) { - char *cpus, *cpus_parse, *memory; + char *cpus, *memory; int cpumasklen = VIR_DOMAIN_CPUMASK_LEN; int ret, ncpus = 0; def->cells[i].cellid = i; - cpus = cpus_parse = virXMLPropString(nodes[i], "cpus"); + cpus = virXMLPropString(nodes[i], "cpus"); if (!cpus) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing 'cpus' attribute in NUMA cell")); goto error; } + def->cells[i].cpustr = cpus; - def->cells[i].cpustr = strdup(cpus); - if (!def->cells[i].cpustr) { - VIR_FREE(cpus); + if (VIR_ALLOC_N(def->cells[i].cpumask, cpumasklen) < 0) goto no_memory; - } - if (VIR_ALLOC_N(def->cells[i].cpumask, cpumasklen) < 0) { - VIR_FREE(cpus); - goto no_memory; - } - - ncpus = virDomainCpuSetParse((const char **)&cpus_parse, - 0, def->cells[i].cpumask, cpumasklen); - if (ncpus <= 0) { - VIR_FREE(cpus); + ncpus = virDomainCpuSetParse(cpus, 0, def->cells[i].cpumask, + cpumasklen); + if (ncpus <= 0) goto error; - } def->cells_cpus += ncpus; memory = virXMLPropString(nodes[i], "memory"); if (!memory) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing 'memory' attribute in NUMA cell")); - VIR_FREE(cpus); goto error; } @@ -354,11 +344,9 @@ virCPUDefParseXML(const xmlNodePtr node, if (ret == -1) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid 'memory' attribute in NUMA cell")); - VIR_FREE(cpus); VIR_FREE(memory); goto error; } - VIR_FREE(cpus); VIR_FREE(memory); } } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e98625307f36c37d88ae60e2eb99da8c1cf13def..d365cee66d1b25781e5ecc2f928a7112247512ab 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6636,8 +6636,7 @@ virDomainVcpuPinDefParseXML(const xmlNodePtr node, virReportOOMError(); goto error; } - if (virDomainCpuSetParse((const char **)&set, - 0, def->cpumask, + if (virDomainCpuSetParse(set, 0, def->cpumask, cpumasklen) < 0) goto error; VIR_FREE(tmp); @@ -6850,8 +6849,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0) { goto no_memory; } - if (virDomainCpuSetParse((const char **)&set, - 0, def->cpumask, + if (virDomainCpuSetParse(set, 0, def->cpumask, def->cpumasklen) < 0) goto error; VIR_FREE(tmp); @@ -6921,8 +6919,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, } /* "nodeset" leads same syntax with "cpuset". */ - if (virDomainCpuSetParse((const char **)&set, - 0, def->numatune.memory.nodemask, + if (virDomainCpuSetParse(set, 0, def->numatune.memory.nodemask, nodemasklen) < 0) goto error; VIR_FREE(tmp); @@ -9155,7 +9152,7 @@ virDomainCpuSetFormat(char *cpuset, int maxcpu) /** * virDomainCpuSetParse: * @conn: connection - * @str: pointer to a CPU set string pointer + * @str: a CPU set string pointer * @sep: potential character used to mark the end of string if not 0 * @cpuset: pointer to a char array for the CPU set * @maxcpu: number of elements available in @cpuset @@ -9166,10 +9163,9 @@ virDomainCpuSetFormat(char *cpuset, int maxcpu) * * Returns the number of CPU found in that set, or -1 in case of error. * @cpuset is modified accordingly to the value parsed. - * @str is updated to the end of the part parsed */ int -virDomainCpuSetParse(const char **str, char sep, +virDomainCpuSetParse(const char *str, char sep, char *cpuset, int maxcpu) { const char *cur; @@ -9181,7 +9177,7 @@ virDomainCpuSetParse(const char **str, char sep, (maxcpu > 100000)) return (-1); - cur = *str; + cur = str; virSkipSpaces(&cur); if (*cur == 0) goto parse_error; @@ -9246,7 +9242,6 @@ virDomainCpuSetParse(const char **str, char sep, } else goto parse_error; } - *str = cur; return (ret); parse_error: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 481dfc6d0bf6bf33d0563034dcc4872ed41c8bef..75111782826256d4c51e0697a72586c261fe90fa 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1747,7 +1747,7 @@ int virDomainDefFormatInternal(virDomainDefPtr def, unsigned int flags, virBufferPtr buf); -int virDomainCpuSetParse(const char **str, +int virDomainCpuSetParse(const char *str, char sep, char *cpuset, int maxcpu); diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 80a247236b1feee8dc87e466e2d15777dac176ae..2318565396b69213bcac8f55199d78a302e6cba4 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1153,7 +1153,7 @@ sexpr_to_xend_topology(const struct sexpr *root, for (cpu = 0; cpu < numCpus; cpu++) cpuset[cpu] = 0; } else { - nb_cpus = virDomainCpuSetParse(&cur, 'n', cpuset, numCpus); + nb_cpus = virDomainCpuSetParse(cur, 'n', cpuset, numCpus); if (nb_cpus < 0) goto error; } diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 24311a70941ecb21b65342237536b4d34f372595..a250b6ff9efe43ae00fbff87c7c72bafa0a9fdb4 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -893,8 +893,7 @@ int xenXMDomainPinVcpu(virDomainPtr domain, virReportOOMError(); goto cleanup; } - if (virDomainCpuSetParse((const char **)&mapstr, 0, - cpuset, maxcpu) < 0) + if (virDomainCpuSetParse(mapstr, 0, cpuset, maxcpu) < 0) goto cleanup; VIR_FREE(entry->def->cpumask); diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index e0bc043a233bcc03b7a1d798a4d02831743c2d6b..124c36978633b07be94a74dd44303fd4e54f2812 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -1140,8 +1140,7 @@ xenParseSxpr(const struct sexpr *root, goto error; } - if (virDomainCpuSetParse(&cpus, - 0, def->cpumask, + if (virDomainCpuSetParse(cpus, 0, def->cpumask, def->cpumasklen) < 0) { XENXS_ERROR(VIR_ERR_INTERNAL_ERROR, _("invalid CPU mask %s"), cpus); diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index a2ef8c8d7b33c8fa53ff77eb0dbd7e367acac472..b415ce8c33abd8a302615203855f23d9e277db8b 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -338,7 +338,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0) goto no_memory; - if (virDomainCpuSetParse(&str, 0, + if (virDomainCpuSetParse(str, 0, def->cpumask, def->cpumasklen) < 0) goto cleanup; }