From cddf5b5b893eafc9515f0da3875099a8fc9baf10 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 7 Apr 2020 19:05:04 +0100 Subject: [PATCH] Only auto-add counterpart GUIDs when required Doing this unconditionally means we accidentally 'bleed' one device mode into another in a non-obvious way. For instance, a device might have two operating modes with different GUIDs. If firmware is supplied for both modes in the same cabinet archive then we might accidentally match the 'wrong' firmware when the daemon has observed a mode switch and added the counterpart GUIDs. We only really need the counterpart GUIDs when switching between Jabra, 8bitdo and DFU devices where the DFU bootloader VID:PID is not manually tagged with `CounterpartGuid` in a quirk file. In the general case lets keep it simple to avoid difficult to find bugs. --- libfwupd/fwupd-enums.c | 4 ++++ libfwupd/fwupd-enums.h | 2 ++ plugins/colorhug/fu-colorhug-device.c | 1 + plugins/dfu/dfu-device.c | 1 + plugins/ebitdo/fu-ebitdo-device.c | 1 + plugins/fastboot/fu-fastboot-device.c | 1 + plugins/jabra/fu-jabra-device.c | 1 + plugins/nitrokey/fu-nitrokey-device.c | 1 + plugins/vli/fu-vli-device.c | 1 + src/fu-device-list.c | 10 ++++++++-- 10 files changed, 21 insertions(+), 2 deletions(-) diff --git a/libfwupd/fwupd-enums.c b/libfwupd/fwupd-enums.c index 354bfaf8c..9909ad6bd 100644 --- a/libfwupd/fwupd-enums.c +++ b/libfwupd/fwupd-enums.c @@ -189,6 +189,8 @@ fwupd_device_flag_to_string (FwupdDeviceFlags device_flag) return "md-set-name-category"; if (device_flag == FWUPD_DEVICE_FLAG_MD_SET_VERFMT) return "md-set-verfmt"; + if (device_flag == FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS) + return "add-counterpart-guids"; if (device_flag == FWUPD_DEVICE_FLAG_UNKNOWN) return "unknown"; return NULL; @@ -279,6 +281,8 @@ fwupd_device_flag_from_string (const gchar *device_flag) return FWUPD_DEVICE_FLAG_MD_SET_NAME_CATEGORY; if (g_strcmp0 (device_flag, "md-set-verfmt") == 0) return FWUPD_DEVICE_FLAG_MD_SET_VERFMT; + if (g_strcmp0 (device_flag, "add-counterpart-guids") == 0) + return FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS; return FWUPD_DEVICE_FLAG_UNKNOWN; } diff --git a/libfwupd/fwupd-enums.h b/libfwupd/fwupd-enums.h index 31fbe31ff..21edfb170 100644 --- a/libfwupd/fwupd-enums.h +++ b/libfwupd/fwupd-enums.h @@ -102,6 +102,7 @@ typedef enum { * @FWUPD_DEVICE_FLAG_MD_SET_NAME: Set the device name from the metadata if available * @FWUPD_DEVICE_FLAG_MD_SET_NAME_CATEGORY: Set the device name from the metadata if available * @FWUPD_DEVICE_FLAG_MD_SET_VERFMT: Set the device version format from the metadata if available + * @FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS: Add counterpart GUIDs from an alternate mode like bootloader * * The device flags. **/ @@ -141,6 +142,7 @@ typedef enum { #define FWUPD_DEVICE_FLAG_MD_SET_NAME (1llu << 32) /* Since: 1.4.0 */ #define FWUPD_DEVICE_FLAG_MD_SET_NAME_CATEGORY (1llu << 33) /* Since: 1.4.0 */ #define FWUPD_DEVICE_FLAG_MD_SET_VERFMT (1llu << 34) /* Since: 1.4.0 */ +#define FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS (1llu << 35) /* Since: 1.4.0 */ #define FWUPD_DEVICE_FLAG_UNKNOWN G_MAXUINT64 /* Since: 0.7.3 */ typedef guint64 FwupdDeviceFlags; diff --git a/plugins/colorhug/fu-colorhug-device.c b/plugins/colorhug/fu-colorhug-device.c index cfe66e916..620e3c486 100644 --- a/plugins/colorhug/fu-colorhug-device.c +++ b/plugins/colorhug/fu-colorhug-device.c @@ -459,6 +459,7 @@ fu_colorhug_device_init (FuColorhugDevice *self) fu_device_set_version_format (FU_DEVICE (self), FWUPD_VERSION_FORMAT_TRIPLET); fu_device_set_remove_delay (FU_DEVICE (self), FU_DEVICE_REMOVE_DELAY_RE_ENUMERATE); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); } static void diff --git a/plugins/dfu/dfu-device.c b/plugins/dfu/dfu-device.c index f587c8e02..e9943edd0 100644 --- a/plugins/dfu/dfu-device.c +++ b/plugins/dfu/dfu-device.c @@ -1837,5 +1837,6 @@ dfu_device_init (DfuDevice *device) priv->transfer_size = 64; fu_device_add_icon (FU_DEVICE (device), "drive-harddisk-usb"); fu_device_add_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_UPDATABLE); + fu_device_add_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); fu_device_set_remove_delay (FU_DEVICE (device), FU_DEVICE_REMOVE_DELAY_RE_ENUMERATE); } diff --git a/plugins/ebitdo/fu-ebitdo-device.c b/plugins/ebitdo/fu-ebitdo-device.c index 32b5f77f1..ad105714b 100644 --- a/plugins/ebitdo/fu-ebitdo-device.c +++ b/plugins/ebitdo/fu-ebitdo-device.c @@ -581,6 +581,7 @@ static void fu_ebitdo_device_init (FuEbitdoDevice *self) { fu_device_set_protocol (FU_DEVICE (self), "com.8bitdo"); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); } static void diff --git a/plugins/fastboot/fu-fastboot-device.c b/plugins/fastboot/fu-fastboot-device.c index 037d7a0b2..c7857f1f8 100644 --- a/plugins/fastboot/fu-fastboot-device.c +++ b/plugins/fastboot/fu-fastboot-device.c @@ -699,6 +699,7 @@ fu_fastboot_device_init (FuFastbootDevice *self) fu_device_set_protocol (FU_DEVICE (self), "com.google.fastboot"); fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_UPDATABLE); fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_IS_BOOTLOADER); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); fu_device_set_remove_delay (FU_DEVICE (self), FASTBOOT_REMOVE_DELAY_RE_ENUMERATE); } diff --git a/plugins/jabra/fu-jabra-device.c b/plugins/jabra/fu-jabra-device.c index 363438a0f..c77acf112 100644 --- a/plugins/jabra/fu-jabra-device.c +++ b/plugins/jabra/fu-jabra-device.c @@ -142,6 +142,7 @@ static void fu_jabra_device_init (FuJabraDevice *self) { fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_UPDATABLE); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); fu_device_set_remove_delay (FU_DEVICE (self), 20000); /* 10+10s! */ } diff --git a/plugins/nitrokey/fu-nitrokey-device.c b/plugins/nitrokey/fu-nitrokey-device.c index 83bc78b12..493caf82d 100644 --- a/plugins/nitrokey/fu-nitrokey-device.c +++ b/plugins/nitrokey/fu-nitrokey-device.c @@ -134,6 +134,7 @@ fu_nitrokey_device_init (FuNitrokeyDevice *device) { fu_device_set_remove_delay (FU_DEVICE (device), FU_DEVICE_REMOVE_DELAY_RE_ENUMERATE); fu_device_add_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_UPDATABLE); + fu_device_add_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); fu_device_set_version_format (FU_DEVICE (device), FWUPD_VERSION_FORMAT_PAIR); fu_device_retry_set_delay (FU_DEVICE (device), 100); } diff --git a/plugins/vli/fu-vli-device.c b/plugins/vli/fu-vli-device.c index 5c7125e68..b91c827aa 100644 --- a/plugins/vli/fu-vli-device.c +++ b/plugins/vli/fu-vli-device.c @@ -674,6 +674,7 @@ fu_vli_device_init (FuVliDevice *self) priv->spi_cmds[FU_VLI_DEVICE_SPI_REQ_READ_ID] = 0x9f; priv->spi_cmd_read_id_sz = 2; priv->spi_auto_detect = TRUE; + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); } static void diff --git a/src/fu-device-list.c b/src/fu-device-list.c index abd7a4563..216a84429 100644 --- a/src/fu-device-list.c +++ b/src/fu-device-list.c @@ -470,8 +470,14 @@ fu_device_list_add_missing_guids (FuDevice *device_new, FuDevice *device_old) for (guint i = 0; i < guids_old->len; i++) { const gchar *guid_tmp = g_ptr_array_index (guids_old, i); if (!fu_device_has_guid (device_new, guid_tmp)) { - g_debug ("adding GUID %s to device", guid_tmp); - fu_device_add_counterpart_guid (device_new, guid_tmp); + if (fu_device_has_flag (device_new, FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS)) { + g_debug ("adding GUID %s to device", guid_tmp); + fu_device_add_counterpart_guid (device_new, guid_tmp); + } else { + g_debug ("not adding GUID %s to device, use " + "FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS if required", + guid_tmp); + } } } }