From b9ac0aa179ae6846072da7f61e226076c638e9c6 Mon Sep 17 00:00:00 2001 From: Mika Westerberg Date: Mon, 6 Aug 2018 14:30:24 +0300 Subject: [PATCH] thunderbolt: Handle -EAGAIN from nvm_version elsewhere as well There are other places in the plugin where we read nvm_version and it can return -EAGAIN as well. To make sure it works consistenly accross the plugin factor reading nvm_version to a helper function and use instead. Signed-off-by: Mika Westerberg --- plugins/thunderbolt/fu-plugin-thunderbolt.c | 33 ++++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/plugins/thunderbolt/fu-plugin-thunderbolt.c b/plugins/thunderbolt/fu-plugin-thunderbolt.c index 3fd7987f4..8a5f4b853 100644 --- a/plugins/thunderbolt/fu-plugin-thunderbolt.c +++ b/plugins/thunderbolt/fu-plugin-thunderbolt.c @@ -174,6 +174,24 @@ fu_plugin_thunderbolt_find_nvmem (GUdevDevice *udevice, return NULL; } +static const gchar * +fu_plugin_thunderbolt_udev_get_version (GUdevDevice *udevice) +{ + const gchar *version = NULL; + + for (guint i = 0; i < 50; i++) { + version = g_udev_device_get_sysfs_attr (udevice, "nvm_version"); + if (version != NULL) + break; + g_debug ("Attempt %u: Failed to read NVM version", i); + if (errno != EAGAIN) + break; + g_usleep (TBT_NVM_RETRY_TIMEOUT * 1000); + } + + return version; +} + static gboolean fu_plugin_thunderbolt_is_native (GUdevDevice *udevice, gboolean *is_native, GError **error) { @@ -285,15 +303,8 @@ fu_plugin_thunderbolt_add (FuPlugin *plugin, GUdevDevice *device) dev = fu_device_new (); is_host = fu_plugin_thunderbolt_is_host (device); - for (guint i = 0; i < 50; i++) { - version_raw = g_udev_device_get_sysfs_attr (device, "nvm_version"); - if (version_raw != NULL) - break; - g_debug ("Attempt %u: Failed to read NVM version", i); - if (errno != EAGAIN) - break; - g_usleep (TBT_NVM_RETRY_TIMEOUT * 1000); - } + + version_raw = fu_plugin_thunderbolt_udev_get_version (device); /* test for safe mode */ version = fu_plugin_thunderbolt_parse_version (version_raw); if (is_host && version == NULL) { @@ -413,7 +424,7 @@ fu_plugin_thunderbolt_change (FuPlugin *plugin, GUdevDevice *device) return; } - version = g_udev_device_get_sysfs_attr (device, "nvm_version"); + version = fu_plugin_thunderbolt_udev_get_version (device); fu_device_set_version (dev, version); } @@ -626,7 +637,7 @@ on_wait_for_device_added (FuPlugin *plugin, /* make sure the version is correct, might have changed * after update. */ - version = g_udev_device_get_sysfs_attr (device, "nvm_version"); + version = fu_plugin_thunderbolt_udev_get_version (device); fu_device_set_version (dev, version); id = fu_plugin_thunderbolt_gen_id (device);