]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: report errors about missing integer properties
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 17 Nov 2020 10:17:48 +0000 (10:17 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 17 Nov 2020 16:55:07 +0000 (16:55 +0000)
The helper methods for getting integer properties ignore a missing
property setting its value to zero. This lack of error reporting
resulted in missing the regression handling hotplug of USB devices
with the vendor and model IDs getting set to zero silently.

The few callers which relied on this silent defaulting have been fixed,
so now we can report fatal errors immediately.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/node_device/node_device_udev.c

index 1db839e14afe4e5060fbcfbb843663899f2ed8d1..17051fd01332f8f93de70403a4ea20ba2e3e62f3 100644 (file)
@@ -169,10 +169,17 @@ udevGetIntProperty(struct udev_device *udev_device,
     const char *str = NULL;
 
     str = udevGetDeviceProperty(udev_device, property_key);
+    if (!str) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Missing udev property '%s' on '%s'"),
+                       property_key, udev_device_get_sysname(udev_device));
+        return -1;
+    }
 
-    if (str && virStrToLong_i(str, NULL, base, value) < 0) {
+    if (virStrToLong_i(str, NULL, base, value) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Failed to convert '%s' to int"), str);
+                       _("Failed to parse int '%s' from udev property '%s' on '%s'"),
+                       str, property_key, udev_device_get_sysname(udev_device));
         return -1;
     }
     return 0;
@@ -188,10 +195,17 @@ udevGetUintProperty(struct udev_device *udev_device,
     const char *str = NULL;
 
     str = udevGetDeviceProperty(udev_device, property_key);
+    if (!str) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Missing udev property '%s' on '%s'"),
+                       property_key, udev_device_get_sysname(udev_device));
+        return -1;
+    }
 
-    if (str && virStrToLong_ui(str, NULL, base, value) < 0) {
+    if (virStrToLong_ui(str, NULL, base, value) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Failed to convert '%s' to int"), str);
+                       _("Failed to parse uint '%s' from udev property '%s' on '%s'"),
+                       str, property_key, udev_device_get_sysname(udev_device));
         return -1;
     }
     return 0;