From ced79fce4a686bd06fe6f69e305fb839b3b61db5 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 30 Jun 2022 15:53:29 +0100 Subject: [PATCH] Create the better device GType in the backend It is weird to do this when constructing the object, and it allows us to match PossiblePlugin quirk matches on potentially better instance IDs added by the superclass. --- libfwupdplugin/fu-mei-device.c | 7 +++++++ libfwupdplugin/fu-udev-device.c | 11 ----------- plugins/amt/fu-amt-device.c | 1 - src/fu-udev-backend.c | 27 +++++++++++++++++++++++++-- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libfwupdplugin/fu-mei-device.c b/libfwupdplugin/fu-mei-device.c index f4c5a7810..b0ba355d7 100644 --- a/libfwupdplugin/fu-mei-device.c +++ b/libfwupdplugin/fu-mei-device.c @@ -70,6 +70,10 @@ fu_mei_device_probe(FuDevice *device, GError **error) return FALSE; } + /* FuUdevDevice->probe */ + if (!FU_DEVICE_CLASS(fu_mei_device_parent_class)->probe(device, error)) + return FALSE; + /* set the physical ID */ return fu_udev_device_set_physical_id(FU_UDEV_DEVICE(device), "pci", error); } @@ -324,6 +328,9 @@ fu_mei_device_incorporate(FuDevice *device, FuDevice *donor) static void fu_mei_device_init(FuMeiDevice *self) { + fu_udev_device_set_flags(FU_UDEV_DEVICE(self), + FU_UDEV_DEVICE_FLAG_OPEN_READ | FU_UDEV_DEVICE_FLAG_OPEN_WRITE | + FU_UDEV_DEVICE_FLAG_VENDOR_FROM_PARENT); } static void diff --git a/libfwupdplugin/fu-udev-device.c b/libfwupdplugin/fu-udev-device.c index 68d9c715a..845961772 100644 --- a/libfwupdplugin/fu-udev-device.c +++ b/libfwupdplugin/fu-udev-device.c @@ -2243,16 +2243,5 @@ fu_udev_device_class_init(FuUdevDeviceClass *klass) FuUdevDevice * fu_udev_device_new(FuContext *ctx, GUdevDevice *udev_device) { -#ifdef HAVE_GUDEV - /* create the correct object depending on the subsystem */ - if (g_strcmp0(g_udev_device_get_subsystem(udev_device), "i2c-dev") == 0) { - return g_object_new(FU_TYPE_I2C_DEVICE, - "context", - ctx, - "udev-device", - udev_device, - NULL); - } -#endif return g_object_new(FU_TYPE_UDEV_DEVICE, "context", ctx, "udev-device", udev_device, NULL); } diff --git a/plugins/amt/fu-amt-device.c b/plugins/amt/fu-amt-device.c index 546a87de9..4659f3990 100644 --- a/plugins/amt/fu-amt-device.c +++ b/plugins/amt/fu-amt-device.c @@ -354,7 +354,6 @@ fu_amt_device_setup(FuDevice *device, GError **error) static void fu_amt_device_init(FuAmtDevice *self) { - fu_device_set_vendor(FU_DEVICE(self), "Intel"); fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_INTEL_ME); fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_INTERNAL); fu_device_add_icon(FU_DEVICE(self), "computer"); diff --git a/src/fu-udev-backend.c b/src/fu-udev-backend.c index ae2df1dac..b3b6d93ab 100644 --- a/src/fu-udev-backend.c +++ b/src/fu-udev-backend.c @@ -8,10 +8,11 @@ #include "config.h" +#include + #include #include "fu-udev-backend.h" -#include "fu-udev-device.h" struct _FuUdevBackend { FuBackend parent_instance; @@ -25,10 +26,32 @@ G_DEFINE_TYPE(FuUdevBackend, fu_udev_backend, FU_TYPE_BACKEND) static void fu_udev_backend_device_add(FuUdevBackend *self, GUdevDevice *udev_device) { + GType gtype = FU_TYPE_UDEV_DEVICE; g_autoptr(FuUdevDevice) device = NULL; + struct { + const gchar *subsystem; + GType gtype; + } subsystem_gtype_map[] = {{"mei", FU_TYPE_MEI_DEVICE}, + {"i2c", FU_TYPE_I2C_DEVICE}, + {"i2c-dev", FU_TYPE_I2C_DEVICE}, + {NULL, G_TYPE_INVALID}}; + + /* create the correct object depending on the subsystem */ + for (guint i = 0; subsystem_gtype_map[i].gtype != G_TYPE_INVALID; i++) { + if (g_strcmp0(g_udev_device_get_subsystem(udev_device), + subsystem_gtype_map[i].subsystem) == 0) { + gtype = subsystem_gtype_map[i].gtype; + break; + } + } /* success */ - device = fu_udev_device_new(fu_backend_get_context(FU_BACKEND(self)), udev_device); + device = g_object_new(gtype, + "context", + fu_backend_get_context(FU_BACKEND(self)), + "udev-device", + udev_device, + NULL); fu_backend_device_added(FU_BACKEND(self), FU_DEVICE(device)); }