diff --git a/libfwupdplugin/fu-device.c b/libfwupdplugin/fu-device.c index 0b0e53afe..32d0cfcc8 100644 --- a/libfwupdplugin/fu-device.c +++ b/libfwupdplugin/fu-device.c @@ -1097,6 +1097,26 @@ fu_device_get_proxy (FuDevice *self) return priv->proxy; } +/** + * fu_device_get_proxy_with_fallback: + * @self: a #FuDevice + * + * Gets the proxy device, falling back to the device itself. + * + * Returns: (transfer none): a device + * + * Since: 1.6.2 + **/ +FuDevice * +fu_device_get_proxy_with_fallback (FuDevice *self) +{ + FuDevicePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_DEVICE (self), NULL); + if (priv->proxy != NULL) + return priv->proxy; + return self; +} + /** * fu_device_get_children: * @self: a #FuDevice diff --git a/libfwupdplugin/fu-device.h b/libfwupdplugin/fu-device.h index 24f8383dd..eac0384de 100644 --- a/libfwupdplugin/fu-device.h +++ b/libfwupdplugin/fu-device.h @@ -310,6 +310,7 @@ void fu_device_add_counterpart_guid (FuDevice *self, FuDevice *fu_device_get_proxy (FuDevice *self); void fu_device_set_proxy (FuDevice *self, FuDevice *proxy); +FuDevice *fu_device_get_proxy_with_fallback (FuDevice *self); const gchar *fu_device_get_metadata (FuDevice *self, const gchar *key); gboolean fu_device_get_metadata_boolean (FuDevice *self, diff --git a/libfwupdplugin/fu-plugin.c b/libfwupdplugin/fu-plugin.c index b3e020e09..2ecdfce30 100644 --- a/libfwupdplugin/fu-plugin.c +++ b/libfwupdplugin/fu-plugin.c @@ -655,8 +655,9 @@ fu_plugin_get_context (FuPlugin *self) static gboolean fu_plugin_device_attach (FuPlugin *self, FuDevice *device, GError **error) { + FuDevice *proxy = fu_device_get_proxy_with_fallback (device); g_autoptr(FuDeviceLocker) locker = NULL; - locker = fu_device_locker_new (device, error); + locker = fu_device_locker_new (proxy, error); if (locker == NULL) return FALSE; return fu_device_attach (device, error); @@ -665,8 +666,9 @@ fu_plugin_device_attach (FuPlugin *self, FuDevice *device, GError **error) static gboolean fu_plugin_device_detach (FuPlugin *self, FuDevice *device, GError **error) { + FuDevice *proxy = fu_device_get_proxy_with_fallback (device); g_autoptr(FuDeviceLocker) locker = NULL; - locker = fu_device_locker_new (device, error); + locker = fu_device_locker_new (proxy, error); if (locker == NULL) return FALSE; return fu_device_detach (device, error); @@ -675,8 +677,9 @@ fu_plugin_device_detach (FuPlugin *self, FuDevice *device, GError **error) static gboolean fu_plugin_device_activate (FuPlugin *self, FuDevice *device, GError **error) { + FuDevice *proxy = fu_device_get_proxy_with_fallback (device); g_autoptr(FuDeviceLocker) locker = NULL; - locker = fu_device_locker_new (device, error); + locker = fu_device_locker_new (proxy, error); if (locker == NULL) return FALSE; return fu_device_activate (device, error); @@ -687,8 +690,9 @@ fu_plugin_device_write_firmware (FuPlugin *self, FuDevice *device, GBytes *fw, FwupdInstallFlags flags, GError **error) { + FuDevice *proxy = fu_device_get_proxy_with_fallback (device); g_autoptr(FuDeviceLocker) locker = NULL; - locker = fu_device_locker_new (device, error); + locker = fu_device_locker_new (proxy, error); if (locker == NULL) return FALSE; @@ -723,6 +727,7 @@ fu_plugin_device_write_firmware (FuPlugin *self, FuDevice *device, static gboolean fu_plugin_device_read_firmware (FuPlugin *self, FuDevice *device, GError **error) { + FuDevice *proxy = fu_device_get_proxy_with_fallback (device); g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(FuFirmware) firmware = NULL; g_autoptr(GBytes) fw = NULL; @@ -730,7 +735,7 @@ fu_plugin_device_read_firmware (FuPlugin *self, FuDevice *device, GError **error G_CHECKSUM_SHA1, G_CHECKSUM_SHA256, 0 }; - locker = fu_device_locker_new (device, error); + locker = fu_device_locker_new (proxy, error); if (locker == NULL) return FALSE; if (!fu_device_detach (device, error)) @@ -1219,6 +1224,7 @@ fu_plugin_runner_update_detach (FuPlugin *self, FuDevice *device, GError **error gboolean fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error) { + FuDevice *proxy = fu_device_get_proxy_with_fallback (device); g_autoptr(FuDeviceLocker) locker = NULL; /* not enabled */ @@ -1226,7 +1232,7 @@ fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error return TRUE; /* no object loaded */ - locker = fu_device_locker_new (device, error); + locker = fu_device_locker_new (proxy, error); if (locker == NULL) return FALSE; return fu_device_reload (device, error); @@ -1407,6 +1413,7 @@ fu_plugin_check_supported_device (FuPlugin *self, FuDevice *device) static gboolean fu_plugin_backend_device_added (FuPlugin *self, FuDevice *device, GError **error) { + FuDevice *proxy; FuPluginPrivate *priv = GET_PRIVATE (self); GType device_gtype = fu_device_get_specialized_gtype (FU_DEVICE (device)); g_autoptr(FuDevice) dev = NULL; @@ -1444,6 +1451,13 @@ fu_plugin_backend_device_added (FuPlugin *self, FuDevice *device, GError **error } /* open and add */ + proxy = fu_device_get_proxy (device); + if (proxy != NULL) { + g_autoptr(FuDeviceLocker) locker_proxy = NULL; + locker_proxy = fu_device_locker_new (proxy, error); + if (locker_proxy == NULL) + return FALSE; + } locker = fu_device_locker_new (dev, error); if (locker == NULL) return FALSE; diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index e2a819b0d..4e7e92cff 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -829,6 +829,7 @@ LIBFWUPDPLUGIN_1.6.2 { fu_device_emit_request; fu_device_get_parent_physical_ids; fu_device_get_private_flags; + fu_device_get_proxy_with_fallback; fu_device_get_request_cnt; fu_device_has_parent_physical_id; fu_device_has_private_flag; diff --git a/plugins/vli/fu-vli-usbhub-device.c b/plugins/vli/fu-vli-usbhub-device.c index 5ea300385..86e8856a1 100644 --- a/plugins/vli/fu-vli-usbhub-device.c +++ b/plugins/vli/fu-vli-usbhub-device.c @@ -299,8 +299,9 @@ fu_vli_usbhub_device_spi_write_data (FuVliDevice *self, #define VL817_ADDR_GPIO_GET_INPUT_DATA 0xF6A2 /* 0=low, 1=high */ static gboolean -fu_vli_usbhub_device_attach_full (FuDevice *device, FuDevice *proxy, GError **error) +fu_vli_usbhub_device_attach (FuDevice *device, GError **error) { + FuDevice *proxy = fu_device_get_proxy_with_fallback (device); g_autoptr(GError) error_local = NULL; /* update UI */ @@ -362,25 +363,6 @@ fu_vli_usbhub_device_attach_full (FuDevice *device, FuDevice *proxy, GError **er return TRUE; } -static gboolean -fu_vli_usbhub_device_attach (FuDevice *device, GError **error) -{ - FuDevice *proxy = fu_device_get_proxy (device); - - /* if we do this in another plugin, perhaps move to the engine? */ - if (proxy != NULL) { - g_autoptr(FuDeviceLocker) locker = NULL; - g_debug ("using proxy device %s", fu_device_get_id (proxy)); - locker = fu_device_locker_new (proxy, error); - if (locker == NULL) - return FALSE; - return fu_vli_usbhub_device_attach_full (device, proxy, error); - } - - /* normal case */ - return fu_vli_usbhub_device_attach_full (device, device, error); -} - /* disable hub sleep states -- not really required by 815~ hubs */ static gboolean fu_vli_usbhub_device_disable_u1u2 (FuVliUsbhubDevice *self, GError **error)