egismoc: Ensure that the command callback is after SSM is completed

We need to make sure that we won't trigger a callback when a SSM is
already in progress or we may end up overwriting it
This commit is contained in:
Marco Trevisan (Treviño)
2024-02-19 15:41:15 +01:00
parent 226b6abfab
commit 6767cd1a4f

View File

@@ -181,7 +181,10 @@ egismoc_cmd_receive_cb (FpiUsbTransfer *transfer,
gpointer userdata, gpointer userdata,
GError *error) GError *error)
{ {
g_autofree guchar *buffer = NULL;
CommandData *data = userdata; CommandData *data = userdata;
SynCmdMsgCallback callback;
gssize actual_length;
fp_dbg ("Command receive callback"); fp_dbg ("Command receive callback");
@@ -197,10 +200,18 @@ egismoc_cmd_receive_cb (FpiUsbTransfer *transfer,
return; return;
} }
if (data->callback) /* Let's complete the previous ssm and then handle the callback, so that
data->callback (device, transfer->buffer, transfer->actual_length, NULL); * we are sure that we won't start a transfer or a new command while there is
* another one still ongoing
*/
callback = data->callback;
buffer = g_steal_pointer (&transfer->buffer);
actual_length = transfer->actual_length;
fpi_ssm_mark_completed (transfer->ssm); fpi_ssm_mark_completed (transfer->ssm);
if (callback)
callback (device, buffer, actual_length, NULL);
} }
static void static void