Skip to content

Commit

Permalink
Merge "qseecom: Unload the app upon receiving qseecom_release."
Browse files Browse the repository at this point in the history
  • Loading branch information
Linux Build Service Account authored and Gerrit - the friendly Code Review server committed Sep 8, 2014
2 parents 0306cc8 + aabff59 commit 28b62ad
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions drivers/misc/qseecom.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ struct qseecom_control {
uint32_t qseos_version;
struct device *pdev;
struct cdev cdev;

bool uclient_shutdown_app;
};

struct qseecom_client_handle {
Expand Down Expand Up @@ -834,7 +836,8 @@ static int qseecom_unmap_ion_allocated_memory(struct qseecom_dev_handle *data)
return ret;
}

static int qseecom_unload_app(struct qseecom_dev_handle *data)
static int qseecom_unload_app(struct qseecom_dev_handle *data,
bool uclient_release)
{
unsigned long flags;
int ret = 0;
Expand All @@ -850,14 +853,21 @@ static int qseecom_unload_app(struct qseecom_dev_handle *data)
list) {
if (ptr_app->app_id == data->client.app_id) {
found_app = true;
if (ptr_app->ref_cnt == 1) {
if ((uclient_release) &&
(!qseecom.uclient_shutdown_app)) {
ptr_app->ref_cnt = 0;
unload = true;
break;
} else {
ptr_app->ref_cnt--;
pr_warn("Can't unload app(%d) inuse\n",
if (ptr_app->ref_cnt == 1) {
unload = true;
break;
} else {
ptr_app->ref_cnt--;
pr_debug("Can't unload app(%d) inuse\n",
ptr_app->app_id);
break;
break;
}
}
}
}
Expand Down Expand Up @@ -1639,7 +1649,7 @@ int qseecom_shutdown_app(struct qseecom_handle **handle)
if (!found_handle)
pr_err("Unable to find the handle, exiting\n");
else
ret = qseecom_unload_app(data);
ret = qseecom_unload_app(data, false);
if (ret == 0) {
kzfree(data);
kzfree(*handle);
Expand Down Expand Up @@ -2145,7 +2155,8 @@ static long qseecom_ioctl(struct file *file, unsigned cmd,
case QSEECOM_IOCTL_UNLOAD_APP_REQ: {
mutex_lock(&app_access_lock);
atomic_inc(&data->ioctl_count);
ret = qseecom_unload_app(data);
qseecom.uclient_shutdown_app = true;
ret = qseecom_unload_app(data, false);
atomic_dec(&data->ioctl_count);
mutex_unlock(&app_access_lock);
if (ret)
Expand Down Expand Up @@ -2272,7 +2283,7 @@ static int qseecom_release(struct inode *inode, struct file *file)
ret = qseecom_unregister_listener(data);
break;
case QSEECOM_CLIENT_APP:
ret = qseecom_unload_app(data);
ret = qseecom_unload_app(data, true);
break;
case QSEECOM_SECURE_SERVICE:
ret = qseecom_unmap_ion_allocated_memory(data);
Expand All @@ -2284,10 +2295,17 @@ static int qseecom_release(struct inode *inode, struct file *file)
case QSEECOM_UNAVAILABLE_CLIENT_APP:
break;
default:
ret = -EINVAL;
pr_err("Unsupported clnt_handle_type %d",
data->type);
break;
}
if (ret) {
pr_err("Close failed\n");
kfree(data);
return ret;
}
qseecom.uclient_shutdown_app = false;
}
if (qseecom.qseos_version == QSEOS_VERSION_13) {
mutex_lock(&pil_access_lock);
Expand Down Expand Up @@ -2556,7 +2574,7 @@ static int __devinit qseecom_remove(struct platform_device *pdev)
goto exit_free_kc_handle;

list_del(&kclient->list);
ret = qseecom_unload_app(kclient->handle->dev);
ret = qseecom_unload_app(kclient->handle->dev, false);
if (!ret) {
kzfree(kclient->handle->dev);
kzfree(kclient->handle);
Expand Down

0 comments on commit 28b62ad

Please sign in to comment.