Skip to content

Commit

Permalink
store the path in FuPluginData
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Limonciello committed Sep 12, 2017
1 parent fa5d5c8 commit 18fda40
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions plugins/thunderbolt-power/fu-plugin-thunderbolt-power.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUdevDevice, g_object_unref)
#endif

/* empirically mesaured amount of time for the TBT device to come and go */
#define TBT_NEW_DEVICE_TIMEOUT 2

struct FuPluginData {
GUdevClient *udev;
gchar *force_path;
gboolean needs_forcepower;
gboolean can_forcepower;
};

static gchar *
static void
fu_plugin_thunderbolt_power_get_path (FuPlugin *plugin)
{
FuPluginData *data = fu_plugin_get_data (plugin);
Expand All @@ -67,35 +68,33 @@ fu_plugin_thunderbolt_power_get_path (FuPlugin *plugin)
continue;
built_path = g_build_path ("/", basepath,
"force_power", NULL);
if (g_file_test (built_path, G_FILE_TEST_IS_REGULAR))
return g_steal_pointer (&built_path);
if (g_file_test (built_path, G_FILE_TEST_IS_REGULAR)) {
data->force_path = g_steal_pointer (&built_path);
return;
}
}

return NULL;
/* driver went away */
if (data->force_path)
g_free (data->force_path);
}

static gboolean
fu_plugin_thunderbolt_power_supported (FuPlugin *plugin)
{
g_autofree gchar *path = NULL;
path = fu_plugin_thunderbolt_power_get_path (plugin);
if (path != NULL) {
g_debug ("Detected force power support at %s", path);
return TRUE;
}
return FALSE;
FuPluginData *data = fu_plugin_get_data (plugin);
return (data->force_path != NULL)
}

static gboolean
fu_plugin_thunderbolt_power_set (FuPlugin *plugin, gboolean enable,
GError **error)
GError **error)
{
g_autofree gchar *path = NULL;
FuPluginData *data = fu_plugin_get_data (plugin);
gint fd;
gint ret;

path = fu_plugin_thunderbolt_power_get_path (plugin);
if (path == NULL) {
if (!fu_plugin_thunderbolt_power_supported (plugin)) {
g_set_error (error,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
Expand All @@ -104,7 +103,7 @@ fu_plugin_thunderbolt_power_set (FuPlugin *plugin, gboolean enable,
return FALSE;
}
g_debug ("Setting force power to %d", enable);
fd = g_open (path, O_WRONLY);
fd = g_open (data->force_path, O_WRONLY);
if (fd == -1) {
g_set_error (error,
FWUPD_ERROR,
Expand Down Expand Up @@ -148,8 +147,7 @@ udev_uevent_cb (GUdevClient *udev,

/* intel-wmi-thunderbolt has been loaded/unloaded */
if (g_str_equal (action, "change")) {
data->can_forcepower =
fu_plugin_thunderbolt_power_supported (plugin);
fu_plugin_thunderbolt_power_get_path (plugin);
fu_plugin_set_enabled (plugin, TRUE);
fu_plugin_recoldplug (plugin);
}
Expand All @@ -172,14 +170,16 @@ fu_plugin_init (FuPlugin *plugin)
data->needs_forcepower = TRUE;

/* determines whether to run device_registered */
data->can_forcepower = fu_plugin_thunderbolt_power_supported (plugin);
fu_plugin_thunderbolt_power_get_path (plugin);
}

void
fu_plugin_destroy (FuPlugin *plugin)
{
FuPluginData *data = fu_plugin_get_data (plugin);
g_object_unref (data->udev);
if (data->force_path)
g_free (data->force_path);
}

void
Expand All @@ -189,7 +189,7 @@ fu_plugin_device_registered (FuPlugin *plugin, FuDevice *device)

/* thunderbolt plugin */
if (g_strcmp0 (fu_device_get_plugin (device), "thunderbolt") == 0 &&
data->can_forcepower) {
fu_plugin_thunderbolt_power_supported (plugin)) {
if (data->needs_forcepower)
data->needs_forcepower = FALSE;
if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_INTERNAL)) {
Expand Down Expand Up @@ -251,7 +251,7 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
{
FuPluginData *data = fu_plugin_get_data (plugin);

if (!data->can_forcepower) {
if (!fu_plugin_thunderbolt_power_supported (plugin)) {
g_set_error (error,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
Expand Down

0 comments on commit 18fda40

Please sign in to comment.