[libvirt] [PATCH] Allow USB hostdev product to be 0x0000

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Product = 0 is a valid value based on this bug report:

https://www.redhat.com/archives/libvir-list/2009-May/msg00368.html

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/domain_conf.c                                  |   12 ++++++++----
 .../qemuxml2argv-hostdev-usb-product.args          |    2 +-
 .../qemuxml2argv-hostdev-usb-product.xml           |    6 ++++++
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/domain_conf.c b/src/domain_conf.c
index c695820..94082a5 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -1660,8 +1660,13 @@ virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn,
                                      int flags ATTRIBUTE_UNUSED) {
 
     int ret = -1;
+    int got_product;
     xmlNodePtr cur;
 
+    /* Product can validly be 0, so we need some extra help to determine
+     * if it is uninitialized*/
+    got_product = 0;
+
     cur = node->children;
     while (cur != NULL) {
         if (cur->type == XML_ELEMENT_NODE) {
@@ -1686,6 +1691,7 @@ virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn,
                 char* product = virXMLPropString(cur, "id");
 
                 if (product) {
+                    got_product = 1;
                     if (virStrToLong_ui(product, NULL, 0,
                                         &def->source.subsys.u.usb.product) < 0) {
                         virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -1745,14 +1751,12 @@ virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn,
         cur = cur->next;
     }
 
-    if (def->source.subsys.u.usb.vendor == 0 &&
-        def->source.subsys.u.usb.product != 0) {
+    if (def->source.subsys.u.usb.vendor == 0 && got_product) {
         virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
             "%s", _("missing vendor"));
         goto out;
     }
-    if (def->source.subsys.u.usb.vendor != 0 &&
-        def->source.subsys.u.usb.product == 0) {
+    if (def->source.subsys.u.usb.vendor != 0 && !got_product) {
         virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
             "%s", _("missing product"));
         goto out;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.args
index e207871..f4c8f60 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.args
@@ -1 +1 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -usbdevice host:0204:6025
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -usbdevice host:0204:6025 -usbdevice host:1234:0000
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml
index b861665..6cb1ba1 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml
@@ -24,5 +24,11 @@
         <product id='0x6025'/>
       </source>
     </hostdev>
+    <hostdev mode='subsystem' type='usb' managed='no'>
+      <source>
+        <vendor id='0x1234'/>
+        <product id='0x0000'/>
+      </source>
+    </hostdev>
   </devices>
 </domain>
-- 
1.6.0.6

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]