Skip to content

Commit

Permalink
qseecom: Proper handling of unmapping dmabuf
Browse files Browse the repository at this point in the history
After unmapping the dmabuf, the pointers for dmabuf
and sg lists should be explicitly made NULL. This
change takes care of releasing the already unmapped
dma buf pointers and sg pointers.

Change-Id: Ia33231af761eddbdd6f71fda2c16b37289724b2e
Signed-off-by: Anmolpreet Kaur <[email protected]>
Signed-off-by: engstk <[email protected]>
  • Loading branch information
Anmolpreet Kaur authored and engstk committed Jul 14, 2020
1 parent 7b59dc9 commit 87b6426
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions drivers/misc/qseecom.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* QTI Secure Execution Environment Communicator (QSEECOM) driver
*
* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
* Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
Expand Down Expand Up @@ -192,6 +192,13 @@ struct sglist_info {
#define MAKE_WHITELIST_VERSION(major, minor, patch) \
(((major & 0x3FF) << 22) | ((minor & 0x3FF) << 12) | (patch & 0xFFF))

#define MAKE_NULL(sgt, attach, dmabuf) do {\
sgt = NULL;\
attach = NULL;\
dmabuf = NULL;\
} while (0)


struct qseecom_registered_listener_list {
struct list_head list;
struct qseecom_register_listener_req svc;
Expand Down Expand Up @@ -1267,6 +1274,7 @@ static int qseecom_vaddr_map(int ion_fd,
err_unmap:
dma_buf_end_cpu_access(new_dma_buf, DMA_BIDIRECTIONAL);
qseecom_dmabuf_unmap(new_sgt, new_attach, new_dma_buf);
MAKE_NULL(*sgt, *attach, *dmabuf);
err:
return ret;
}
Expand Down Expand Up @@ -1341,9 +1349,11 @@ static int __qseecom_set_sb_memory(struct qseecom_registered_listener_list *svc,
}
return 0;
err:
if (svc->dmabuf)
if (svc->dmabuf) {
qseecom_vaddr_unmap(svc->sb_virt, svc->sgt, svc->attach,
svc->dmabuf);
MAKE_NULL(svc->sgt, svc->attach, svc->dmabuf);
}
return ret;
}

Expand Down Expand Up @@ -1459,9 +1469,11 @@ static int __qseecom_unregister_listener(struct qseecom_dev_handle *data,
}

exit:
if (ptr_svc->dmabuf)
if (ptr_svc->dmabuf) {
qseecom_vaddr_unmap(ptr_svc->sb_virt,
ptr_svc->sgt, ptr_svc->attach, ptr_svc->dmabuf);
MAKE_NULL(ptr_svc->sgt, ptr_svc->attach, ptr_svc->dmabuf);
}

list_del(&ptr_svc->list);
kzfree(ptr_svc);
Expand Down Expand Up @@ -1866,9 +1878,12 @@ static int qseecom_set_client_mem_param(struct qseecom_dev_handle *data,

return ret;
exit:
if (data->client.dmabuf)
if (data->client.dmabuf) {
qseecom_vaddr_unmap(data->client.sb_virt, data->client.sgt,
data->client.attach, data->client.dmabuf);
MAKE_NULL(data->client.sgt,
data->client.attach, data->client.dmabuf);
}
return ret;
}

Expand Down Expand Up @@ -2798,8 +2813,10 @@ static int qseecom_load_app(struct qseecom_dev_handle *data, void __user *argp)

loadapp_err:
__qseecom_disable_clk_scale_down(data);
if (dmabuf)
if (dmabuf) {
qseecom_vaddr_unmap(vaddr, sgt, attach, dmabuf);
MAKE_NULL(sgt, attach, dmabuf);
}
enable_clk_err:
if (qseecom.support_bus_scaling) {
mutex_lock(&qsee_bw_mutex);
Expand Down Expand Up @@ -2977,9 +2994,12 @@ static int qseecom_unload_app(struct qseecom_dev_handle *data,
flags1);
}

if (data->client.dmabuf)
if (data->client.dmabuf) {
qseecom_vaddr_unmap(data->client.sb_virt, data->client.sgt,
data->client.attach, data->client.dmabuf);
MAKE_NULL(data->client.sgt,
data->client.attach, data->client.dmabuf);
}
data->released = true;
return ret;
}
Expand Down Expand Up @@ -3814,8 +3834,10 @@ static int __qseecom_update_cmd_buf(void *msg, bool cleanup,
}
return ret;
err:
if (!IS_ERR_OR_NULL(sg_ptr))
if (!IS_ERR_OR_NULL(sg_ptr)) {
qseecom_dmabuf_unmap(sg_ptr, attach, dmabuf);
MAKE_NULL(sg_ptr, attach, dmabuf);
}
return -ENOMEM;
}

Expand Down Expand Up @@ -4053,8 +4075,10 @@ static int __qseecom_update_cmd_buf_64(void *msg, bool cleanup,
data->client.sec_buf_fd[i].size,
data->client.sec_buf_fd[i].vbase,
data->client.sec_buf_fd[i].pbase);
if (!IS_ERR_OR_NULL(sg_ptr))
if (!IS_ERR_OR_NULL(sg_ptr)) {
qseecom_dmabuf_unmap(sg_ptr, attach, dmabuf);
MAKE_NULL(sg_ptr, attach, dmabuf);
}
return -ENOMEM;
}

Expand Down Expand Up @@ -5606,8 +5630,10 @@ static int qseecom_load_external_elf(struct qseecom_dev_handle *data,
}

exit_cpu_restore:
if (dmabuf)
if (dmabuf) {
qseecom_vaddr_unmap(va, sgt, attach, dmabuf);
MAKE_NULL(sgt, attach, dmabuf);
}
return ret;
}

Expand Down Expand Up @@ -6873,8 +6899,10 @@ static int __qseecom_update_qteec_req_buf(struct qseecom_qteec_modfd_req *req,
}
return ret;
err:
if (!IS_ERR_OR_NULL(sg_ptr))
if (!IS_ERR_OR_NULL(sg_ptr)) {
qseecom_dmabuf_unmap(sg_ptr, attach, dmabuf);
MAKE_NULL(sg_ptr, attach, dmabuf);
}
return -ENOMEM;
}

Expand Down Expand Up @@ -8020,10 +8048,13 @@ static int qseecom_release(struct inode *inode, struct file *file)
break;
case QSEECOM_SECURE_SERVICE:
case QSEECOM_GENERIC:
if (data->client.dmabuf)
if (data->client.dmabuf) {
qseecom_vaddr_unmap(data->client.sb_virt,
data->client.sgt, data->client.attach,
data->client.dmabuf);
MAKE_NULL(data->client.sgt, data->client.attach,
data->client.dmabuf);
}
break;
case QSEECOM_UNAVAILABLE_CLIENT_APP:
break;
Expand Down

0 comments on commit 87b6426

Please sign in to comment.