From: Andrea Bolognani Date: Wed, 17 Dec 2025 00:12:35 +0000 (+0100) Subject: qemu_firmware: Refactor setting NVRAM format X-Git-Tag: v12.0.0-rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab8efe6fd076d5e944902e4b2194a7db35a85101;p=thirdparty%2Flibvirt.git qemu_firmware: Refactor setting NVRAM format Instead of setting the format every single time, knowing that we might throw away the entire definition immediately afterwards, and duplicating a check, only set it if we are going to perform an early return due to the rest of the definition being properly filled in already. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index a7bb8f7e45..f32e46cc8c 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -985,15 +985,16 @@ qemuFirmwareEnsureNVRAM(virDomainDef *def, if (loader->stateless == VIR_TRISTATE_BOOL_YES) return; - /* If the NVRAM format hasn't been set yet, inherit the same as - * the loader */ - if (loader->nvram && !loader->nvram->format) - loader->nvram->format = loader->format; - if (loader->nvram) { - /* Nothing to do if a proper NVRAM backend is already configured */ - if (!virStorageSourceIsEmpty(loader->nvram)) + /* If a proper NVRAM backend is already configured, we are + * done for the most part. We might still need to set the + * NVRAM format if that's missing though */ + if (!virStorageSourceIsEmpty(loader->nvram)) { + if (!loader->nvram->format) { + loader->nvram->format = loader->format; + } return; + } /* otherwise we want to reset and re-populate the definition */ virObjectUnref(loader->nvram);