From: Peter Krempa Date: Mon, 19 Aug 2024 14:57:55 +0000 (+0200) Subject: conf: domain: Clarify nvram/loader format logic X-Git-Tag: v10.10.0-rc1~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a448d4a18a378300852d1819b7a072cffe6ca661;p=thirdparty%2Flibvirt.git conf: domain: Clarify nvram/loader format logic Restructure the code to assign first (as this is simpler to refactor in the future) and avoid mixing implicit value checks with explicit ones by checking for _NONE. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3a32e50890..986c634fae 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17153,15 +17153,16 @@ virDomainLoaderDefParseXMLNvram(virDomainLoaderDef *loader, &format, VIR_STORAGE_FILE_NONE) < 0) { return -1; } - if (format && - format != VIR_STORAGE_FILE_RAW && - format != VIR_STORAGE_FILE_QCOW2) { + src->format = format; + + if (src->format != VIR_STORAGE_FILE_NONE && + src->format != VIR_STORAGE_FILE_RAW && + src->format != VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_XML_ERROR, _("Unsupported nvram format '%1$s'"), - virStorageFileFormatTypeToString(format)); + virStorageFileFormatTypeToString(src->format)); return -1; } - src->format = format; if ((typePresent = virXMLPropEnum(nvramNode, "type", virStorageTypeFromString, VIR_XML_PROP_NONE, @@ -17243,15 +17244,17 @@ virDomainLoaderDefParseXMLLoader(virDomainLoaderDef *loader, &format, VIR_STORAGE_FILE_NONE) < 0) { return -1; } - if (format && - format != VIR_STORAGE_FILE_RAW && - format != VIR_STORAGE_FILE_QCOW2) { + + loader->format = format; + + if (loader->format != VIR_STORAGE_FILE_NONE && + loader->format != VIR_STORAGE_FILE_RAW && + loader->format != VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_XML_ERROR, _("Unsupported loader format '%1$s'"), - virStorageFileFormatTypeToString(format)); + virStorageFileFormatTypeToString(loader->format)); return -1; } - loader->format = format; return 0; }