Run the child setup when calling the parent device

If we're creating the child device using `Children=FuFooDevice|FOO&I2C_01` in
the quirk file then there's not actually anywhere to call FuDevice->setup()
on the child.

The logical place to do it is when we setup the parent, which is a NOP if
already called for the child. We also don't need to convert the child instance
IDs as it's already being handled during the child setup.

Tested-By: Ricky Wu <ricky_wu@realtek.com>
This commit is contained in:
Richard Hughes 2021-01-23 13:00:03 +00:00 committed by Ricky Wu
parent e9adb950b7
commit b54d69467d
2 changed files with 39 additions and 9 deletions

View File

@ -3147,24 +3147,17 @@ fu_device_rescan (FuDevice *self, GError **error)
void
fu_device_convert_instance_ids (FuDevice *self)
{
GPtrArray *children;
GPtrArray *instance_ids = fwupd_device_get_instance_ids (FWUPD_DEVICE (self));
GPtrArray *instance_ids;
/* OEM specific hardware */
if (fu_device_has_internal_flag (self, FU_DEVICE_INTERNAL_FLAG_NO_AUTO_INSTANCE_IDS))
return;
instance_ids = fwupd_device_get_instance_ids (FWUPD_DEVICE (self));
for (guint i = 0; i < instance_ids->len; i++) {
const gchar *instance_id = g_ptr_array_index (instance_ids, i);
g_autofree gchar *guid = fwupd_guid_hash_string (instance_id);
fwupd_device_add_guid (FWUPD_DEVICE (self), guid);
}
/* convert all children too */
children = fu_device_get_children (self);
for (guint i = 0; i < children->len; i++) {
FuDevice *devtmp = g_ptr_array_index (children, i);
fu_device_convert_instance_ids (devtmp);
}
}
/**
@ -3185,6 +3178,7 @@ fu_device_setup (FuDevice *self, GError **error)
{
FuDevicePrivate *priv = GET_PRIVATE (self);
FuDeviceClass *klass = FU_DEVICE_GET_CLASS (self);
GPtrArray *children;
g_return_val_if_fail (FU_IS_DEVICE (self), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@ -3199,6 +3193,14 @@ fu_device_setup (FuDevice *self, GError **error)
return FALSE;
}
/* run setup on the children too (unless done already) */
children = fu_device_get_children (self);
for (guint i = 0; i < children->len; i++) {
FuDevice *child_tmp = g_ptr_array_index (children, i);
if (!fu_device_setup (child_tmp, error))
return FALSE;
}
/* convert the instance IDs to GUIDs */
fu_device_convert_instance_ids (self);

View File

@ -1180,6 +1180,33 @@ fu_device_flags_func (void)
g_assert_cmpint (fu_device_get_flags (device), ==, FWUPD_DEVICE_FLAG_UPDATABLE);
}
static void
fu_device_children_func (void)
{
gboolean ret;
g_autoptr(FuDevice) child = fu_device_new ();
g_autoptr(FuDevice) parent = fu_device_new ();
g_autoptr(GError) error = NULL;
fu_device_set_physical_id (child, "dummy");
fu_device_set_physical_id (parent, "dummy");
/* set up family */
fu_device_add_child (parent, child);
/* set an instance ID that will be converted to a GUID when the parent
* calls ->setup */
fu_device_add_instance_id (child, "foo");
g_assert_false (fu_device_has_guid (child, "b84ed8ed-a7b1-502f-83f6-90132e68adef"));
/* setup parent, which also calls setup on child too (and thus also
* converts the instance ID to a GUID) */
ret = fu_device_setup (parent, &error);
g_assert_no_error (error);
g_assert_true (ret);
g_assert_true (fu_device_has_guid (child, "b84ed8ed-a7b1-502f-83f6-90132e68adef"));
}
static void
fu_device_parent_func (void)
{
@ -2249,6 +2276,7 @@ main (int argc, char **argv)
g_test_add_func ("/fwupd/device{instance-ids}", fu_device_instance_ids_func);
g_test_add_func ("/fwupd/device{flags}", fu_device_flags_func);
g_test_add_func ("/fwupd/device{parent}", fu_device_parent_func);
g_test_add_func ("/fwupd/device{children}", fu_device_children_func);
g_test_add_func ("/fwupd/device{incorporate}", fu_device_incorporate_func);
if (g_test_slow ())
g_test_add_func ("/fwupd/device{poll}", fu_device_poll_func);