* [PATCH 0/4] Add FPC1540 fingerprint sensor support through QSEE
@ 2026-11-24 17:42 Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 1/4] firmware: qcom: scm: Add QSEE app start, shutdown and services image load Armandas Kvietkus via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Armandas Kvietkus via B4 Relay @ 2026-11-24 17:42 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Arnd Bergmann, Greg Kroah-Hartman
Cc: linux-arm-msm, linux-kernel, devicetree, linux-doc,
Armandas Kvietkus
On some Qualcomm phones the FPC1540 is driven by a QSEE app and Linux
only has to power the sensor, load the app and pass commands to it.
The first patch adds the qcom_scm calls to start and stop an app and to
load a services image. The rest adds the binding and the driver, which
exposes the app to userspace through /dev/fpc_tee.
---
Armandas Kvietkus (4):
firmware: qcom: scm: Add QSEE app start, shutdown and services image load
dt-bindings: vendor-prefixes: Add Fingerprint Cards AB
dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app
misc: Add FPC1540 fingerprint sensor driver for QSEE apps
.../devicetree/bindings/misc/fpc,fpc1540-tee.yaml | 74 +++
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
Documentation/userspace-api/ioctl/ioctl-number.rst | 2 +
MAINTAINERS | 8 +
drivers/firmware/qcom/qcom_scm.c | 83 ++++
drivers/misc/Kconfig | 10 +
drivers/misc/Makefile | 1 +
drivers/misc/fpc1540-tee.c | 512 +++++++++++++++++++++
include/linux/firmware/qcom/qcom_scm.h | 23 +
include/uapi/linux/fpc1540-tee.h | 20 +
10 files changed, 735 insertions(+)
---
base-commit: ef922b721a5e99348fc1f5801fdeb427ee14ee9f
change-id: 20261124-fpc1540-tee-c89b3527e72a
Best regards,
--
Armandas Kvietkus <armandas.kvietkus@proton.me>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] firmware: qcom: scm: Add QSEE app start, shutdown and services image load
2026-11-24 17:42 [PATCH 0/4] Add FPC1540 fingerprint sensor support through QSEE Armandas Kvietkus via B4 Relay
@ 2026-11-24 17:43 ` Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 2/4] dt-bindings: vendor-prefixes: Add Fingerprint Cards AB Armandas Kvietkus via B4 Relay
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Armandas Kvietkus via B4 Relay @ 2026-11-24 17:43 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Arnd Bergmann, Greg Kroah-Hartman
Cc: linux-arm-msm, linux-kernel, devicetree, linux-doc,
Armandas Kvietkus
From: Armandas Kvietkus <armandas.kvietkus@proton.me>
qseecom can only talk to apps that are already running in QSEE. Add
the app manager calls to start an app from an image, shut it down and
load a services image such as cmnlib64.
Signed-off-by: Armandas Kvietkus <armandas.kvietkus@proton.me>
---
drivers/firmware/qcom/qcom_scm.c | 83 ++++++++++++++++++++++++++++++++++
include/linux/firmware/qcom/qcom_scm.h | 23 ++++++++++
2 files changed, 106 insertions(+)
diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index fcb04441dd52..979e101280b6 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -119,6 +119,12 @@ enum qcom_scm_qseecom_tz_cmd_app {
QSEECOM_TZ_CMD_APP_LOOKUP = 3,
};
+enum qcom_scm_qseecom_tz_cmd_app_mgr {
+ QSEECOM_TZ_CMD_APP_START = 1,
+ QSEECOM_TZ_CMD_APP_SHUTDOWN = 2,
+ QSEECOM_TZ_CMD_SERVICES_IMAGE_LOAD = 7,
+};
+
enum qcom_scm_qseecom_tz_cmd_info {
QSEECOM_TZ_CMD_INFO_VERSION = 3,
};
@@ -2220,6 +2226,83 @@ int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size,
}
EXPORT_SYMBOL_GPL(qcom_scm_qseecom_app_send);
+static int qcom_scm_qseecom_image_call(u32 cmd, phys_addr_t image,
+ size_t mdt_len, size_t img_len,
+ struct qcom_scm_qseecom_resp *res)
+{
+ struct qcom_scm_desc desc = {};
+ int status;
+
+ desc.owner = QSEECOM_TZ_OWNER_QSEE_OS;
+ desc.svc = QSEECOM_TZ_SVC_APP_MGR;
+ desc.cmd = cmd;
+ desc.arginfo = QCOM_SCM_ARGS(3);
+ desc.args[0] = mdt_len;
+ desc.args[1] = img_len;
+ desc.args[2] = image;
+
+ status = qcom_scm_qseecom_call(&desc, res);
+ if (status)
+ return status;
+
+ if (res->result != QSEECOM_RESULT_SUCCESS)
+ return -EIO;
+
+ return 0;
+}
+
+int qcom_scm_qseecom_app_start(phys_addr_t image, size_t mdt_len,
+ size_t img_len, u32 *app_id)
+{
+ struct qcom_scm_qseecom_resp res = {};
+ int status;
+
+ status = qcom_scm_qseecom_image_call(QSEECOM_TZ_CMD_APP_START, image,
+ mdt_len, img_len, &res);
+ if (status)
+ return status;
+
+ if (res.resp_type != QSEECOM_SCM_RES_APP_ID)
+ return -EIO;
+
+ *app_id = res.data;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(qcom_scm_qseecom_app_start);
+
+int qcom_scm_qseecom_app_shutdown(u32 app_id)
+{
+ struct qcom_scm_desc desc = {};
+ struct qcom_scm_qseecom_resp res = {};
+ int status;
+
+ desc.owner = QSEECOM_TZ_OWNER_QSEE_OS;
+ desc.svc = QSEECOM_TZ_SVC_APP_MGR;
+ desc.cmd = QSEECOM_TZ_CMD_APP_SHUTDOWN;
+ desc.arginfo = QCOM_SCM_ARGS(1);
+ desc.args[0] = app_id;
+
+ status = qcom_scm_qseecom_call(&desc, &res);
+ if (status)
+ return status;
+
+ if (res.result != QSEECOM_RESULT_SUCCESS)
+ return -EIO;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(qcom_scm_qseecom_app_shutdown);
+
+int qcom_scm_qseecom_services_image_load(phys_addr_t image, size_t mdt_len,
+ size_t img_len)
+{
+ struct qcom_scm_qseecom_resp res = {};
+
+ return qcom_scm_qseecom_image_call(QSEECOM_TZ_CMD_SERVICES_IMAGE_LOAD,
+ image, mdt_len, img_len, &res);
+}
+EXPORT_SYMBOL_GPL(qcom_scm_qseecom_services_image_load);
+
/*
* We do not yet support re-entrant calls via the qseecom interface. To prevent
+ any potential issues with this, only allow validated machines for now.
diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h
index a0a6bc0229c4..1027907e27b0 100644
--- a/include/linux/firmware/qcom/qcom_scm.h
+++ b/include/linux/firmware/qcom/qcom_scm.h
@@ -143,6 +143,11 @@ int qcom_scm_shm_bridge_delete(u64 handle);
int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id);
int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size,
void *rsp, size_t rsp_size);
+int qcom_scm_qseecom_app_start(phys_addr_t image, size_t mdt_len,
+ size_t img_len, u32 *app_id);
+int qcom_scm_qseecom_app_shutdown(u32 app_id);
+int qcom_scm_qseecom_services_image_load(phys_addr_t image, size_t mdt_len,
+ size_t img_len);
#else /* CONFIG_QCOM_QSEECOM */
@@ -158,6 +163,24 @@ static inline int qcom_scm_qseecom_app_send(u32 app_id,
return -EINVAL;
}
+static inline int qcom_scm_qseecom_app_start(phys_addr_t image, size_t mdt_len,
+ size_t img_len, u32 *app_id)
+{
+ return -EINVAL;
+}
+
+static inline int qcom_scm_qseecom_app_shutdown(u32 app_id)
+{
+ return -EINVAL;
+}
+
+static inline int qcom_scm_qseecom_services_image_load(phys_addr_t image,
+ size_t mdt_len,
+ size_t img_len)
+{
+ return -EINVAL;
+}
+
#endif /* CONFIG_QCOM_QSEECOM */
int qcom_scm_qtee_invoke_smc(phys_addr_t inbuf, size_t inbuf_size,
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] dt-bindings: vendor-prefixes: Add Fingerprint Cards AB
2026-11-24 17:42 [PATCH 0/4] Add FPC1540 fingerprint sensor support through QSEE Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 1/4] firmware: qcom: scm: Add QSEE app start, shutdown and services image load Armandas Kvietkus via B4 Relay
@ 2026-11-24 17:43 ` Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 3/4] dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 4/4] misc: Add FPC1540 fingerprint sensor driver for QSEE apps Armandas Kvietkus via B4 Relay
3 siblings, 0 replies; 7+ messages in thread
From: Armandas Kvietkus via B4 Relay @ 2026-11-24 17:43 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Arnd Bergmann, Greg Kroah-Hartman
Cc: linux-arm-msm, linux-kernel, devicetree, linux-doc,
Armandas Kvietkus
From: Armandas Kvietkus <armandas.kvietkus@proton.me>
Add the vendor prefix for Fingerprint Cards AB.
Signed-off-by: Armandas Kvietkus <armandas.kvietkus@proton.me>
---
Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index 5471a06f93f1..f0153a5f0687 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -628,6 +628,8 @@ patternProperties:
description: Shanghai FourSemi Semiconductor Co.,Ltd.
"^foxlink,.*":
description: Foxlink Group
+ "^fpc,.*":
+ description: Fingerprint Cards AB
"^freebox,.*":
description: Freebox SAS
"^freecom,.*":
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app
2026-11-24 17:42 [PATCH 0/4] Add FPC1540 fingerprint sensor support through QSEE Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 1/4] firmware: qcom: scm: Add QSEE app start, shutdown and services image load Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 2/4] dt-bindings: vendor-prefixes: Add Fingerprint Cards AB Armandas Kvietkus via B4 Relay
@ 2026-11-24 17:43 ` Armandas Kvietkus via B4 Relay
2026-11-24 17:51 ` sashiko-bot
2026-11-24 17:43 ` [PATCH 4/4] misc: Add FPC1540 fingerprint sensor driver for QSEE apps Armandas Kvietkus via B4 Relay
3 siblings, 1 reply; 7+ messages in thread
From: Armandas Kvietkus via B4 Relay @ 2026-11-24 17:43 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Arnd Bergmann, Greg Kroah-Hartman
Cc: linux-arm-msm, linux-kernel, devicetree, linux-doc,
Armandas Kvietkus
From: Armandas Kvietkus <armandas.kvietkus@proton.me>
On some Qualcomm phones the FPC1540 sits on a QUP owned by the secure
world and a QSEE app drives it. Linux only powers and resets it, takes
the interrupt and loads the app.
Signed-off-by: Armandas Kvietkus <armandas.kvietkus@proton.me>
---
.../devicetree/bindings/misc/fpc,fpc1540-tee.yaml | 74 ++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/Documentation/devicetree/bindings/misc/fpc,fpc1540-tee.yaml b/Documentation/devicetree/bindings/misc/fpc,fpc1540-tee.yaml
new file mode 100644
index 000000000000..0c2ec847c2d7
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/fpc,fpc1540-tee.yaml
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/fpc,fpc1540-tee.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: FPC1540 fingerprint sensor driven by a QSEE trusted application
+
+maintainers:
+ - Armandas Kvietkus <armandas.kvietkus@proton.me>
+
+description:
+ The FPC1540 is connected to a QUP serial engine that the secure world owns.
+ A QSEE trusted application drives the sensor. Linux powers and resets the
+ sensor, receives the finger interrupt and loads the trusted application.
+
+properties:
+ compatible:
+ const: fpc,fpc1540-tee
+
+ firmware-name:
+ minItems: 1
+ items:
+ - description: Path of the trusted application, without the .mdt suffix.
+ - description:
+ Path of the QSEE common library the trusted application needs,
+ without the .mdt suffix.
+
+ vdd-supply: true
+
+ reset-gpios:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ irq-gpios:
+ maxItems: 1
+ description:
+ The interrupt line read as a GPIO, so that edges where the line is
+ already low again are not reported as a finger.
+
+ memory-region:
+ maxItems: 1
+ description:
+ Region used to pass the trusted application image to QSEE. The whole
+ region is shared with QSEE because QSEE reads past the end of the image
+ while it starts the application.
+
+required:
+ - compatible
+ - firmware-name
+ - vdd-supply
+ - reset-gpios
+ - interrupts
+ - memory-region
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ fingerprint {
+ compatible = "fpc,fpc1540-tee";
+ firmware-name = "qcom/sm8250/xiaomi/alioth/fpcali",
+ "qcom/sm8250/xiaomi/alioth/cmnlib64";
+ vdd-supply = <&vreg_l13a_3p3>;
+ reset-gpios = <&tlmm 24 GPIO_ACTIVE_LOW>;
+ interrupts-extended = <&tlmm 23 IRQ_TYPE_EDGE_RISING>;
+ irq-gpios = <&tlmm 23 GPIO_ACTIVE_HIGH>;
+ memory-region = <&fpc_ta_mem>;
+ };
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] misc: Add FPC1540 fingerprint sensor driver for QSEE apps
2026-11-24 17:42 [PATCH 0/4] Add FPC1540 fingerprint sensor support through QSEE Armandas Kvietkus via B4 Relay
` (2 preceding siblings ...)
2026-11-24 17:43 ` [PATCH 3/4] dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app Armandas Kvietkus via B4 Relay
@ 2026-11-24 17:43 ` Armandas Kvietkus via B4 Relay
2026-11-24 18:01 ` sashiko-bot
3 siblings, 1 reply; 7+ messages in thread
From: Armandas Kvietkus via B4 Relay @ 2026-11-24 17:43 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Arnd Bergmann, Greg Kroah-Hartman
Cc: linux-arm-msm, linux-kernel, devicetree, linux-doc,
Armandas Kvietkus
From: Armandas Kvietkus <armandas.kvietkus@proton.me>
Power and reset the sensor, load the QSEE app on first open and pass
commands to it through /dev/fpc_tee. Finger interrupts are reported
through poll() and read().
QSEE reads past the end of the image while starting an app, so the
whole reserved region is bridged at probe.
Signed-off-by: Armandas Kvietkus <armandas.kvietkus@proton.me>
---
Documentation/userspace-api/ioctl/ioctl-number.rst | 2 +
MAINTAINERS | 8 +
drivers/misc/Kconfig | 10 +
drivers/misc/Makefile | 1 +
drivers/misc/fpc1540-tee.c | 512 +++++++++++++++++++++
include/uapi/linux/fpc1540-tee.h | 20 +
6 files changed, 553 insertions(+)
diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
index dbe462040999..55457169dff1 100644
--- a/Documentation/userspace-api/ioctl/ioctl-number.rst
+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
@@ -387,6 +387,8 @@ Code Seq# Include File Comments
<mailto:linux-hyperv@vger.kernel.org>
0xBA 00-0F uapi/linux/liveupdate.h Pasha Tatashin
<mailto:pasha.tatashin@soleen.com>
+0xBB 00-0F uapi/linux/fpc1540-tee.h FPC1540 fingerprint sensor
+ <mailto:armandas.kvietkus@proton.me>
0xC0 00-0F linux/usb/iowarrior.h
0xCA 00-0F uapi/misc/cxl.h Dead since 6.15
0xCA 10-2F uapi/misc/ocxl.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065..51d854bcb5e5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10539,6 +10539,14 @@ F: Documentation/devicetree/bindings/sound/foursemi,fs2105s.yaml
F: sound/soc/codecs/fs-amp-lib.*
F: sound/soc/codecs/fs210x.*
+FPC1540 FINGERPRINT SENSOR QSEE DRIVER
+M: Armandas Kvietkus <armandas.kvietkus@proton.me>
+L: linux-arm-msm@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/misc/fpc,fpc1540-tee.yaml
+F: drivers/misc/fpc1540-tee.c
+F: include/uapi/linux/fpc1540-tee.h
+
FPGA DFL DRIVERS
M: Xu Yilun <yilun.xu@intel.com>
R: Tom Rix <trix@redhat.com>
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index c40e89cc5724..46128f190207 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -583,6 +583,16 @@ config TC9564_PCI
quirk causes the ranges property in the endpoint's devicetree
node to be updated dynamically.
+config FPC1540_TEE
+ tristate "FPC1540 fingerprint sensor through a QSEE trusted application"
+ depends on QCOM_SCM && QCOM_QSEECOM
+ depends on OF && GPIOLIB
+ help
+ Support for the FPC1540 fingerprint sensor on Qualcomm phones where
+ the sensor is driven by a QSEE trusted application. The driver
+ powers and resets the sensor, loads the trusted application and
+ passes commands and finger interrupts to userspace.
+
source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 7cc3d615d37a..f061d6ee89bc 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -72,3 +72,4 @@ obj-y += amd-sbi/
obj-$(CONFIG_MISC_RP1) += rp1/
obj-$(CONFIG_INTEL_SSEI) += issei/
obj-$(CONFIG_TC9564_PCI) += tc9564-pci.o
+obj-$(CONFIG_FPC1540_TEE) += fpc1540-tee.o
diff --git a/drivers/misc/fpc1540-tee.c b/drivers/misc/fpc1540-tee.c
new file mode 100644
index 000000000000..37229190c46a
--- /dev/null
+++ b/drivers/misc/fpc1540-tee.c
@@ -0,0 +1,512 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/elf.h>
+#include <linux/firmware.h>
+#include <linux/firmware/qcom/qcom_scm.h>
+#include <linux/firmware/qcom/qcom_tzmem.h>
+#include <linux/fs.h>
+#include <linux/gpio/consumer.h>
+#include <linux/interrupt.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/poll.h>
+#include <linux/regulator/consumer.h>
+#include <linux/sizes.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/vmalloc.h>
+#include <linux/wait.h>
+#include <uapi/linux/fpc1540-tee.h>
+
+#define FPC_TEE_MSG_SIZE 0x40
+#define FPC_TEE_MAX_BULK SZ_256K
+
+struct fpc_tee {
+ struct device *dev;
+ struct miscdevice misc;
+ struct regulator *vdd;
+ struct gpio_desc *reset;
+ struct gpio_desc *irq_gpio;
+ struct qcom_tzmem_pool *pool;
+ const char *ta_name;
+ const char *lib_name;
+ struct mutex lock;
+ wait_queue_head_t irq_wait;
+ atomic_t irq_events;
+ bool powered;
+ bool loaded;
+ bool lib_loaded;
+ u64 bridge;
+ u32 app_id;
+};
+
+static irqreturn_t fpc_tee_irq(int irq, void *data)
+{
+ struct fpc_tee *fpc = data;
+
+ if (fpc->irq_gpio && !gpiod_get_value_cansleep(fpc->irq_gpio))
+ return IRQ_HANDLED;
+
+ atomic_inc(&fpc->irq_events);
+ wake_up_interruptible(&fpc->irq_wait);
+ pm_wakeup_event(fpc->dev, 1000);
+
+ return IRQ_HANDLED;
+}
+
+static void *fpc_tee_read_image(struct fpc_tee *fpc, const char *name,
+ size_t *mdt_len, size_t *img_len,
+ size_t *map_len)
+{
+ const struct firmware *fw;
+ const struct elf32_hdr *ehdr;
+ char fw_name[128];
+ unsigned int phnum, i;
+ size_t total, off;
+ void *buf;
+ int ret;
+
+ snprintf(fw_name, sizeof(fw_name), "%s.mdt", name);
+ ret = request_firmware(&fw, fw_name, fpc->dev);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ehdr = (const struct elf32_hdr *)fw->data;
+ if (fw->size < sizeof(struct elf64_hdr) ||
+ memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) {
+ release_firmware(fw);
+ return ERR_PTR(-EINVAL);
+ }
+
+ *map_len = 0;
+ if (ehdr->e_ident[EI_CLASS] == ELFCLASS64) {
+ const struct elf64_hdr *eh = (const struct elf64_hdr *)fw->data;
+ const struct elf64_phdr *ph = (const void *)fw->data + eh->e_phoff;
+
+ phnum = eh->e_phnum;
+ if (eh->e_phoff + phnum * sizeof(*ph) <= fw->size)
+ for (i = 0; i < phnum; i++)
+ *map_len = max_t(size_t, *map_len,
+ ph[i].p_offset + ph[i].p_filesz);
+ } else {
+ const struct elf32_phdr *ph = (const void *)fw->data + ehdr->e_phoff;
+
+ phnum = ehdr->e_phnum;
+ if (ehdr->e_phoff + phnum * sizeof(*ph) <= fw->size)
+ for (i = 0; i < phnum; i++)
+ *map_len = max_t(size_t, *map_len,
+ ph[i].p_offset + ph[i].p_filesz);
+ }
+
+ *mdt_len = fw->size;
+ total = fw->size;
+ release_firmware(fw);
+
+ for (i = 0; i < phnum; i++) {
+ snprintf(fw_name, sizeof(fw_name), "%s.b%02u", name, i);
+ ret = request_firmware(&fw, fw_name, fpc->dev);
+ if (ret)
+ return ERR_PTR(ret);
+ total += fw->size;
+ release_firmware(fw);
+ }
+
+ buf = vmalloc(total);
+ if (!buf)
+ return ERR_PTR(-ENOMEM);
+
+ off = 0;
+ for (i = 0; i <= phnum; i++) {
+ if (i)
+ snprintf(fw_name, sizeof(fw_name), "%s.b%02u", name, i - 1);
+ else
+ snprintf(fw_name, sizeof(fw_name), "%s.mdt", name);
+ ret = request_firmware(&fw, fw_name, fpc->dev);
+ if (ret || off + fw->size > total) {
+ if (!ret)
+ release_firmware(fw);
+ vfree(buf);
+ return ERR_PTR(ret ?: -EINVAL);
+ }
+ memcpy(buf + off, fw->data, fw->size);
+ off += fw->size;
+ release_firmware(fw);
+ }
+
+ *img_len = total;
+ *map_len = max(*map_len, total);
+ return buf;
+}
+
+static int fpc_tee_start(struct fpc_tee *fpc, phys_addr_t pa, size_t mdt_len,
+ size_t img_len, bool app)
+{
+ if (app)
+ return qcom_scm_qseecom_app_start(pa, mdt_len, img_len, &fpc->app_id);
+
+ return qcom_scm_qseecom_services_image_load(pa, mdt_len, img_len);
+}
+
+static int fpc_tee_load(struct fpc_tee *fpc, const char *name, bool app)
+{
+ size_t mdt_len, img_len, map_len, size;
+ dma_addr_t pa;
+ void *image, *buf;
+ int ret;
+
+ image = fpc_tee_read_image(fpc, name, &mdt_len, &img_len, &map_len);
+ if (IS_ERR(image))
+ return PTR_ERR(image);
+
+ size = PAGE_ALIGN(map_len);
+ buf = dma_alloc_coherent(fpc->dev, size, &pa, GFP_KERNEL);
+ if (!buf) {
+ vfree(image);
+ return -ENOMEM;
+ }
+
+ memcpy(buf, image, img_len);
+ vfree(image);
+
+ ret = fpc_tee_start(fpc, pa, mdt_len, img_len, app);
+ dma_free_coherent(fpc->dev, size, buf, pa);
+
+ if (ret)
+ dev_err(fpc->dev, "failed to start %s: %d\n", name, ret);
+
+ return ret;
+}
+
+static int fpc_tee_ensure_loaded(struct fpc_tee *fpc)
+{
+ int ret;
+
+ if (fpc->loaded)
+ return 0;
+
+ if (fpc->lib_name && !fpc->lib_loaded)
+ fpc->lib_loaded = !fpc_tee_load(fpc, fpc->lib_name, false);
+
+ ret = fpc_tee_load(fpc, fpc->ta_name, true);
+ if (ret)
+ return ret;
+
+ fpc->loaded = true;
+ return 0;
+}
+
+static int fpc_tee_power(struct fpc_tee *fpc, bool on)
+{
+ int ret;
+
+ if (on == fpc->powered)
+ return 0;
+
+ if (on) {
+ gpiod_set_value_cansleep(fpc->reset, 1);
+ ret = regulator_enable(fpc->vdd);
+ if (ret)
+ return ret;
+ usleep_range(1000, 1100);
+ gpiod_set_value_cansleep(fpc->reset, 0);
+ } else {
+ gpiod_set_value_cansleep(fpc->reset, 1);
+ usleep_range(1000, 1100);
+ regulator_disable(fpc->vdd);
+ }
+
+ fpc->powered = on;
+ return 0;
+}
+
+static void fpc_tee_hw_reset(struct fpc_tee *fpc)
+{
+ gpiod_set_value_cansleep(fpc->reset, 0);
+ usleep_range(100, 200);
+ gpiod_set_value_cansleep(fpc->reset, 1);
+ usleep_range(5000, 5100);
+ gpiod_set_value_cansleep(fpc->reset, 0);
+ usleep_range(5000, 5100);
+}
+
+static int fpc_tee_cmd(struct fpc_tee *fpc, struct fpc_tee_cmd __user *ucmd)
+{
+ struct fpc_tee_cmd cmd;
+ void *bulk, *req, *rsp;
+ phys_addr_t bulk_phys;
+ int ret;
+
+ if (copy_from_user(&cmd, ucmd, sizeof(cmd)))
+ return -EFAULT;
+ if (!cmd.len || cmd.len > FPC_TEE_MAX_BULK)
+ return -EINVAL;
+
+ bulk = qcom_tzmem_alloc(fpc->pool, PAGE_ALIGN(cmd.len), GFP_KERNEL);
+ req = qcom_tzmem_alloc(fpc->pool, FPC_TEE_MSG_SIZE, GFP_KERNEL);
+ rsp = qcom_tzmem_alloc(fpc->pool, FPC_TEE_MSG_SIZE, GFP_KERNEL);
+ if (!bulk || !req || !rsp) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ memset(bulk, 0, PAGE_ALIGN(cmd.len));
+ if (copy_from_user(bulk, u64_to_user_ptr(cmd.buf), cmd.len)) {
+ ret = -EFAULT;
+ goto out;
+ }
+
+ bulk_phys = qcom_tzmem_to_phys(bulk);
+ if (upper_32_bits(bulk_phys)) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ memset(req, 0, FPC_TEE_MSG_SIZE);
+ memset(rsp, 0, FPC_TEE_MSG_SIZE);
+ ((u32 *)req)[0] = cmd.len;
+ ((u32 *)req)[1] = lower_32_bits(bulk_phys);
+
+ ret = qcom_scm_qseecom_app_send(fpc->app_id, req, FPC_TEE_MSG_SIZE,
+ rsp, FPC_TEE_MSG_SIZE);
+ if (ret)
+ goto out;
+
+ cmd.status = ((s32 *)rsp)[0];
+ if (copy_to_user(u64_to_user_ptr(cmd.buf), bulk, cmd.len) ||
+ copy_to_user(ucmd, &cmd, sizeof(cmd)))
+ ret = -EFAULT;
+out:
+ if (bulk)
+ qcom_tzmem_free(bulk);
+ if (req)
+ qcom_tzmem_free(req);
+ if (rsp)
+ qcom_tzmem_free(rsp);
+ return ret;
+}
+
+static struct fpc_tee *fpc_tee_from_file(struct file *file)
+{
+ return container_of(file->private_data, struct fpc_tee, misc);
+}
+
+static int fpc_tee_open(struct inode *inode, struct file *file)
+{
+ struct fpc_tee *fpc = fpc_tee_from_file(file);
+ int ret;
+
+ mutex_lock(&fpc->lock);
+ ret = fpc_tee_ensure_loaded(fpc);
+ mutex_unlock(&fpc->lock);
+
+ return ret;
+}
+
+static long fpc_tee_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+ struct fpc_tee *fpc = fpc_tee_from_file(file);
+ u32 on;
+ long ret;
+
+ mutex_lock(&fpc->lock);
+ switch (cmd) {
+ case FPC_TEE_IOC_POWER:
+ ret = get_user(on, (u32 __user *)arg);
+ if (!ret)
+ ret = fpc_tee_power(fpc, on);
+ break;
+ case FPC_TEE_IOC_RESET:
+ fpc_tee_hw_reset(fpc);
+ ret = 0;
+ break;
+ case FPC_TEE_IOC_CMD:
+ ret = fpc_tee_cmd(fpc, (struct fpc_tee_cmd __user *)arg);
+ break;
+ case FPC_TEE_IOC_IRQ_CLEAR:
+ atomic_set(&fpc->irq_events, fpc->irq_gpio &&
+ gpiod_get_value_cansleep(fpc->irq_gpio) ? 1 : 0);
+ ret = 0;
+ break;
+ default:
+ ret = -ENOTTY;
+ }
+ mutex_unlock(&fpc->lock);
+
+ return ret;
+}
+
+static __poll_t fpc_tee_poll(struct file *file, poll_table *wait)
+{
+ struct fpc_tee *fpc = fpc_tee_from_file(file);
+
+ poll_wait(file, &fpc->irq_wait, wait);
+
+ return atomic_read(&fpc->irq_events) ? EPOLLIN | EPOLLRDNORM : 0;
+}
+
+static ssize_t fpc_tee_read(struct file *file, char __user *buf, size_t len,
+ loff_t *ppos)
+{
+ struct fpc_tee *fpc = fpc_tee_from_file(file);
+ u32 events;
+ int ret;
+
+ if (len < sizeof(events))
+ return -EINVAL;
+
+ if (!(file->f_flags & O_NONBLOCK)) {
+ ret = wait_event_interruptible(fpc->irq_wait,
+ atomic_read(&fpc->irq_events));
+ if (ret)
+ return ret;
+ }
+
+ events = atomic_xchg(&fpc->irq_events, 0);
+ if (copy_to_user(buf, &events, sizeof(events)))
+ return -EFAULT;
+
+ return sizeof(events);
+}
+
+static const struct file_operations fpc_tee_fops = {
+ .owner = THIS_MODULE,
+ .open = fpc_tee_open,
+ .unlocked_ioctl = fpc_tee_ioctl,
+ .compat_ioctl = compat_ptr_ioctl,
+ .poll = fpc_tee_poll,
+ .read = fpc_tee_read,
+ .llseek = noop_llseek,
+};
+
+static void fpc_tee_release_mem(void *data)
+{
+ struct fpc_tee *fpc = data;
+
+ qcom_tzmem_shm_bridge_delete(fpc->bridge);
+ of_reserved_mem_device_release(fpc->dev);
+}
+
+static int fpc_tee_probe(struct platform_device *pdev)
+{
+ struct qcom_tzmem_pool_config pool_config = {
+ .policy = QCOM_TZMEM_POLICY_ON_DEMAND,
+ .max_size = SZ_32M,
+ };
+ struct device *dev = &pdev->dev;
+ struct reserved_mem *rmem;
+ struct device_node *np;
+ struct fpc_tee *fpc;
+ int irq, ret;
+
+ fpc = devm_kzalloc(dev, sizeof(*fpc), GFP_KERNEL);
+ if (!fpc)
+ return -ENOMEM;
+
+ fpc->dev = dev;
+ mutex_init(&fpc->lock);
+ init_waitqueue_head(&fpc->irq_wait);
+
+ ret = of_property_read_string_index(dev->of_node, "firmware-name", 0,
+ &fpc->ta_name);
+ if (ret)
+ return dev_err_probe(dev, ret, "no firmware-name\n");
+ of_property_read_string_index(dev->of_node, "firmware-name", 1,
+ &fpc->lib_name);
+
+ fpc->vdd = devm_regulator_get(dev, "vdd");
+ if (IS_ERR(fpc->vdd))
+ return dev_err_probe(dev, PTR_ERR(fpc->vdd), "no vdd supply\n");
+
+ fpc->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(fpc->reset))
+ return dev_err_probe(dev, PTR_ERR(fpc->reset), "no reset gpio\n");
+
+ fpc->irq_gpio = devm_gpiod_get_optional(dev, "irq", GPIOD_IN);
+ if (IS_ERR(fpc->irq_gpio))
+ return dev_err_probe(dev, PTR_ERR(fpc->irq_gpio), "bad irq gpio\n");
+
+ np = of_parse_phandle(dev->of_node, "memory-region", 0);
+ if (!np)
+ return dev_err_probe(dev, -EINVAL, "no memory region\n");
+ rmem = of_reserved_mem_lookup(np);
+ of_node_put(np);
+ if (!rmem)
+ return dev_err_probe(dev, -EINVAL, "bad memory region\n");
+
+ ret = of_reserved_mem_device_init(dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "no memory region\n");
+
+ ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
+ if (!ret)
+ ret = qcom_tzmem_shm_bridge_create(rmem->base, rmem->size,
+ &fpc->bridge);
+ if (ret) {
+ of_reserved_mem_device_release(dev);
+ return dev_err_probe(dev, ret, "no shm bridge\n");
+ }
+
+ ret = devm_add_action_or_reset(dev, fpc_tee_release_mem, fpc);
+ if (ret)
+ return ret;
+
+ fpc->pool = devm_qcom_tzmem_pool_new(dev, &pool_config);
+ if (IS_ERR(fpc->pool))
+ return dev_err_probe(dev, PTR_ERR(fpc->pool), "no tzmem pool\n");
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return irq;
+
+ ret = devm_request_threaded_irq(dev, irq, NULL, fpc_tee_irq,
+ IRQF_ONESHOT, dev_name(dev), fpc);
+ if (ret)
+ return ret;
+
+ device_init_wakeup(dev, true);
+ enable_irq_wake(irq);
+
+ fpc->misc.minor = MISC_DYNAMIC_MINOR;
+ fpc->misc.name = "fpc_tee";
+ fpc->misc.fops = &fpc_tee_fops;
+ fpc->misc.parent = dev;
+
+ platform_set_drvdata(pdev, fpc);
+
+ return misc_register(&fpc->misc);
+}
+
+static void fpc_tee_remove(struct platform_device *pdev)
+{
+ struct fpc_tee *fpc = platform_get_drvdata(pdev);
+
+ misc_deregister(&fpc->misc);
+ if (fpc->loaded)
+ qcom_scm_qseecom_app_shutdown(fpc->app_id);
+ fpc_tee_power(fpc, false);
+}
+
+static const struct of_device_id fpc_tee_of_match[] = {
+ { .compatible = "fpc,fpc1540-tee" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, fpc_tee_of_match);
+
+static struct platform_driver fpc_tee_driver = {
+ .probe = fpc_tee_probe,
+ .remove = fpc_tee_remove,
+ .driver = {
+ .name = "fpc1540-tee",
+ .of_match_table = fpc_tee_of_match,
+ },
+};
+module_platform_driver(fpc_tee_driver);
+
+MODULE_DESCRIPTION("FPC1540 fingerprint sensor driven through a QSEE trusted application");
+MODULE_LICENSE("GPL");
diff --git a/include/uapi/linux/fpc1540-tee.h b/include/uapi/linux/fpc1540-tee.h
new file mode 100644
index 000000000000..87d452cc8b3c
--- /dev/null
+++ b/include/uapi/linux/fpc1540-tee.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_FPC1540_TEE_H
+#define _UAPI_LINUX_FPC1540_TEE_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+struct fpc_tee_cmd {
+ __u64 buf;
+ __u32 len;
+ __s32 status;
+};
+
+#define FPC_TEE_IOC_MAGIC 0xBB
+#define FPC_TEE_IOC_POWER _IOW(FPC_TEE_IOC_MAGIC, 0, __u32)
+#define FPC_TEE_IOC_RESET _IO(FPC_TEE_IOC_MAGIC, 1)
+#define FPC_TEE_IOC_CMD _IOWR(FPC_TEE_IOC_MAGIC, 2, struct fpc_tee_cmd)
+#define FPC_TEE_IOC_IRQ_CLEAR _IO(FPC_TEE_IOC_MAGIC, 3)
+
+#endif
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/4] dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app
2026-11-24 17:43 ` [PATCH 3/4] dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app Armandas Kvietkus via B4 Relay
@ 2026-11-24 17:51 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-24 17:51 UTC (permalink / raw)
To: Armandas Kvietkus; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] dt-bindings: misc: fpc1540-tee duplicates interrupt pin as
irq-gpios
- [Medium] dt-bindings: misc: fpc1540-tee strips .mdt suffix and embeds
QSEE resources
- [Low] dt-bindings: misc: fpc1540-tee uses non-canonical property
ordering
--
commit 9d798d8abb4687cb95d763a981df15f03d125a1a
Author: Armandas Kvietkus <armandas.kvietkus@proton.me>
dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app
This commit adds a Device Tree binding schema for the FPC1540 fingerprint
sensor when driven by a Qualcomm QSEE trusted application.
> diff --git a/Documentation/devicetree/bindings/misc/fpc,fpc1540-tee.yaml b/Documentation/devicetree/bindings/misc/fpc,fpc1540-tee.yaml
> new file mode 100644
> index 0000000000000..0c2ec847c2d75
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/misc/fpc,fpc1540-tee.yaml
> @@ -0,0 +1,74 @@
[ ... ]
> +properties:
> + compatible:
> + const: fpc,fpc1540-tee
> +
> + firmware-name:
> + minItems: 1
> + items:
> + - description: Path of the trusted application, without the .mdt suffix.
> + - description:
> + Path of the QSEE common library the trusted application needs,
> + without the .mdt suffix.
[Severity: Medium]
Should firmware-name specify the complete filename including the .mdt (or
.mbn) extension rather than stripping the suffix? Qualcomm bindings and
drivers/soc/qcom/mdt_loader.c expect the full relative filename in
firmware-name so that standard MDT loader helpers work directly and both
split (.mdt + .bXX) and single-file (.mbn) images are supported.
Also, the QSEE common library (cmnlib64) and the QSEE image-loading
memory-region below are system-wide QSEE/TEE environment resources rather
than hardware properties of the FPC1540 sensor node.
> +
> + vdd-supply: true
> +
> + reset-gpios:
> + maxItems: 1
> +
> + interrupts:
> + maxItems: 1
> +
> + irq-gpios:
> + maxItems: 1
> + description:
> + The interrupt line read as a GPIO, so that edges where the line is
> + already low again are not reported as a finger.
[Severity: Medium]
Should the binding describe the sensor's single physical interrupt wire
only once rather than duplicating the same pin in both interrupts and
irq-gpios? As shown in the example where both interrupts-extended and
irq-gpios reference <&tlmm 23>, irq-gpios encodes a Linux driver
edge-filtering workaround into the DT binding ABI rather than a distinct
hardware connection.
> +
> + memory-region:
> + maxItems: 1
> + description:
> + Region used to pass the trusted application image to QSEE. The whole
> + region is shared with QSEE because QSEE reads past the end of the image
> + while it starts the application.
> +
> +required:
> + - compatible
> + - firmware-name
> + - vdd-supply
> + - reset-gpios
> + - interrupts
> + - memory-region
[Severity: Low]
In properties:, required: and examples:, interrupts (and
interrupts-extended in the example) should be listed immediately after
compatible to follow the canonical DT schema property ordering.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-fpc1540-tee-v1-0-6c6985f05b06@proton.me?part=3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/4] misc: Add FPC1540 fingerprint sensor driver for QSEE apps
2026-11-24 17:43 ` [PATCH 4/4] misc: Add FPC1540 fingerprint sensor driver for QSEE apps Armandas Kvietkus via B4 Relay
@ 2026-11-24 18:01 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-24 18:01 UTC (permalink / raw)
To: Armandas Kvietkus; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] misc: fpc1540-tee: missing qcom_scm_is_available() check in
fpc_tee_probe()
- [High] misc: fpc1540-tee: fpc_tee_read() returns 0 events instead of
-EAGAIN
- [Medium] misc: fpc1540-tee: unbalanced wakeup and IRQ wake on
fpc_tee_probe() error
- [Medium] misc: fpc1540-tee: unbalanced wakeup and IRQ wake in
fpc_tee_remove()
- [Medium] misc: fpc1540-tee: ELF header overflow in
fpc_tee_read_image()
- [Medium] misc: fpc1540-tee: unhandled GPIO error and race in IRQ
handling
- [Medium] misc: fpc1540-tee: unlocked teardown and UAF race in
fpc_tee_remove()
- [Medium] misc: fpc1540-tee: unverified size in second pass of
fpc_tee_read_image()
- [Low] misc: fpc1540-tee: double firmware load and bounce buffer in
fpc_tee_load()
--
commit 23089f4b85a359ddf10f0fa7ac60bd5d6f60b0d1
Author: Armandas Kvietkus <armandas.kvietkus@proton.me>
misc: Add FPC1540 fingerprint sensor driver for QSEE apps
This commit adds a misc driver for the FPC1540 fingerprint sensor on
Qualcomm platforms, handling power, reset, interrupt reporting, and QSEE
trusted application loading and commands via /dev/fpc_tee.
> diff --git a/drivers/misc/fpc1540-tee.c b/drivers/misc/fpc1540-tee.c
> new file mode 100644
> index 0000000000000..37229190c46af
> --- /dev/null
> +++ b/drivers/misc/fpc1540-tee.c
[ ... ]
> +static void *fpc_tee_read_image(struct fpc_tee *fpc, const char *name,
> + size_t *mdt_len, size_t *img_len,
> + size_t *map_len)
> +{
[ ... ]
> + *map_len = 0;
> + if (ehdr->e_ident[EI_CLASS] == ELFCLASS64) {
> + const struct elf64_hdr *eh = (const struct elf64_hdr *)fw->data;
> + const struct elf64_phdr *ph = (const void *)fw->data + eh->e_phoff;
> +
> + phnum = eh->e_phnum;
> + if (eh->e_phoff + phnum * sizeof(*ph) <= fw->size)
> + for (i = 0; i < phnum; i++)
> + *map_len = max_t(size_t, *map_len,
> + ph[i].p_offset + ph[i].p_filesz);
> + } else {
> + const struct elf32_phdr *ph = (const void *)fw->data + ehdr->e_phoff;
> +
> + phnum = ehdr->e_phnum;
> + if (ehdr->e_phoff + phnum * sizeof(*ph) <= fw->size)
> + for (i = 0; i < phnum; i++)
> + *map_len = max_t(size_t, *map_len,
> + ph[i].p_offset + ph[i].p_filesz);
> + }
[Severity: Medium]
Can a malformed .mdt header wrap eh->e_phoff + phnum * sizeof(*ph) and
read ph[i] out of bounds?
In addition, ph[i].p_offset + ph[i].p_filesz can overflow (or produce a
*map_len that wraps PAGE_ALIGN(map_len) to 0 in fpc_tee_load() before
memcpy(buf, image, img_len)), and when e_phoff + phnum * sizeof(*ph) >
fw->size without wrapping, the function continues with *map_len == 0
instead of releasing fw and returning ERR_PTR(-EINVAL).
> +
> + *mdt_len = fw->size;
> + total = fw->size;
> + release_firmware(fw);
> +
> + for (i = 0; i < phnum; i++) {
> + snprintf(fw_name, sizeof(fw_name), "%s.b%02u", name, i);
> + ret = request_firmware(&fw, fw_name, fpc->dev);
> + if (ret)
> + return ERR_PTR(ret);
> + total += fw->size;
> + release_firmware(fw);
> + }
[Severity: Low]
This isn't a bug, but fpc_tee_read_image() calls request_firmware() and
release_firmware() on the .mdt and every .bNN segment once just to sum
their sizes, then loads all of them a second time into a vmalloc() buffer
that fpc_tee_load() immediately copies into a dma_alloc_coherent() buffer
and frees.
> +
> + buf = vmalloc(total);
> + if (!buf)
> + return ERR_PTR(-ENOMEM);
> +
> + off = 0;
> + for (i = 0; i <= phnum; i++) {
> + if (i)
> + snprintf(fw_name, sizeof(fw_name), "%s.b%02u", name, i - 1);
> + else
> + snprintf(fw_name, sizeof(fw_name), "%s.mdt", name);
> + ret = request_firmware(&fw, fw_name, fpc->dev);
> + if (ret || off + fw->size > total) {
> + if (!ret)
> + release_firmware(fw);
> + vfree(buf);
> + return ERR_PTR(ret ?: -EINVAL);
> + }
> + memcpy(buf + off, fw->data, fw->size);
> + off += fw->size;
> + release_firmware(fw);
> + }
> +
> + *img_len = total;
> + *map_len = max(*map_len, total);
> + return buf;
> +}
[Severity: Medium]
What happens if any firmware file shrinks between the two
request_firmware() passes?
The second loop checks off + fw->size > total, but does not verify that
the reloaded .mdt size still equals *mdt_len or that off == total after
the loop. If a file is smaller on the second read, buf[off .. total - 1]
is left with uninitialized vmalloc() memory and copied to TrustZone with
*img_len = total.
[ ... ]
> +static long fpc_tee_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
> +{
[ ... ]
> + case FPC_TEE_IOC_IRQ_CLEAR:
> + atomic_set(&fpc->irq_events, fpc->irq_gpio &&
> + gpiod_get_value_cansleep(fpc->irq_gpio) ? 1 : 0);
> + ret = 0;
> + break;
[Severity: Medium]
Does gpiod_get_value_cansleep() returning a negative errno get treated as
an asserted interrupt line both here and in fpc_tee_irq()?
Also, when FPC_TEE_IOC_IRQ_CLEAR sets fpc->irq_events to 1, it does not
call wake_up_interruptible(&fpc->irq_wait), and if fpc->irq_gpio reads 0
right before fpc_tee_irq() runs, atomic_set(&fpc->irq_events, 0) can
overwrite the new increment and drop the interrupt:
CPU0 CPU1
fpc_tee_ioctl()
gpiod_get_value_cansleep() -> 0
fpc_tee_irq()
atomic_inc(&fpc->irq_events)
atomic_set(&fpc->irq_events, 0) <-- loses interrupt event
> + default:
> + ret = -ENOTTY;
> + }
> + mutex_unlock(&fpc->lock);
> +
> + return ret;
> +}
[ ... ]
> +static ssize_t fpc_tee_read(struct file *file, char __user *buf, size_t len,
> + loff_t *ppos)
> +{
> + struct fpc_tee *fpc = fpc_tee_from_file(file);
> + u32 events;
> + int ret;
> +
> + if (len < sizeof(events))
> + return -EINVAL;
> +
> + if (!(file->f_flags & O_NONBLOCK)) {
> + ret = wait_event_interruptible(fpc->irq_wait,
> + atomic_read(&fpc->irq_events));
> + if (ret)
> + return ret;
> + }
> +
> + events = atomic_xchg(&fpc->irq_events, 0);
> + if (copy_to_user(buf, &events, sizeof(events)))
> + return -EFAULT;
> +
> + return sizeof(events);
> +}
[Severity: High]
Does a non-blocking read() return 4 bytes with events == 0 instead of
-EAGAIN when no interrupts are pending? A userspace poll/read loop
draining a non-blocking descriptor until -EAGAIN will spin forever.
Even for blocking reads, atomic_xchg(&fpc->irq_events, 0) runs outside the
wait condition, so a concurrent reader or FPC_TEE_IOC_IRQ_CLEAR can consume
the count first and cause a blocking read() to return events == 0.
Zeroing fpc->irq_events before copy_to_user() also discards the pending
events if copy_to_user() faults.
[ ... ]
> +static int fpc_tee_probe(struct platform_device *pdev)
> +{
[ ... ]
> + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
> + if (!ret)
> + ret = qcom_tzmem_shm_bridge_create(rmem->base, rmem->size,
> + &fpc->bridge);
> + if (ret) {
> + of_reserved_mem_device_release(dev);
> + return dev_err_probe(dev, ret, "no shm bridge\n");
> + }
[Severity: High]
What happens if fpc_tee_probe() runs before qcom_scm_probe() finishes?
Without checking qcom_scm_is_available() and returning -EPROBE_DEFER,
qcom_tzmem_shm_bridge_create() runs while qcom_tzmem_using_shm_bridge is
still false and silently returns 0 without creating the bridge:
drivers/firmware/qcom/qcom_tzmem.c:qcom_tzmem_shm_bridge_create() {
if (!qcom_tzmem_using_shm_bridge)
return 0;
...
}
If /dev/fpc_tee is also opened before qcom_scm_probe() completes,
fpc_tee_open() -> ... -> qcom_scm_qseecom_app_start() ->
__qcom_scm_qseecom_call() dereferences __scm->dev while __scm is NULL.
[ ... ]
> + device_init_wakeup(dev, true);
> + enable_irq_wake(irq);
> +
> + fpc->misc.minor = MISC_DYNAMIC_MINOR;
> + fpc->misc.name = "fpc_tee";
> + fpc->misc.fops = &fpc_tee_fops;
> + fpc->misc.parent = dev;
> +
> + platform_set_drvdata(pdev, fpc);
> +
> + return misc_register(&fpc->misc);
> +}
[Severity: Medium]
If misc_register() fails here, does fpc_tee_probe() leave IRQ wake enabled
and the wakeup source registered on dev?
> +
> +static void fpc_tee_remove(struct platform_device *pdev)
> +{
> + struct fpc_tee *fpc = platform_get_drvdata(pdev);
> +
> + misc_deregister(&fpc->misc);
> + if (fpc->loaded)
> + qcom_scm_qseecom_app_shutdown(fpc->app_id);
> + fpc_tee_power(fpc, false);
> +}
[Severity: Medium]
Should fpc_tee_remove() (or a devm action) also call disable_irq_wake()
and device_init_wakeup(dev, false) to balance fpc_tee_probe()?
[Severity: Medium]
Can fpc_tee_remove() race with an open file descriptor that is still in
fpc_tee_ioctl() or sleeping in fpc_tee_read()?
misc_deregister() does not wait for already-open file descriptors to close,
and fpc_tee_remove() inspects fpc->loaded, shuts down fpc->app_id, and
calls fpc_tee_power() without taking fpc->lock:
CPU0 CPU1
fpc_tee_ioctl(FPC_TEE_IOC_POWER)
mutex_lock(&fpc->lock)
fpc_tee_power(fpc, true)
regulator_enable(fpc->vdd)
usleep_range(1000, 1100)
fpc_tee_remove()
misc_deregister(&fpc->misc)
fpc_tee_power(fpc, false)
if (on == fpc->powered)
return 0; <-- vdd left enabled
fpc->powered = true
In addition, any reader still sleeping on fpc->irq_wait or holding an open
file descriptor can access fpc after fpc_tee_remove() returns and devres
frees it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-fpc1540-tee-v1-0-6c6985f05b06@proton.me?part=4
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-24 18:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 17:42 [PATCH 0/4] Add FPC1540 fingerprint sensor support through QSEE Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 1/4] firmware: qcom: scm: Add QSEE app start, shutdown and services image load Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 2/4] dt-bindings: vendor-prefixes: Add Fingerprint Cards AB Armandas Kvietkus via B4 Relay
2026-11-24 17:43 ` [PATCH 3/4] dt-bindings: misc: Add FPC1540 fingerprint sensor driven by a QSEE app Armandas Kvietkus via B4 Relay
2026-11-24 17:51 ` sashiko-bot
2026-11-24 17:43 ` [PATCH 4/4] misc: Add FPC1540 fingerprint sensor driver for QSEE apps Armandas Kvietkus via B4 Relay
2026-11-24 18:01 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox