From abd7c668337bfc5b5c5d0cede25fd5e36fd5a07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 27 Sep 2022 23:27:53 +0200 Subject: [PATCH] fp-device: Do not setup current action before updating temperature At every action we update the device temperature, and this can potentially lead to a failure, if the temperature is too hot. However in such case we were failing a task that we had just stolen, causing an error, tasks never returning and the device was left in an undefined state. So, just return early in case temperature is too hot, as we don't really need to have the current task or action set at this point because there's no active action to cancel yet. This was causing random errors when running tests under valgrind --- libfprint/fp-device.c | 32 ++++++++++++++++---------------- tests/test-fpi-device.c | 5 +++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/libfprint/fp-device.c b/libfprint/fp-device.c index 0d79fae1..17178d19 100644 --- a/libfprint/fp-device.c +++ b/libfprint/fp-device.c @@ -1172,10 +1172,6 @@ fp_device_enroll (FpDevice *device, } } - priv->current_action = FPI_DEVICE_ACTION_ENROLL; - priv->current_task = g_steal_pointer (&task); - setup_task_cancellable (device); - fpi_device_update_temp (device, TRUE); if (priv->temp_current == FP_TEMPERATURE_HOT) { @@ -1184,6 +1180,10 @@ fp_device_enroll (FpDevice *device, return; } + priv->current_action = FPI_DEVICE_ACTION_ENROLL; + priv->current_task = g_steal_pointer (&task); + setup_task_cancellable (device); + data = g_new0 (FpEnrollData, 1); data->print = g_object_ref_sink (template_print); data->enroll_progress_cb = progress_cb; @@ -1273,10 +1273,6 @@ fp_device_verify (FpDevice *device, return; } - priv->current_action = FPI_DEVICE_ACTION_VERIFY; - priv->current_task = g_steal_pointer (&task); - setup_task_cancellable (device); - fpi_device_update_temp (device, TRUE); if (priv->temp_current == FP_TEMPERATURE_HOT) { @@ -1285,6 +1281,10 @@ fp_device_verify (FpDevice *device, return; } + priv->current_action = FPI_DEVICE_ACTION_VERIFY; + priv->current_task = g_steal_pointer (&task); + setup_task_cancellable (device); + data = g_new0 (FpMatchData, 1); data->enrolled_print = g_object_ref (enrolled_print); data->match_cb = match_cb; @@ -1408,10 +1408,6 @@ fp_device_identify (FpDevice *device, return; } - priv->current_action = FPI_DEVICE_ACTION_IDENTIFY; - priv->current_task = g_steal_pointer (&task); - setup_task_cancellable (device); - fpi_device_update_temp (device, TRUE); if (priv->temp_current == FP_TEMPERATURE_HOT) { @@ -1420,6 +1416,10 @@ fp_device_identify (FpDevice *device, return; } + priv->current_action = FPI_DEVICE_ACTION_IDENTIFY; + priv->current_task = g_steal_pointer (&task); + setup_task_cancellable (device); + data = g_new0 (FpMatchData, 1); /* We cannot store the gallery directly, because the ptr array may not own * a reference to each print. Also, the caller could in principle modify the @@ -1533,10 +1533,6 @@ fp_device_capture (FpDevice *device, return; } - priv->current_action = FPI_DEVICE_ACTION_CAPTURE; - priv->current_task = g_steal_pointer (&task); - setup_task_cancellable (device); - fpi_device_update_temp (device, TRUE); if (priv->temp_current == FP_TEMPERATURE_HOT) { @@ -1545,6 +1541,10 @@ fp_device_capture (FpDevice *device, return; } + priv->current_action = FPI_DEVICE_ACTION_CAPTURE; + priv->current_task = g_steal_pointer (&task); + setup_task_cancellable (device); + priv->wait_for_finger = wait_for_finger; cls->capture (device); diff --git a/tests/test-fpi-device.c b/tests/test-fpi-device.c index 2b5a9dc1..f778eaa8 100644 --- a/tests/test-fpi-device.c +++ b/tests/test-fpi-device.c @@ -2388,6 +2388,11 @@ test_driver_identify_warmup_cooldown (void) g_assert_true (identify_data->called); g_assert_error (identify_data->error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_TOO_HOT); + /* Try to identify again, and ensure that we fail early */ + fp_device_identify_sync (device, prints, NULL, NULL, NULL, NULL, NULL, &error); + g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_TOO_HOT); + g_clear_error (&error); + /* Now, wait for it to cool down again; * WARM should be reached after about 2s * COLD after 5s but give it some more slack. */