synapticsmst: Use FuDeviceLocker for all instances of remote control

This will make sure that remote control requests are always paired with
a close.
This commit is contained in:
Mario Limonciello 2018-08-13 00:46:36 -05:00 committed by Mario Limonciello
parent 8bba1ed2ef
commit 9818692336

View File

@ -250,6 +250,7 @@ synapticsmst_device_scan_cascade_device (SynapticsMSTDevice *device,
guint8 byte[4]; guint8 byte[4];
g_autoptr(SynapticsMSTConnection) connection = NULL; g_autoptr(SynapticsMSTConnection) connection = NULL;
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
if (priv->test_mode) if (priv->test_mode)
return TRUE; return TRUE;
@ -257,17 +258,18 @@ synapticsmst_device_scan_cascade_device (SynapticsMSTDevice *device,
/* reset */ /* reset */
priv->has_cascade = FALSE; priv->has_cascade = FALSE;
if (!synapticsmst_device_enable_remote_control (device, error)) { /* enable remote control and disable on exit */
g_prefix_error (error, locker = fu_device_locker_new_full (device,
"failed to enable remote control on tx_port %d: ", (FuDeviceLockerFunc) synapticsmst_device_enable_remote_control,
tx_port); (FuDeviceLockerFunc) synapticsmst_device_disable_remote_control,
error);
if (locker == NULL)
return FALSE; return FALSE;
}
connection = synapticsmst_common_new (priv->fd, layer, rad); connection = synapticsmst_common_new (priv->fd, layer, rad);
if (!synapticsmst_common_read (connection, REG_RC_CAP, byte, 1, &error_local)) { if (!synapticsmst_common_read (connection, REG_RC_CAP, byte, 1, &error_local)) {
g_debug ("No cascade device found: %s", error_local->message); g_debug ("No cascade device found: %s", error_local->message);
return synapticsmst_device_disable_remote_control (device, error); return TRUE;
} }
if (byte[0] & 0x04) { if (byte[0] & 0x04) {
if (!synapticsmst_common_read (connection, REG_VENDOR_ID, byte, 3, error)) { if (!synapticsmst_common_read (connection, REG_VENDOR_ID, byte, 3, error)) {
@ -280,13 +282,6 @@ synapticsmst_device_scan_cascade_device (SynapticsMSTDevice *device,
priv->has_cascade = TRUE; priv->has_cascade = TRUE;
} }
if (!synapticsmst_device_disable_remote_control (device, error)) {
g_prefix_error (error,
"failed to disable remote control on tx_port %d: ",
tx_port);
return FALSE;
}
return TRUE; return TRUE;
} }
@ -460,6 +455,7 @@ synapticsmst_device_enumerate_device (SynapticsMSTDevice *device,
guint8 byte[16]; guint8 byte[16];
guint8 bank; guint8 bank;
g_autoptr(SynapticsMSTConnection) connection = NULL; g_autoptr(SynapticsMSTConnection) connection = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
//FIXME? //FIXME?
if (!synapticsmst_device_open (device, error)) { if (!synapticsmst_device_open (device, error)) {
@ -468,21 +464,25 @@ synapticsmst_device_enumerate_device (SynapticsMSTDevice *device,
return FALSE; return FALSE;
} }
/* enable remote control */ /* enable remote control and disable on exit */
if (!synapticsmst_device_enable_remote_control (device, error)) locker = fu_device_locker_new_full (device,
(FuDeviceLockerFunc) synapticsmst_device_enable_remote_control,
(FuDeviceLockerFunc) synapticsmst_device_disable_remote_control,
error);
if (locker == NULL)
return FALSE; return FALSE;
/* read firmware version */ /* read firmware version */
connection = synapticsmst_common_new (priv->fd, priv->layer, priv->rad); connection = synapticsmst_common_new (priv->fd, priv->layer, priv->rad);
if (!synapticsmst_common_read (connection, REG_FIRMWARE_VERSION, if (!synapticsmst_common_read (connection, REG_FIRMWARE_VERSION,
byte, 3, error)) byte, 3, error))
goto error_disable_remote; return FALSE;
priv->version = g_strdup_printf ("%1d.%02d.%03d", byte[0], byte[1], byte[2]); priv->version = g_strdup_printf ("%1d.%02d.%03d", byte[0], byte[1], byte[2]);
/* read board ID */ /* read board ID */
if (!synapticsmst_device_read_board_id (device, connection, byte, error)) if (!synapticsmst_device_read_board_id (device, connection, byte, error))
goto error_disable_remote; return FALSE;
priv->board_id = (byte[0] << 8) | (byte[1]); priv->board_id = (byte[0] << 8) | (byte[1]);
g_debug ("BoardID %x", priv->board_id); g_debug ("BoardID %x", priv->board_id);
@ -490,27 +490,19 @@ synapticsmst_device_enumerate_device (SynapticsMSTDevice *device,
if (!synapticsmst_common_read (connection, REG_CHIP_ID, if (!synapticsmst_common_read (connection, REG_CHIP_ID,
byte, 2, error)) { byte, 2, error)) {
g_prefix_error (error, "failed to read chip id: "); g_prefix_error (error, "failed to read chip id: ");
goto error_disable_remote; return FALSE;
} }
priv->chip_id = (byte[0] << 8) | (byte[1]); priv->chip_id = (byte[0] << 8) | (byte[1]);
priv->chip_id_str = g_strdup_printf ("VMM%02x%02x", byte[0], byte[1]); priv->chip_id_str = g_strdup_printf ("VMM%02x%02x", byte[0], byte[1]);
if (!synapticsmst_create_guids (device, system_type, error)) if (!synapticsmst_create_guids (device, system_type, error))
goto error_disable_remote; return FALSE;
/* if running on panamera, check the active bank (for debugging logs) */ /* if running on panamera, check the active bank (for debugging logs) */
if (priv->chip_id > 0x5000 && if (priv->chip_id > 0x5000 &&
!synapticsmst_device_get_active_bank_panamera (device, &bank, error)) !synapticsmst_device_get_active_bank_panamera (device, &bank, error))
goto error_disable_remote;
/* disable remote control */
if (!synapticsmst_device_disable_remote_control (device, error))
return FALSE; return FALSE;
return TRUE; return TRUE;
error_disable_remote:
synapticsmst_device_disable_remote_control (device, NULL);
return FALSE;
} }
const gchar * const gchar *