Hi,
Here's some small fixes to the generic TEE subsystem.
I've created a pull request of the same patches at https://github.com/TrustZoneGenericDriver/linux/pull/1
Jens Wiklander (2): tee: bugfix and export tee_shm_fd() tee: bugfix tee_shm_alloc()
drivers/sec-hw/tee.c | 9 ++++++++- drivers/sec-hw/tee_private.h | 2 -- drivers/sec-hw/tee_shm.c | 7 ++++++- include/linux/sec-hw/tee_drv.h | 7 +++++++ 4 files changed, 21 insertions(+), 4 deletions(-)
* 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*/
Bugfix tee_shm_alloc(), close file descriptor on error.
Signed-off-by: Jens Wiklander jens.wiklander@linaro.org --- drivers/sec-hw/tee.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/sec-hw/tee.c b/drivers/sec-hw/tee.c index df4a359..4f4badb 100644 --- a/drivers/sec-hw/tee.c +++ b/drivers/sec-hw/tee.c @@ -15,8 +15,11 @@ #include <linux/fs.h> #include <linux/module.h> #include <linux/slab.h> -#include <linux/sec-hw/tee_drv.h> +#include <linux/fdtable.h> +#include <linux/thread_info.h> #include <linux/uaccess.h> +#include <linux/sched.h> +#include <linux/sec-hw/tee_drv.h> #include "tee_private.h"
static int tee_open(struct inode *inode, struct file *filp) @@ -91,6 +94,8 @@ static long tee_ioctl_shm_alloc(struct tee_filp *teefilp, if (data.flags) return -EINVAL;
+ data.fd = -1; + shm = tee_shm_alloc(teefilp->teedev, teefilp, data.size, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); if (IS_ERR(shm)) @@ -114,6 +119,8 @@ static long tee_ioctl_shm_alloc(struct tee_filp *teefilp, } return 0; err: + if (data.fd >= 0) + __close_fd(current->files, data.fd); tee_shm_free(shm); return ret; }
Merged
On 01 Apr 2015, at 11:51, Jens Wiklander jens.wiklander@linaro.org wrote:
Hi,
Here's some small fixes to the generic TEE subsystem.
I've created a pull request of the same patches at https://github.com/TrustZoneGenericDriver/linux/pull/1
Jens Wiklander (2): tee: bugfix and export tee_shm_fd() tee: bugfix tee_shm_alloc()
drivers/sec-hw/tee.c | 9 ++++++++- drivers/sec-hw/tee_private.h | 2 -- drivers/sec-hw/tee_shm.c | 7 ++++++- include/linux/sec-hw/tee_drv.h | 7 +++++++ 4 files changed, 21 insertions(+), 4 deletions(-)
-- 1.9.1
Tee-dev mailing list Tee-dev@lists.linaro.org https://lists.linaro.org/mailman/listinfo/tee-dev