Skip to content

Commit 7f565d0

Browse files
b49020jenswi-linaro
authored andcommitted
tee: optee: Fix missing devices unregister during optee_remove
When OP-TEE driver is built as a module, OP-TEE client devices registered on TEE bus during probe should be unregistered during optee_remove. So implement optee_unregister_devices() accordingly. Fixes: c3fa24a ("tee: optee: add TEE bus device enumeration support") Reported-by: Sudeep Holla <[email protected]> Signed-off-by: Sumit Garg <[email protected]> Signed-off-by: Jens Wiklander <[email protected]>
1 parent 88a3856 commit 7f565d0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

drivers/tee/optee/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ static int optee_remove(struct platform_device *pdev)
585585
{
586586
struct optee *optee = platform_get_drvdata(pdev);
587587

588+
/* Unregister OP-TEE specific client devices on TEE bus */
589+
optee_unregister_devices();
590+
588591
/*
589592
* Ask OP-TEE to free all cached shared memory objects to decrease
590593
* reference counters and also avoid wild pointers in secure world

drivers/tee/optee/device.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ static int get_devices(struct tee_context *ctx, u32 session,
5353
return 0;
5454
}
5555

56+
static void optee_release_device(struct device *dev)
57+
{
58+
struct tee_client_device *optee_device = to_tee_client_device(dev);
59+
60+
kfree(optee_device);
61+
}
62+
5663
static int optee_register_device(const uuid_t *device_uuid)
5764
{
5865
struct tee_client_device *optee_device = NULL;
@@ -63,6 +70,7 @@ static int optee_register_device(const uuid_t *device_uuid)
6370
return -ENOMEM;
6471

6572
optee_device->dev.bus = &tee_bus_type;
73+
optee_device->dev.release = optee_release_device;
6674
if (dev_set_name(&optee_device->dev, "optee-ta-%pUb", device_uuid)) {
6775
kfree(optee_device);
6876
return -ENOMEM;
@@ -154,3 +162,17 @@ int optee_enumerate_devices(u32 func)
154162
{
155163
return __optee_enumerate_devices(func);
156164
}
165+
166+
static int __optee_unregister_device(struct device *dev, void *data)
167+
{
168+
if (!strncmp(dev_name(dev), "optee-ta", strlen("optee-ta")))
169+
device_unregister(dev);
170+
171+
return 0;
172+
}
173+
174+
void optee_unregister_devices(void)
175+
{
176+
bus_for_each_dev(&tee_bus_type, NULL, NULL,
177+
__optee_unregister_device);
178+
}

drivers/tee/optee/optee_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ void optee_fill_pages_list(u64 *dst, struct page **pages, int num_pages,
184184
#define PTA_CMD_GET_DEVICES 0x0
185185
#define PTA_CMD_GET_DEVICES_SUPP 0x1
186186
int optee_enumerate_devices(u32 func);
187+
void optee_unregister_devices(void);
187188

188189
/*
189190
* Small helpers

0 commit comments

Comments
 (0)