From 3ca2bdefa57c90d7d9ed633a01393d8a825ca2a1 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 25 Oct 2019 16:16:41 +0200 Subject: [PATCH] conf: caps: Modernize virCapabilitiesFormatCaches MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use automatic memory freeing and use virXMLFormatElement instead of open coding it. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/capabilities.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 0a0de447b5..1ab389bc65 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -938,7 +938,6 @@ virCapabilitiesFormatCaches(virBufferPtr buf, { size_t i = 0; size_t j = 0; - virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; if (!cache->nbanks) return 0; @@ -947,6 +946,8 @@ virCapabilitiesFormatCaches(virBufferPtr buf, virBufferAdjustIndent(buf, 2); for (i = 0; i < cache->nbanks; i++) { + g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; virCapsHostCacheBankPtr bank = cache->banks[i]; g_autofree char *cpus_str = virBitmapFormat(bank->cpus); const char *unit = NULL; @@ -959,8 +960,8 @@ virCapabilitiesFormatCaches(virBufferPtr buf, * Let's just *hope* the size is aligned to KiBs so that it does not * bite is back in the future */ - virBufferAsprintf(buf, - "id, bank->level, virCacheTypeToString(bank->type), @@ -1006,13 +1007,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf, controls->max_allocation); } - if (virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } + virXMLFormatElement(buf, "bank", &attrBuf, &childrenBuf); } if (virCapabilitiesFormatResctrlMonitor(buf, cache->monitor) < 0) -- 2.47.2