Blob Blame History Raw
From 651cc37ee0409af767447f626f6a90db50c016b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Fri, 22 Nov 2019 18:39:02 +0100
Subject: [PATCH 061/181] drivers: Use SSM delayed actions when possible

---
 libfprint/drivers/uru4000.c | 72 ++++++++++++++-----------------------
 libfprint/drivers/vfs0050.c | 13 +------
 libfprint/fpi-ssm.c         |  3 +-
 3 files changed, 29 insertions(+), 59 deletions(-)

diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c
index 1deadd3..e15f1ca 100644
--- a/libfprint/drivers/uru4000.c
+++ b/libfprint/drivers/uru4000.c
@@ -829,26 +829,6 @@ enum rebootpwr_states {
   REBOOTPWR_NUM_STATES,
 };
 
-static void
-rebootpwr_pause_cb (FpDevice *dev,
-                    void     *data)
-{
-  FpiSsm *ssm = data;
-  FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev);
-
-  if (!--self->rebootpwr_ctr)
-    {
-      fp_err ("could not reboot device power");
-      fpi_ssm_mark_failed (ssm,
-                           fpi_device_error_new_msg (FP_DEVICE_ERROR,
-                                                     "Could not reboot device"));
-    }
-  else
-    {
-      fpi_ssm_jump_to_state (ssm, REBOOTPWR_GET_HWSTAT);
-    }
-}
-
 static void
 rebootpwr_run_state (FpiSsm *ssm, FpDevice *_dev)
 {
@@ -875,7 +855,17 @@ rebootpwr_run_state (FpiSsm *ssm, FpDevice *_dev)
       break;
 
     case REBOOTPWR_PAUSE:
-      fpi_device_add_timeout (_dev, 10, rebootpwr_pause_cb, ssm, NULL);
+      if (!--self->rebootpwr_ctr)
+        {
+          fp_err ("could not reboot device power");
+          fpi_ssm_mark_failed (ssm,
+                               fpi_device_error_new_msg (FP_DEVICE_ERROR,
+                                                         "Could not reboot device"));
+        }
+      else
+        {
+          fpi_ssm_jump_to_state_delayed (ssm, 10, REBOOTPWR_GET_HWSTAT);
+        }
       break;
     }
 }
@@ -916,30 +906,6 @@ enum powerup_states {
   POWERUP_NUM_STATES,
 };
 
-static void
-powerup_pause_cb (FpDevice *dev,
-                  void     *data)
-{
-  FpiSsm *ssm = data;
-  FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev);
-
-  if (!--self->powerup_ctr)
-    {
-      fp_err ("could not power device up");
-      fpi_ssm_mark_failed (ssm,
-                           fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
-                                                     "could not power device up"));
-    }
-  else if (!self->profile->auth_cr)
-    {
-      fpi_ssm_jump_to_state (ssm, POWERUP_SET_HWSTAT);
-    }
-  else
-    {
-      fpi_ssm_next_state (ssm);
-    }
-}
-
 static void
 powerup_run_state (FpiSsm *ssm, FpDevice *_dev)
 {
@@ -971,7 +937,21 @@ powerup_run_state (FpiSsm *ssm, FpDevice *_dev)
       break;
 
     case POWERUP_PAUSE:
-      fpi_device_add_timeout (_dev, 10, powerup_pause_cb, ssm, NULL);
+      if (!--self->powerup_ctr)
+        {
+          fp_err ("could not power device up");
+          fpi_ssm_mark_failed (ssm,
+                               fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
+                                                         "could not power device up"));
+        }
+      else if (!self->profile->auth_cr)
+        {
+          fpi_ssm_jump_to_state_delayed (ssm, POWERUP_SET_HWSTAT, 10);
+        }
+      else
+        {
+          fpi_ssm_next_state_delayed (ssm, 10);
+        }
       break;
 
     case POWERUP_CHALLENGE_RESPONSE:
diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c
index af70db5..22e9ae9 100644
--- a/libfprint/drivers/vfs0050.c
+++ b/libfprint/drivers/vfs0050.c
@@ -479,16 +479,6 @@ receive_callback (FpiUsbTransfer *transfer, FpDevice *device,
     }
 }
 
-/* SSM stub to prepare device to another scan after orange light was on */
-static void
-another_scan (FpDevice *dev,
-              void     *data)
-{
-  FpiSsm *ssm = data;
-
-  fpi_ssm_jump_to_state (ssm, SSM_TURN_ON);
-}
-
 /* Main SSM loop */
 static void
 activate_ssm (FpiSsm *ssm, FpDevice *dev)
@@ -637,8 +627,7 @@ activate_ssm (FpiSsm *ssm, FpDevice *dev)
 
     case SSM_WAIT_ANOTHER_SCAN:
       /* Orange light is on now */
-      fpi_device_add_timeout (dev, VFS_SSM_ORANGE_TIMEOUT,
-                              another_scan, ssm, NULL);
+      fpi_ssm_jump_to_state_delayed (ssm, SSM_TURN_ON, VFS_SSM_ORANGE_TIMEOUT);
       break;
 
     default:
diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c
index e2cb48a..19712ef 100644
--- a/libfprint/fpi-ssm.c
+++ b/libfprint/fpi-ssm.c
@@ -168,6 +168,8 @@ fpi_ssm_free (FpiSsm *machine)
   if (!machine)
     return;
 
+  BUG_ON (machine->timeout != NULL);
+
   if (machine->ssm_data_destroy)
     g_clear_pointer (&machine->ssm_data, machine->ssm_data_destroy);
   g_clear_pointer (&machine->error, g_error_free);
@@ -250,7 +252,6 @@ void
 fpi_ssm_mark_completed (FpiSsm *machine)
 {
   BUG_ON (machine->completed);
-  BUG_ON (machine->timeout);
   BUG_ON (machine->timeout != NULL);
 
   g_clear_pointer (&machine->timeout, g_source_destroy);
-- 
2.24.1