summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2019-06-05 14:28:00 -0700
committerCommit Bot <commit-bot@chromium.org>2019-09-28 17:00:32 +0000
commit3c1215dadc3a279925a17f55bdf0cb8863c41626 (patch)
tree5eee8e879aed7545f7d860119d5867c5455f730f
parent19b8749c0915278171acfd83495d5a73bb359385 (diff)
downloadchrome-ec-3c1215dadc3a279925a17f55bdf0cb8863c41626.tar.gz
fpsensor: Deinit the sensor before clearing the context
The opaque context contains sensor state that we can't nuke from underneath the sensor library. Calling fp_sensor_deinit will release this context and allow us to safely clear the context. BRANCH=none BUG=b:124773209 TEST="fpenroll" followed by "fpclear" in the FP console TEST=On nocturne, in the UI, enroll finger, log out, and log in => then lock and unlock with finger TEST=make buildall -j Change-Id: I3e25bdf7eaaf99f3801547e11a6c524f924f4726 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1647294 Reviewed-by: Nicolas Norvez <norvez@chromium.org> Commit-Queue: Yicheng Li <yichengli@chromium.org> Tested-by: Yicheng Li <yichengli@chromium.org>
-rw-r--r--common/fpsensor/fpsensor.c20
-rw-r--r--common/fpsensor/fpsensor_state.c19
-rw-r--r--common/mock/README.md2
-rw-r--r--common/mock/build.mk1
-rw-r--r--common/mock/fpsensor_mock.c17
-rw-r--r--fuzz/host_command_fuzz.mocklist1
-rw-r--r--include/fpsensor.h3
-rw-r--r--include/fpsensor_state.h7
-rw-r--r--test/fpsensor.mocklist7
9 files changed, 65 insertions, 12 deletions
diff --git a/common/fpsensor/fpsensor.c b/common/fpsensor/fpsensor.c
index d0bc54faba..11060baf6c 100644
--- a/common/fpsensor/fpsensor.c
+++ b/common/fpsensor/fpsensor.c
@@ -243,8 +243,7 @@ void fp_task(void)
if (mode & FP_MODE_ANY_WAIT_IRQ) {
gpio_enable_interrupt(GPIO_FPS_INT);
} else if (mode & FP_MODE_RESET_SENSOR) {
- fp_clear_context();
- fp_sensor_init();
+ fp_reset_and_clear_context();
sensor_mode &= ~FP_MODE_RESET_SENSOR;
} else {
fp_sensor_low_power();
@@ -602,7 +601,8 @@ static enum ec_error_list fp_console_action(uint32_t mode)
uint32_t mode_output = 0;
int rc = 0;
- CPRINTS("Waiting for finger ...");
+ if (!(sensor_mode & FP_MODE_RESET_SENSOR))
+ CPRINTS("Waiting for finger ...");
rc = fp_set_sensor_mode(mode, &mode_output);
@@ -709,8 +709,18 @@ DECLARE_CONSOLE_COMMAND(fpmatch, command_fpmatch, NULL,
int command_fpclear(int argc, char **argv)
{
- fp_clear_context();
- return EC_SUCCESS;
+ /*
+ * We intentionally run this on the fp_task so that we use the
+ * same code path as host commands.
+ */
+ enum ec_error_list rc = fp_console_action(FP_MODE_RESET_SENSOR);
+
+ if (rc < 0)
+ CPRINTS("Failed to clear fingerprint context: %d", rc);
+
+ atomic_read_clear(&fp_events);
+
+ return rc;
}
DECLARE_CONSOLE_COMMAND(fpclear, command_fpclear, NULL,
"Clear fingerprint sensor context");
diff --git a/common/fpsensor/fpsensor_state.c b/common/fpsensor/fpsensor_state.c
index 7474634487..bfbf0c6cb5 100644
--- a/common/fpsensor/fpsensor_state.c
+++ b/common/fpsensor/fpsensor_state.c
@@ -55,7 +55,12 @@ void fp_clear_finger_context(int idx)
always_memset(fp_template[idx], 0, sizeof(fp_template[0]));
}
-void fp_clear_context(void)
+/**
+ * @warning |fp_buffer| contains data used by the matching algorithm that must
+ * be released by calling fp_sensor_deinit() first. Call
+ * fp_reset_and_clear_context instead of calling this directly.
+ */
+static void _fp_clear_context(void)
{
int idx;
@@ -66,7 +71,15 @@ void fp_clear_context(void)
always_memset(user_id, 0, sizeof(user_id));
for (idx = 0; idx < FP_MAX_FINGER_COUNT; idx++)
fp_clear_finger_context(idx);
- /* TODO maybe shutdown and re-init the private libraries ? */
+}
+
+void fp_reset_and_clear_context(void)
+{
+ if (fp_sensor_deinit() != EC_SUCCESS)
+ CPRINTS("Failed to deinit sensor");
+ _fp_clear_context();
+ if (fp_sensor_init() != EC_SUCCESS)
+ CPRINTS("Failed to init sensor");
}
int fp_get_next_event(uint8_t *out)
@@ -187,7 +200,7 @@ static int fp_command_context(struct host_cmd_handler_args *args)
{
const struct ec_params_fp_context *params = args->params;
- fp_clear_context();
+ fp_reset_and_clear_context();
memcpy(user_id, params->userid, sizeof(user_id));
diff --git a/common/mock/README.md b/common/mock/README.md
index e1962651a6..0044856639 100644
--- a/common/mock/README.md
+++ b/common/mock/README.md
@@ -43,7 +43,7 @@ Example `.mocklist`:
#define CONFIG_TEST_MOCK_LIST \
MOCK(ROLLBACK) \
- MOCK(FP_SENSOR)
+ MOCK(FPSENSOR)
```
If you need additional mock control functionality, you may need to include
diff --git a/common/mock/build.mk b/common/mock/build.mk
index 037718d3bb..e89c658968 100644
--- a/common/mock/build.mk
+++ b/common/mock/build.mk
@@ -4,4 +4,5 @@
# See common/mock/README.md for more information.
+mock-$(HAS_MOCK_FPSENSOR) += fpsensor_mock.o
mock-$(HAS_MOCK_ROLLBACK) += rollback_mock.o
diff --git a/common/mock/fpsensor_mock.c b/common/mock/fpsensor_mock.c
new file mode 100644
index 0000000000..7ace5c2f43
--- /dev/null
+++ b/common/mock/fpsensor_mock.c
@@ -0,0 +1,17 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+
+/* No-op mocks */
+int fp_sensor_init(void)
+{
+ return EC_SUCCESS;
+}
+
+int fp_sensor_deinit(void)
+{
+ return EC_SUCCESS;
+}
diff --git a/fuzz/host_command_fuzz.mocklist b/fuzz/host_command_fuzz.mocklist
index d84275532e..97b5e74c73 100644
--- a/fuzz/host_command_fuzz.mocklist
+++ b/fuzz/host_command_fuzz.mocklist
@@ -4,4 +4,5 @@
*/
#define CONFIG_TEST_MOCK_LIST \
+ MOCK(FPSENSOR) \
MOCK(ROLLBACK)
diff --git a/include/fpsensor.h b/include/fpsensor.h
index 9a3d2c4e21..ce8abaf870 100644
--- a/include/fpsensor.h
+++ b/include/fpsensor.h
@@ -28,6 +28,9 @@
/* Initialize the connected sensor hardware and put it in a low power mode. */
int fp_sensor_init(void);
+/* De-initialize the sensor hardware. */
+int fp_sensor_deinit(void);
+
/*
* Fill the 'ec_response_fp_info' buffer with the sensor information
* as required by the EC_CMD_FP_INFO host command.
diff --git a/include/fpsensor_state.h b/include/fpsensor_state.h
index 8b5ab6ef0c..76b88d79b8 100644
--- a/include/fpsensor_state.h
+++ b/include/fpsensor_state.h
@@ -78,10 +78,11 @@ void fp_task_simulate(void);
*/
void fp_clear_finger_context(int idx);
-/*
- * Clear all fingerprint templates associated with the current user id.
+/**
+ * Clear all fingerprint templates associated with the current user id and
+ * reset the sensor.
*/
-void fp_clear_context(void);
+void fp_reset_and_clear_context(void);
/*
* Get the next FP event.
diff --git a/test/fpsensor.mocklist b/test/fpsensor.mocklist
new file mode 100644
index 0000000000..9bed932526
--- /dev/null
+++ b/test/fpsensor.mocklist
@@ -0,0 +1,7 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+ #define CONFIG_TEST_MOCK_LIST \
+ MOCK(FPSENSOR)