[PATCH 2/2] optee: skip registration of already known TEE bus devices

Sascha Hauer s.hauer at pengutronix.de
Thu Mar 19 00:03:04 PDT 2026


optee_enumerate_devices() may be called multiple times, e.g. when a
new RPMB device appears. Check if a device with the same name is
already registered on the TEE bus before registering it again.

Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/device.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
index f5e03630b1..ab05a4dfc9 100644
--- a/drivers/tee/optee/device.c
+++ b/drivers/tee/optee/device.c
@@ -57,14 +57,23 @@ static int get_devices(struct tee_context *ctx, u32 session,
 static int optee_register_device(const uuid_t *device_uuid)
 {
 	struct tee_client_device *optee_device = NULL;
+	struct device *dev;
+	char name[39];
 	int rc;
 
+	snprintf(name, sizeof(name), "optee-ta-%pUb", device_uuid);
+
+	dev = bus_find_device_by_name(&tee_bus_type, NULL, name);
+	if (dev)
+		return 0;
+
 	optee_device = kzalloc(sizeof(*optee_device), GFP_KERNEL);
 	if (!optee_device)
 		return -ENOMEM;
 
+	optee_device->dev.id = DEVICE_ID_SINGLE;
 	optee_device->dev.bus = &tee_bus_type;
-	if (dev_set_name(&optee_device->dev, "optee-ta-%pUb", device_uuid)) {
+	if (dev_set_name(&optee_device->dev, "%s", name)) {
 		kfree(optee_device);
 		return -ENOMEM;
 	}
-- 
2.47.3




More information about the barebox mailing list