From 94e94eb9766a0ab9e06d4be8fbd516dd7de3c9df Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Wed, 29 Nov 2017 15:51:28 +0000 Subject: [PATCH] Never overwrite GUsbDevice properties Getting the string indexes from the hardware is not cheap, and also triggers a warning from the fwupd daemon. --- src/fu-device.h | 1 + src/fu-usb-device.c | 71 +++++++++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/fu-device.h b/src/fu-device.h index 829c0ffeb..71c06d2b7 100644 --- a/src/fu-device.h +++ b/src/fu-device.h @@ -86,6 +86,7 @@ FuDevice *fu_device_new (void); #define fu_device_get_plugin(d) fwupd_device_get_plugin(FWUPD_DEVICE(d)) #define fu_device_get_update_error(d) fwupd_device_get_update_error(FWUPD_DEVICE(d)) #define fu_device_get_update_state(d) fwupd_device_get_update_state(FWUPD_DEVICE(d)) +#define fu_device_get_vendor(d) fwupd_device_get_vendor(FWUPD_DEVICE(d)) #define fu_device_get_version(d) fwupd_device_get_version(FWUPD_DEVICE(d)) #define fu_device_get_version_lowest(d) fwupd_device_get_version_lowest(FWUPD_DEVICE(d)) #define fu_device_get_version_bootloader(d) fwupd_device_get_version_bootloader(FWUPD_DEVICE(d)) diff --git a/src/fu-usb-device.c b/src/fu-usb-device.c index 8803a304d..5fe03321d 100644 --- a/src/fu-usb-device.c +++ b/src/fu-usb-device.c @@ -133,7 +133,6 @@ fu_usb_device_open (FuUsbDevice *device, GError **error) { FuUsbDevicePrivate *priv = GET_PRIVATE (device); FuUsbDeviceClass *klass = FU_USB_DEVICE_GET_CLASS (device); - guint idx; g_autoptr(AsProfile) profile = as_profile_new (); g_autoptr(AsProfileTask) ptask = NULL; g_autoptr(FuDeviceLocker) locker = NULL; @@ -158,45 +157,55 @@ fu_usb_device_open (FuUsbDevice *device, GError **error) return FALSE; /* get vendor */ - idx = g_usb_device_get_manufacturer_index (priv->usb_device); - if (idx != 0x00) { - g_autofree gchar *tmp = NULL; - tmp = g_usb_device_get_string_descriptor (priv->usb_device, - idx, error); - if (tmp == NULL) - return FALSE; - fu_device_set_vendor (FU_DEVICE (device), tmp); + if (fu_device_get_vendor (FU_DEVICE (device)) == NULL) { + guint idx = g_usb_device_get_manufacturer_index (priv->usb_device); + if (idx != 0x00) { + g_autofree gchar *tmp = NULL; + tmp = g_usb_device_get_string_descriptor (priv->usb_device, + idx, error); + if (tmp == NULL) + return FALSE; + fu_device_set_vendor (FU_DEVICE (device), tmp); + } } /* get product */ - idx = g_usb_device_get_product_index (priv->usb_device); - if (idx != 0x00) { - g_autofree gchar *tmp = NULL; - tmp = g_usb_device_get_string_descriptor (priv->usb_device, - idx, error); - if (tmp == NULL) - return FALSE; - fu_device_set_name (FU_DEVICE (device), tmp); + if (fu_device_get_name (FU_DEVICE (device)) == NULL) { + guint idx = g_usb_device_get_product_index (priv->usb_device); + if (idx != 0x00) { + g_autofree gchar *tmp = NULL; + tmp = g_usb_device_get_string_descriptor (priv->usb_device, + idx, error); + if (tmp == NULL) + return FALSE; + fu_device_set_name (FU_DEVICE (device), tmp); + } } /* get version number, falling back to the USB device release */ - idx = g_usb_device_get_custom_index (priv->usb_device, - G_USB_DEVICE_CLASS_VENDOR_SPECIFIC, - 'F', 'W', NULL); - if (idx != 0x00) { - g_autofree gchar *tmp = NULL; - tmp = g_usb_device_get_string_descriptor (priv->usb_device, idx, NULL); - fu_device_set_version (FU_DEVICE (device), tmp); + if (fu_device_get_version (FU_DEVICE (device)) == NULL) { + guint idx; + idx = g_usb_device_get_custom_index (priv->usb_device, + G_USB_DEVICE_CLASS_VENDOR_SPECIFIC, + 'F', 'W', NULL); + if (idx != 0x00) { + g_autofree gchar *tmp = NULL; + tmp = g_usb_device_get_string_descriptor (priv->usb_device, idx, NULL); + fu_device_set_version (FU_DEVICE (device), tmp); + } } /* get GUID from the descriptor if set */ - idx = g_usb_device_get_custom_index (priv->usb_device, - G_USB_DEVICE_CLASS_VENDOR_SPECIFIC, - 'G', 'U', NULL); - if (idx != 0x00) { - g_autofree gchar *tmp = NULL; - tmp = g_usb_device_get_string_descriptor (priv->usb_device, idx, NULL); - fu_device_add_guid (FU_DEVICE (device), tmp); + if (fu_device_get_guid_default (FU_DEVICE (device)) == NULL) { + guint idx; + idx = g_usb_device_get_custom_index (priv->usb_device, + G_USB_DEVICE_CLASS_VENDOR_SPECIFIC, + 'G', 'U', NULL); + if (idx != 0x00) { + g_autofree gchar *tmp = NULL; + tmp = g_usb_device_get_string_descriptor (priv->usb_device, idx, NULL); + fu_device_add_guid (FU_DEVICE (device), tmp); + } } /* subclassed */