From 4ab526ef71c13299d43115779b3e3ee0985298be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Fri, 3 Jun 2016 18:49:40 +0200 Subject: [PATCH] Only return two values in udevGetUintSysfsAttr Open code the call to udev_device_get_sysattr_value in the one place where it's needed. --- src/node_device/node_device_udev.c | 65 +++++++++--------------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 8c9c539f3e..d9d9887830 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -189,10 +189,10 @@ static int udevGetUintSysfsAttr(struct udev_device *udev_device, if (str && virStrToLong_ui(str, NULL, base, value) < 0) { VIR_ERROR(_("Failed to convert '%s' to unsigned int"), str); - return PROPERTY_ERROR; + return -1; } - return str == NULL ? PROPERTY_MISSING : PROPERTY_FOUND; + return 0; } @@ -339,19 +339,11 @@ static int udevProcessPCI(struct udev_device *device, goto out; } - if (udevGetUintSysfsAttr(device, - "vendor", - &data->pci_dev.vendor, - 16) == PROPERTY_ERROR) { + if (udevGetUintSysfsAttr(device, "vendor", &data->pci_dev.vendor, 16) < 0) goto out; - } - if (udevGetUintSysfsAttr(device, - "device", - &data->pci_dev.product, - 16) == PROPERTY_ERROR) { + if (udevGetUintSysfsAttr(device, "device", &data->pci_dev.product, 16) < 0) goto out; - } if (udevTranslatePCIIds(data->pci_dev.vendor, data->pci_dev.product, @@ -470,33 +462,21 @@ static int udevProcessUSBInterface(struct udev_device *device, int ret = -1; virNodeDevCapDataPtr data = &def->caps->data; - if (udevGetUintSysfsAttr(device, - "bInterfaceNumber", - &data->usb_if.number, - 16) == PROPERTY_ERROR) { + if (udevGetUintSysfsAttr(device, "bInterfaceNumber", + &data->usb_if.number, 16) < 0) goto out; - } - if (udevGetUintSysfsAttr(device, - "bInterfaceClass", - &data->usb_if._class, - 16) == PROPERTY_ERROR) { + if (udevGetUintSysfsAttr(device, "bInterfaceClass", + &data->usb_if._class, 16) < 0) goto out; - } - if (udevGetUintSysfsAttr(device, - "bInterfaceSubClass", - &data->usb_if.subclass, - 16) == PROPERTY_ERROR) { + if (udevGetUintSysfsAttr(device, "bInterfaceSubClass", + &data->usb_if.subclass, 16) < 0) goto out; - } - if (udevGetUintSysfsAttr(device, - "bInterfaceProtocol", - &data->usb_if.protocol, - 16) == PROPERTY_ERROR) { + if (udevGetUintSysfsAttr(device, "bInterfaceProtocol", + &data->usb_if.protocol, 16) < 0) goto out; - } if (udevGenerateDeviceName(device, def, NULL) != 0) goto out; @@ -530,12 +510,8 @@ static int udevProcessNetworkInterface(struct udev_device *device, &data->net.address) < 0) goto out; - if (udevGetUintSysfsAttr(device, - "addr_len", - &data->net.address_len, - 0) == PROPERTY_ERROR) { + if (udevGetUintSysfsAttr(device, "addr_len", &data->net.address_len, 0) < 0) goto out; - } if (udevGenerateDeviceName(device, def, data->net.address) != 0) goto out; @@ -683,17 +659,12 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED, return -1; } - switch (udevGetUintSysfsAttr(device, "type", &tmp, 0)) { - case PROPERTY_FOUND: - if (udevGetSCSIType(def, tmp, &data->scsi.type) == -1) + if (udev_device_get_sysattr_value(device, "type")) { + if (udevGetUintSysfsAttr(device, "type", &tmp, 0) < 0) + goto out; + + if (udevGetSCSIType(def, tmp, &data->scsi.type) < 0) goto out; - break; - case PROPERTY_MISSING: - break; /* No type is not an error */ - case PROPERTY_ERROR: - default: - goto out; - break; } if (udevGenerateDeviceName(device, def, NULL) != 0) -- GitLab