Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60867964 authored by Zhen Kong's avatar Zhen Kong Committed by Gerrit - the friendly Code Review server
Browse files

qseecom: double check if app entry exists when unloading app



Double check if app entry still exists before deleting it from
app list when unloading app.

Change-Id: I61c70fe9d3d323696f9f1bbc1257ae768c5f991b
Signed-off-by: default avatarZhen Kong <zkong@codeaurora.org>
parent 041a4fc2
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -2823,6 +2823,7 @@ static int qseecom_unload_app(struct qseecom_dev_handle *data,
	bool unload = false;
	bool found_app = false;
	bool found_dead_app = false;
	bool scm_called = false;

	if (!data) {
		pr_err("Invalid/uninitialized device handle\n");
@@ -2881,11 +2882,12 @@ static int qseecom_unload_app(struct qseecom_dev_handle *data,
		ret = qseecom_scm_call(SCM_SVC_TZSCHEDULER, 1, &req,
				sizeof(struct qseecom_unload_app_ireq),
				&resp, sizeof(resp));
		scm_called = true;
		if (ret) {
			pr_err("scm_call to unload app (id = %d) failed\n",
								req.app_id);
			ret = -EFAULT;
			goto unload_exit;
			goto scm_exit;
		} else {
			pr_warn("App id %d now unloaded\n", req.app_id);
		}
@@ -2893,7 +2895,7 @@ static int qseecom_unload_app(struct qseecom_dev_handle *data,
			pr_err("app (%d) unload_failed!!\n",
					data->client.app_id);
			ret = -EFAULT;
			goto unload_exit;
			goto scm_exit;
		}
		if (resp.result == QSEOS_RESULT_SUCCESS)
			pr_debug("App (%d) is unloaded!!\n",
@@ -2903,11 +2905,35 @@ static int qseecom_unload_app(struct qseecom_dev_handle *data,
			if (ret) {
				pr_err("process_incomplete_cmd fail err: %d\n",
									ret);
				goto unload_exit;
				goto scm_exit;
			}
		}
	}

scm_exit:
	if (scm_called) {
		/* double check if this app_entry still exists */
		bool doublecheck = false;

		spin_lock_irqsave(&qseecom.registered_app_list_lock, flags1);
		list_for_each_entry(ptr_app,
			&qseecom.registered_app_list_head, list) {
			if ((ptr_app->app_id == data->client.app_id) &&
				(!strcmp((void *)ptr_app->app_name,
				(void *)data->client.app_name))) {
				doublecheck = true;
				break;
			}
		}
		spin_unlock_irqrestore(&qseecom.registered_app_list_lock,
								flags1);
		if (!doublecheck) {
			pr_warn("app %d(%s) entry is already removed\n",
				data->client.app_id,
				(char *)data->client.app_name);
			found_app = false;
		}
	}
unload_exit:
	if (found_app) {
		spin_lock_irqsave(&qseecom.registered_app_list_lock, flags1);