Blame SOURCES/0177-image-device-Avoid-invalid-state-transition-on-cance.patch

73b847
From c16f8101e29dd93e846c90574b68677c8e9ab0b6 Mon Sep 17 00:00:00 2001
73b847
From: Benjamin Berg <bberg@redhat.com>
73b847
Date: Wed, 15 Jan 2020 14:48:06 +0100
73b847
Subject: [PATCH 177/181] image-device: Avoid invalid state transition on
73b847
 cancellation
73b847
73b847
Fixes: #226
73b847
---
73b847
 libfprint/drivers/elan.c     |  2 --
73b847
 libfprint/fpi-image-device.c | 18 +++++++++++++++---
73b847
 2 files changed, 15 insertions(+), 5 deletions(-)
73b847
73b847
diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c
73b847
index 1c2a7a3..084e4bd 100644
73b847
--- a/libfprint/drivers/elan.c
73b847
+++ b/libfprint/drivers/elan.c
73b847
@@ -585,8 +585,6 @@ capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
73b847
 
73b847
   G_DEBUG_HERE ();
73b847
 
73b847
-  /* XXX: cancellation was specially handled by doing nothing! */
73b847
-
73b847
   /* either max frames captured or timed out waiting for the next frame */
73b847
   if (!error ||
73b847
       (g_error_matches (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_TIMED_OUT) &&
73b847
diff --git a/libfprint/fpi-image-device.c b/libfprint/fpi-image-device.c
73b847
index 888c931..b5747f6 100644
73b847
--- a/libfprint/fpi-image-device.c
73b847
+++ b/libfprint/fpi-image-device.c
73b847
@@ -428,7 +428,9 @@ fpi_image_device_retry_scan (FpImageDevice *self, FpDeviceRetry retry)
73b847
  * @error: The #GError to report
73b847
  *
73b847
  * Report an error while interacting with the device. This effectively
73b847
- * aborts the current ongoing action.
73b847
+ * aborts the current ongoing action. Note that doing so will result in
73b847
+ * the deactivation handler to be called and this function must not be
73b847
+ * used to report an error during deactivation.
73b847
  */
73b847
 void
73b847
 fpi_image_device_session_error (FpImageDevice *self, GError *error)
73b847
@@ -455,10 +457,20 @@ fpi_image_device_session_error (FpImageDevice *self, GError *error)
73b847
           return;
73b847
         }
73b847
     }
73b847
+  else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
73b847
+           fpi_device_action_is_cancelled (FP_DEVICE (self)))
73b847
+    {
73b847
+      /* Ignore cancellation errors here, as we will explicitly deactivate
73b847
+       * anyway (or, may already have done so at this point).
73b847
+       */
73b847
+      g_debug ("Driver reported a cancellation error, this is expected but not required. Ignoring.");
73b847
+      g_clear_error (&error);
73b847
+      return;
73b847
+    }
73b847
   else if (priv->state == FPI_IMAGE_DEVICE_STATE_INACTIVE)
73b847
     {
73b847
-      g_warning ("Driver reported session error; translating to deactivation failure.");
73b847
-      fpi_image_device_deactivate_complete (self, error);
73b847
+      g_warning ("Driver reported session error while deactivating already, ignoring. This indicates a driver bug.");
73b847
+      g_clear_error (&error);
73b847
       return;
73b847
     }
73b847
 
73b847
-- 
73b847
2.24.1
73b847