* Exports tee_shm_fd() to be used by other modules * Bugfixes tee_shm_fd(), increase refcount on dmabuf before returning the assigned file descriptor
Signed-off-by: Jens Wiklander jens.wiklander@linaro.org --- drivers/sec-hw/tee_private.h | 2 -- drivers/sec-hw/tee_shm.c | 7 ++++++- include/linux/sec-hw/tee_drv.h | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/sec-hw/tee_private.h b/drivers/sec-hw/tee_private.h index 7b1668f..0bf4f52 100644 --- a/drivers/sec-hw/tee_private.h +++ b/drivers/sec-hw/tee_private.h @@ -35,8 +35,6 @@ struct tee_shm { u32 flags; };
-int tee_shm_fd(struct tee_shm *shm); void tee_shm_free_by_teefilp(struct tee_filp *teefilp);
- #endif /*TEE_PRIVATE_H*/ diff --git a/drivers/sec-hw/tee_shm.c b/drivers/sec-hw/tee_shm.c index a807af5..61ca5aa 100644 --- a/drivers/sec-hw/tee_shm.c +++ b/drivers/sec-hw/tee_shm.c @@ -182,12 +182,17 @@ EXPORT_SYMBOL_GPL(tee_shm_alloc); int tee_shm_fd(struct tee_shm *shm) { u32 req_flags = TEE_SHM_MAPPED | TEE_SHM_DMA_BUF; + int fd;
if ((shm->flags & req_flags) != req_flags) return -EINVAL;
- return dma_buf_fd(shm->dmabuf, O_CLOEXEC); + fd = dma_buf_fd(shm->dmabuf, O_CLOEXEC); + if (fd >= 0) + get_dma_buf(shm->dmabuf); + return fd; } +EXPORT_SYMBOL_GPL(tee_shm_fd);
static void tee_shm_release(struct tee_shm *shm) { diff --git a/include/linux/sec-hw/tee_drv.h b/include/linux/sec-hw/tee_drv.h index 8693363..0ea8c10 100644 --- a/include/linux/sec-hw/tee_drv.h +++ b/include/linux/sec-hw/tee_drv.h @@ -211,4 +211,11 @@ struct tee_shm *tee_shm_get_from_fd(int fd); */ void tee_shm_put(struct tee_shm *shm);
+/** + * tee_shm_fd() - Increase reference count and return file descriptor + * @shm: Shared memory handle + * @returns user space file descriptor to shared memory + */ +int tee_shm_fd(struct tee_shm *shm); + #endif /*__TEE_DRV_H*/