qseecom: Fix issues with failure to release client handle

In some scenarios when qseecom_release is called with the incorrect
client handle type. Hence proper cleanup is not done for the memory
allocated to the device handle or to unload the app.

This change addresses the cleanup issues related to qseecom client in
qseecom_release call by ensuring the handle type is set correctly and
cleanup is done properly based on client type.

Change-Id: I126aa431ce635ae98100b774e3d92b704635d199
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
This commit is contained in:
AnilKumar Chimata 2013-09-05 18:00:28 +05:30 committed by Gerrit - the friendly Code Review server
parent a9f4bdf509
commit 03e523358a
1 changed files with 13 additions and 5 deletions

View File

@ -383,7 +383,6 @@ static int qseecom_register_listener(struct qseecom_dev_handle *data,
return ret;
}
data->listener.id = 0;
data->type = QSEECOM_LISTENER_SERVICE;
if (!__qseecom_is_svc_unique(data, &rcvd_lstnr)) {
pr_err("Service is not unique and is already registered\n");
data->released = true;
@ -2111,6 +2110,7 @@ static long qseecom_ioctl(struct file *file, unsigned cmd,
switch (cmd) {
case QSEECOM_IOCTL_REGISTER_LISTENER_REQ: {
pr_debug("ioctl register_listener_req()\n");
data->type = QSEECOM_LISTENER_SERVICE;
atomic_inc(&data->ioctl_count);
ret = qseecom_register_listener(data, argp);
atomic_dec(&data->ioctl_count);
@ -2172,6 +2172,8 @@ static long qseecom_ioctl(struct file *file, unsigned cmd,
break;
}
case QSEECOM_IOCTL_SET_MEM_PARAM_REQ: {
data->type = QSEECOM_CLIENT_APP;
pr_debug("SET_MEM_PARAM: qseecom addr = 0x%x\n", (u32)data);
ret = qseecom_set_client_mem_param(data, argp);
if (ret)
pr_err("failed Qqseecom_set_mem_param request: %d\n",
@ -2179,6 +2181,8 @@ static long qseecom_ioctl(struct file *file, unsigned cmd,
break;
}
case QSEECOM_IOCTL_LOAD_APP_REQ: {
data->type = QSEECOM_CLIENT_APP;
pr_debug("LOAD_APP_REQ: qseecom_addr = 0x%x\n", (u32)data);
mutex_lock(&app_access_lock);
atomic_inc(&data->ioctl_count);
ret = qseecom_load_app(data, argp);
@ -2189,6 +2193,7 @@ static long qseecom_ioctl(struct file *file, unsigned cmd,
break;
}
case QSEECOM_IOCTL_UNLOAD_APP_REQ: {
pr_debug("UNLOAD_APP: qseecom_addr = 0x%x\n", (u32)data);
mutex_lock(&app_access_lock);
atomic_inc(&data->ioctl_count);
qseecom.uclient_shutdown_app = true;
@ -2226,6 +2231,7 @@ static long qseecom_ioctl(struct file *file, unsigned cmd,
break;
}
case QSEECOM_IOCTL_LOAD_EXTERNAL_ELF_REQ: {
data->type = QSEECOM_UNAVAILABLE_CLIENT_APP;
data->released = true;
if (qseecom.qseos_version == QSEOS_VERSION_13) {
pr_err("Loading External elf image unsupported in rev 0x13\n");
@ -2258,6 +2264,8 @@ static long qseecom_ioctl(struct file *file, unsigned cmd,
break;
}
case QSEECOM_IOCTL_APP_LOADED_QUERY_REQ: {
data->type = QSEECOM_CLIENT_APP;
pr_debug("APP_LOAD_QUERY: qseecom_addr = 0x%x\n", (u32)data);
mutex_lock(&app_access_lock);
atomic_inc(&data->ioctl_count);
ret = qseecom_query_app_loaded(data, argp);
@ -2313,7 +2321,8 @@ static int qseecom_release(struct inode *inode, struct file *file)
int ret = 0;
if (data->released == false) {
pr_warn("data->released == false\n");
pr_warn("data: released = false, type = %d, data = 0x%x\n",
data->type, (u32)data);
switch (data->type) {
case QSEECOM_LISTENER_SERVICE:
ret = qseecom_unregister_listener(data);
@ -2322,11 +2331,10 @@ static int qseecom_release(struct inode *inode, struct file *file)
ret = qseecom_unload_app(data, true);
break;
case QSEECOM_SECURE_SERVICE:
case QSEECOM_GENERIC:
ret = qseecom_unmap_ion_allocated_memory(data);
if (ret) {
if (ret)
pr_err("Close failed\n");
return ret;
}
break;
case QSEECOM_UNAVAILABLE_CLIENT_APP:
break;