From 2ab379e6c50ea1de679a016d20431b9f95e377df Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 9 Apr 2020 16:03:36 +0100 Subject: [PATCH] Only set the parent when adopting children We use the ParentGuid quirk key to logically 'tie-together' different discrete devices into one logical device, for instance making the USB soundcard in a hub the child of the USB controller on the same PCB. Setting the discrete child is sometimes correct, for instance when rebooting the hub, the audio device also goes away -- but it's also sometimes wrong. If we set the child for a discrete device and the parent does *not* go away then we get to a situation where the child reference may no longer be valid if it comes back as a different object. When we try to remove this no-longer-valid device with the removal timeout the daemon segfaults. This is realy bad. Continue to allow using fu_device_add_child() in plugins, where we know the child lifecycle is is matched by the the parent. In the engine just set the weak parent directly and let the client use this information to show the tree of logical devices correctly. There's no benefit to setting up the children as referenced objects anyway. --- src/fu-engine.c | 4 ++-- src/fu-self-test.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fu-engine.c b/src/fu-engine.c index 6415d49a8..fc49b07fa 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -4369,7 +4369,7 @@ fu_engine_adopt_children (FuEngine *self, FuDevice *device) fu_device_get_id (device), fu_device_get_name (device_tmp), fu_device_get_id (device_tmp)); - fu_device_add_child (device_tmp, device); + fu_device_set_parent (device, device_tmp); break; } } @@ -4389,7 +4389,7 @@ fu_engine_adopt_children (FuEngine *self, FuDevice *device) fu_device_get_id (device_tmp), fu_device_get_name (device), fu_device_get_id (device)); - fu_device_add_child (device, device_tmp); + fu_device_set_parent (device_tmp, device); } } } diff --git a/src/fu-self-test.c b/src/fu-self-test.c index 40decb5cf..0fef6b3be 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -958,7 +958,6 @@ fu_engine_device_parent_func (gconstpointer user_data) g_assert (fu_device_get_parent (device3) == device2); g_assert (fu_device_get_parent (device1) == device2); g_assert_cmpstr (fu_device_get_vendor (device3), ==, "oem"); - g_assert_cmpstr (fu_device_get_vendor (device1), ==, "oem"); /* verify order */ g_assert_cmpint (fu_device_get_order (device1), ==, 0);