From 3fba30fc82a3f4286ec12e56c75b217e3a19abb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 17 Nov 2020 10:17:48 +0000 Subject: [PATCH] nodedev: report errors about missing integer properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Daniel P. Berrangé --- src/node_device/node_device_udev.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 1db839e14a..17051fd013 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -169,10 +169,17 @@ udevGetIntProperty(struct udev_device *udev_device, const char *str = NULL; str = udevGetDeviceProperty(udev_device, property_key); - - if (str && virStrToLong_i(str, NULL, base, value) < 0) { + if (!str) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to convert '%s' to int"), str); + _("Missing udev property '%s' on '%s'"), + property_key, udev_device_get_sysname(udev_device)); + return -1; + } + + if (virStrToLong_i(str, NULL, base, value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("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 && virStrToLong_ui(str, NULL, base, value) < 0) { + if (!str) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to convert '%s' to int"), str); + _("Missing udev property '%s' on '%s'"), + property_key, udev_device_get_sysname(udev_device)); + return -1; + } + + if (virStrToLong_ui(str, NULL, base, value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse uint '%s' from udev property '%s' on '%s'"), + str, property_key, udev_device_get_sysname(udev_device)); return -1; } return 0;