Updates the module of the specific driver reference counter when a shared memory object is added/removed and when device is opened/released.
Signed-off-by: Jens Wiklander jens.wiklander@linaro.org --- drivers/sec-hw/tee.c | 4 ++++ drivers/sec-hw/tee_shm.c | 7 +++++++ 2 files changed, 11 insertions(+)
diff --git a/drivers/sec-hw/tee.c b/drivers/sec-hw/tee.c index ce54be2..9af6e7d 100644 --- a/drivers/sec-hw/tee.c +++ b/drivers/sec-hw/tee.c @@ -26,6 +26,8 @@ static int tee_open(struct inode *inode, struct file *filp) struct tee_context *ctx;
teedev = container_of(filp->private_data, struct tee_device, miscdev); + if (!try_module_get(teedev->desc->owner)) + return -EINVAL; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -41,11 +43,13 @@ static int tee_open(struct inode *inode, struct file *filp) static int tee_release(struct inode *inode, struct file *filp) { struct tee_context *ctx = filp->private_data; + struct tee_device *teedev = ctx->teedev;
/* Free all shm:s related to this ctx */ tee_shm_free_by_tee_context(ctx);
ctx->teedev->desc->ops->release(ctx); + module_put(teedev->desc->owner); return 0; }
diff --git a/drivers/sec-hw/tee_shm.c b/drivers/sec-hw/tee_shm.c index b8127c0..a3e5af0 100644 --- a/drivers/sec-hw/tee_shm.c +++ b/drivers/sec-hw/tee_shm.c @@ -96,6 +96,11 @@ struct tee_shm *tee_shm_alloc(struct tee_device *teedev, if (!shm) return ERR_PTR(-ENOMEM);
+ if (!try_module_get(teedev->desc->owner)) { + ret = ERR_PTR(-EINVAL); + goto err; + } + shm->flags = flags;
if (flags & TEE_SHM_DMA_BUF) { @@ -191,6 +196,8 @@ static void tee_shm_release(struct tee_shm *shm)
poolm->ops->free(poolm, shm); kfree(shm); + + module_put(teedev->desc->owner); }
void tee_shm_free_by_tee_context(struct tee_context *ctx)