From a855c0cc7944c474936c104ee77959db7185cd3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 26 Nov 2019 16:18:14 +0100 Subject: [PATCH] fpi-ssm: Take ownership of the SSM when completing it When a machine is completed, we automatically free it since we can't consider it valid anymore since this point. Update the drivers not to free the SSM on completion callback anymore. --- libfprint/drivers/aes1610.c | 2 -- libfprint/drivers/aes2501.c | 2 -- libfprint/drivers/aes2550.c | 2 -- libfprint/drivers/aesx660.c | 3 --- libfprint/drivers/elan.c | 4 ---- libfprint/drivers/etes603.c | 6 ------ libfprint/drivers/synaptics/synaptics.c | 1 - libfprint/drivers/upeksonly.c | 2 -- libfprint/drivers/upektc.c | 2 -- libfprint/drivers/upektc_img.c | 3 --- libfprint/drivers/upekts.c | 4 ---- libfprint/drivers/uru4000.c | 1 - libfprint/drivers/vcom5s.c | 1 - libfprint/drivers/vfs0050.c | 2 -- libfprint/drivers/vfs101.c | 2 -- libfprint/drivers/vfs301.c | 2 -- libfprint/drivers/vfs5011.c | 2 -- libfprint/fpi-ssm.c | 15 +++++++++++---- 18 files changed, 11 insertions(+), 45 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index c9742e9..0326565 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -710,7 +710,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) { start_finger_detection (dev); } - fpi_ssm_free (ssm); } static void @@ -774,7 +773,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) if (!error) start_finger_detection (dev); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index fad0218..1b59c56 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -575,7 +575,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) { start_finger_detection (dev); } - fpi_ssm_free (ssm); } static void @@ -806,7 +805,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *dev, GError *error) if (!error) start_finger_detection (FP_IMAGE_DEVICE (dev)); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 2abcf76..b95b053 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -391,7 +391,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) { start_finger_detection (dev); } - fpi_ssm_free (ssm); } static void @@ -537,7 +536,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) if (!error) start_finger_detection (dev); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index 8ad4c63..3f13252 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -215,7 +215,6 @@ finger_det_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) fp_dbg ("Finger detection completed"); fpi_image_device_report_finger_status (dev, TRUE); - fpi_ssm_free (ssm); if (priv->deactivating) { @@ -466,7 +465,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *device, GError *error) FpiDeviceAesX660Private *priv = fpi_device_aes_x660_get_instance_private (self); fp_dbg ("Capture completed"); - fpi_ssm_free (ssm); if (priv->deactivating) { @@ -672,7 +670,6 @@ static void activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) { fpi_image_device_activate_complete (FP_IMAGE_DEVICE (_dev), error); - fpi_ssm_free (ssm); if (!error) start_finger_detection (FP_IMAGE_DEVICE (_dev)); diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 961366e..5e80be5 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -479,7 +479,6 @@ stop_capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) G_DEBUG_HERE (); - fpi_ssm_free (ssm); /* The device is inactive at this point. */ self->dev_state = FP_IMAGE_DEVICE_STATE_INACTIVE; @@ -606,7 +605,6 @@ capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) fpi_image_device_session_error (dev, error); } - fpi_ssm_free (ssm); } static void @@ -789,7 +787,6 @@ calibrate_complete (FpiSsm *ssm, FpDevice *dev, GError *error) elan_capture (dev); } - fpi_ssm_free (ssm); } static void @@ -886,7 +883,6 @@ activate_complete (FpiSsm *ssm, FpDevice *dev, GError *error) fpi_image_device_activate_complete (idev, error); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index 5c990da..55f0139 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -789,7 +789,6 @@ m_exit_complete (FpiSsm *ssm, FpDevice *dev, GError *error) else fp_dbg ("The device is now in idle state"); fpi_image_device_deactivate_complete (idev, error); - fpi_ssm_free (ssm); } static void @@ -911,7 +910,6 @@ m_capture_complete (FpiSsm *ssm, FpDevice *dev, GError *error) g_error_free (error); } } - fpi_ssm_free (ssm); if (self->is_active == TRUE) { @@ -1061,7 +1059,6 @@ m_finger_complete (FpiSsm *ssm, FpDevice *dev, GError *error) self->is_active = FALSE; } - fpi_ssm_free (ssm); } static void @@ -1265,7 +1262,6 @@ m_tunevrb_complete (FpiSsm *ssm, FpDevice *dev, GError *error) if (!self->is_active) m_exit_start (idev); - fpi_ssm_free (ssm); } /* @@ -1409,7 +1405,6 @@ m_tunedc_complete (FpiSsm *ssm, FpDevice *dev, GError *error) if (!self->is_active) m_exit_start (idev); - fpi_ssm_free (ssm); } static void @@ -1543,7 +1538,6 @@ m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error) reset_param (FPI_DEVICE_ETES603 (dev)); fpi_image_device_session_error (idev, error); } - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/synaptics/synaptics.c b/libfprint/drivers/synaptics/synaptics.c index a2286b2..4932d01 100644 --- a/libfprint/drivers/synaptics/synaptics.c +++ b/libfprint/drivers/synaptics/synaptics.c @@ -290,7 +290,6 @@ cmd_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error) } self->cmd_complete_on_removal = FALSE; g_clear_pointer (&self->cmd_complete_error, g_error_free); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index ec81375..e1cd7e5 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -1380,7 +1380,6 @@ loopsm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) FpImageDevice *dev = FP_IMAGE_DEVICE (_dev); FpiDeviceUpeksonly *self = FPI_DEVICE_UPEKSONLY (_dev); - fpi_ssm_free (ssm); if (self->deactivating) { @@ -1401,7 +1400,6 @@ initsm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) FpImageDevice *dev = FP_IMAGE_DEVICE (_dev); FpiDeviceUpeksonly *self = FPI_DEVICE_UPEKSONLY (_dev); - fpi_ssm_free (ssm); fpi_image_device_activate_complete (dev, error); if (error) return; diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index ff5b49b..e1254ce 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -157,7 +157,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) if (!error) start_finger_detection (dev); - fpi_ssm_free (ssm); } @@ -345,7 +344,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) else start_finger_detection (dev); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 1e06b90..28a709f 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -389,7 +389,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error_arg) g_autoptr(GError) error = error_arg; - fpi_ssm_free (ssm); /* Note: We assume that the error is a cancellation in the deactivation case */ if (self->deactivating) @@ -470,7 +469,6 @@ deactivate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (_dev); fp_dbg ("Deactivate completed"); - fpi_ssm_free (ssm); self->deactivating = FALSE; fpi_image_device_deactivate_complete (dev, error); @@ -601,7 +599,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) { FpImageDevice *dev = FP_IMAGE_DEVICE (_dev); - fpi_ssm_free (ssm); fpi_image_device_activate_complete (dev, error); if (!error) diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index b3481aa..4bc6556 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -990,7 +990,6 @@ enroll_stop_deinit_cb (FpiSsm *ssm, FpDevice *dev, GError *error) fp_warn ("Error deinitializing: %s", error->message); fpi_device_enroll_complete (dev, data->print, data->error); - fpi_ssm_free (ssm); } static void @@ -1217,7 +1216,6 @@ enroll_started (FpiSsm *ssm, FpDevice *dev, GError *error) else enroll_iterate (dev); - fpi_ssm_free (ssm); } static void @@ -1256,7 +1254,6 @@ verify_stop_deinit_cb (FpiSsm *ssm, FpDevice *dev, GError *error) fp_warn ("Error deinitializing: %s", error->message); fpi_device_verify_complete (dev, data->res, NULL, data->error); - fpi_ssm_free (ssm); } static void @@ -1540,7 +1537,6 @@ verify_started (FpiSsm *ssm, FpDevice *dev, GError *error) upekdev->first_verify_iteration = TRUE; verify_iterate (dev); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index f248411..89328d0 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -789,7 +789,6 @@ imaging_complete (FpiSsm *ssm, FpDevice *dev, GError *error) { FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev); - fpi_ssm_free (ssm); /* Report error before exiting imaging loop - the error handler * can request state change, which needs to be postponed to end of diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index 0e10252..edd2dd4 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -301,7 +301,6 @@ loopsm_complete (FpiSsm *ssm, FpDevice *dev, GError *error) FpImageDevice *imgdev = FP_IMAGE_DEVICE (dev); FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev); - fpi_ssm_free (ssm); g_object_unref (self->capture_img); self->capture_img = NULL; self->loop_running = FALSE; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 4dc6782..1be272b 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -669,7 +669,6 @@ dev_activate_callback (FpiSsm *ssm, FpDevice *dev, GError *error) g_error_free (error); } - fpi_ssm_free (ssm); } /* Activate device */ @@ -710,7 +709,6 @@ dev_open_callback (FpiSsm *ssm, FpDevice *dev, GError *error) { /* Notify open complete */ fpi_image_device_open_complete (FP_IMAGE_DEVICE (dev), error); - fpi_ssm_free (ssm); } /* Open device */ diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 37e083c..9ca1b0a 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -960,7 +960,6 @@ m_loop_complete (FpiSsm *ssm, FpDevice *dev, GError *error) self->active = FALSE; - fpi_ssm_free (ssm); } /* Init ssm states */ @@ -1268,7 +1267,6 @@ m_init_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) } /* Free sequential state machine */ - fpi_ssm_free (ssm); } /* Activate device */ diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 8fdac7c..7219792 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -168,7 +168,6 @@ m_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) g_error_free (error); } /* Free sequential state machine */ - fpi_ssm_free (ssm); } /* Exec init sequential state machine */ @@ -201,7 +200,6 @@ m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error) } /* Free sequential state machine */ - fpi_ssm_free (ssm); } /* Activate device */ diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 9eddca7..007e486 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -745,7 +745,6 @@ activate_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) submit_image (ssm, self, dev); fpi_image_device_report_finger_status (dev, FALSE); } - fpi_ssm_free (ssm); self->loop_running = FALSE; @@ -793,7 +792,6 @@ open_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) self->init_sequence.receive_buf = NULL; fpi_image_device_open_complete (dev, error); - fpi_ssm_free (ssm); } static void diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 1569be8..a614860 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -51,6 +51,7 @@ * * To start a ssm, you pass in a completion callback function to fpi_ssm_start() * which gets called when the ssm completes (both on error and on failure). + * Starting a ssm also takes ownership of it. * * To iterate to the next state, call fpi_ssm_next_state(). It is legal to * attempt to iterate beyond the final state - this is equivalent to marking @@ -58,6 +59,7 @@ * * To mark successful completion of a SSM, either iterate beyond the final * state or call fpi_ssm_mark_completed() from any state. + * This will also invalidate the machine, freeing it. * * To mark failed completion of a SSM, call fpi_ssm_mark_failed() from any * state. You must pass a non-zero error code. @@ -125,7 +127,6 @@ fpi_ssm_new (FpDevice *dev, * @ssm_data_destroy: (nullable): #GDestroyNotify for @ssm_data * * Sets @machine's data (freeing the existing data, if any). - * */ void fpi_ssm_set_data (FpiSsm *machine, @@ -182,12 +183,16 @@ __ssm_call_handler (FpiSsm *machine) /** * fpi_ssm_start: - * @ssm: an #FpiSsm state machine + * @ssm: (transfer full): an #FpiSsm state machine * @callback: the #FpiSsmCompletedCallback callback to call on completion * * Starts a state machine. You can also use this function to restart * a completed or failed state machine. The @callback will be called * on completion. + * + * Note that @ssm will be stolen when this function is called. + * So that all associated data will be free'ed automatically, after the + * @callback is ran. */ void fpi_ssm_start (FpiSsm *ssm, FpiSsmCompletedCallback callback) @@ -210,7 +215,6 @@ __subsm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) fpi_ssm_mark_failed (parent, error); else fpi_ssm_next_state (parent); - fpi_ssm_free (ssm); } /** @@ -253,6 +257,7 @@ fpi_ssm_mark_completed (FpiSsm *machine) machine->callback (machine, machine->dev, error); } + fpi_ssm_free (machine); } /** @@ -260,7 +265,7 @@ fpi_ssm_mark_completed (FpiSsm *machine) * @machine: an #FpiSsm state machine * @error: a #GError * - * Mark a state machine as failed with @error as the error code. + * Mark a state machine as failed with @error as the error code, completing it. */ void fpi_ssm_mark_failed (FpiSsm *machine, GError *error) @@ -305,6 +310,8 @@ fpi_ssm_next_state (FpiSsm *machine) * @state: the state to jump to * * Jump to the @state state, bypassing intermediary states. + * If @state is the last state, the machine won't be completed unless + * fpi_ssm_mark_completed() isn't explicitly called. */ void fpi_ssm_jump_to_state (FpiSsm *machine, int state)