From 19732341d6b0accddb87786858580eba3889e7ad Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 8 Aug 2019 13:42:31 +0200
Subject: [PATCH] lib: Fix overwriting action after deactivating callback

If one of the callbacks called from fpi_imgdev_deactivate_complete()
was reactivating the device, then we would be overwriting whichever
"action" got set in the callback, leading to
fpi_imgdev_activate_complete() failing as it doesn't handle the "none"
action.

Reset the action before calling the callbacks.
---
 libfprint/fpi-dev-img.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libfprint/fpi-dev-img.c b/libfprint/fpi-dev-img.c
index a7c2410..b9d2783 100644
--- a/libfprint/fpi-dev-img.c
+++ b/libfprint/fpi-dev-img.c
@@ -485,9 +485,15 @@ void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status)
  */
 void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev)
 {
+	enum fp_imgdev_action action;
+
 	G_DEBUG_HERE();
 
-	switch (imgdev->action) {
+	action = imgdev->action;
+	imgdev->action = IMG_ACTION_NONE;
+	imgdev->action_state = 0;
+
+	switch (action) {
 	case IMG_ACTION_ENROLL:
 		fpi_drvcb_enroll_stopped(FP_DEV(imgdev));
 		break;
@@ -504,9 +510,6 @@ void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev)
 		fp_err("unhandled action %d", imgdev->action);
 		break;
 	}
-
-	imgdev->action = IMG_ACTION_NONE;
-	imgdev->action_state = 0;
 }
 
 int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev)