[libvirt] [PATCH] domain_conf: Fix str2enum translation of video driver name

Michal Privoznik posted 1 patch 4 years, 6 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20cc7f9e8a3324a4ba7dcd126a656386ea212b29.1569401876.git.mprivozn@redhat.com
src/conf/domain_conf.c | 4 +++-
src/conf/domain_conf.h | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
[libvirt] [PATCH] domain_conf: Fix str2enum translation of video driver name
Posted by Michal Privoznik 4 years, 6 months ago
In bc1e924cf0d we've introduced video driver name and whilst
doing so we've utilized VIR_ENUM_IMPL() macro. Then, in domain
XML parsing code the generated
virDomainVideoBackendTypeFromString() is called and its return
value is assigned directly to an unsigned int variable which is
wrong. Also, the video driver enum has 'default' value which is
not formatted into domain XML but is accepted during parsing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

Pushed under trivial & build breaker rules.

 src/conf/domain_conf.c | 4 +++-
 src/conf/domain_conf.h | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6dea670257..67555c9be3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15504,11 +15504,13 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
     }
 
     if (driver_name) {
-        if ((def->backend = virDomainVideoBackendTypeFromString(driver_name)) < 0) {
+        int backend;
+        if ((backend = virDomainVideoBackendTypeFromString(driver_name)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown video driver '%s'"), driver_name);
             goto error;
         }
+        def->backend = backend;
     } else {
         def->backend = VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT;
     }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cff33f6682..53bdee22fb 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1378,7 +1378,7 @@ struct _virDomainWatchdogDef {
 
 /* the backend driver used for virtio interfaces */
 typedef enum {
-    VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT,
+    VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT = 0,
     VIR_DOMAIN_VIDEO_BACKEND_TYPE_QEMU,
     VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER,
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list