Never overwrite GUsbDevice properties

Getting the string indexes from the hardware is not cheap, and also triggers a
warning from the fwupd daemon.
This commit is contained in:
Richard Hughes 2017-11-29 15:51:28 +00:00
parent 634e9228f8
commit 94e94eb976
2 changed files with 41 additions and 31 deletions

View File

@ -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))

View File

@ -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,7 +157,8 @@ fu_usb_device_open (FuUsbDevice *device, GError **error)
return FALSE;
/* get vendor */
idx = g_usb_device_get_manufacturer_index (priv->usb_device);
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,
@ -167,9 +167,11 @@ fu_usb_device_open (FuUsbDevice *device, GError **error)
return FALSE;
fu_device_set_vendor (FU_DEVICE (device), tmp);
}
}
/* get product */
idx = g_usb_device_get_product_index (priv->usb_device);
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,
@ -178,8 +180,11 @@ fu_usb_device_open (FuUsbDevice *device, GError **error)
return FALSE;
fu_device_set_name (FU_DEVICE (device), tmp);
}
}
/* get version number, falling back to the USB device release */
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);
@ -188,8 +193,11 @@ fu_usb_device_open (FuUsbDevice *device, GError **error)
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 */
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);
@ -198,6 +206,7 @@ fu_usb_device_open (FuUsbDevice *device, GError **error)
tmp = g_usb_device_get_string_descriptor (priv->usb_device, idx, NULL);
fu_device_add_guid (FU_DEVICE (device), tmp);
}
}
/* subclassed */
if (klass->open != NULL) {