qseecom: Fix error log and add error checks

Add error checks for response returned for all scm_call()
Fix qsapps "name" logged during loading app

Change-Id: I5662cd7dfccb60367f616c75b7786161da08cb84
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
diff --git a/drivers/misc/qseecom.c b/drivers/misc/qseecom.c
index 937490d..999bd0d 100644
--- a/drivers/misc/qseecom.c
+++ b/drivers/misc/qseecom.c
@@ -571,6 +571,11 @@
 			pr_err("qseecom_scm_call failed with err: %d\n", ret);
 			return ret;
 		}
+		if (resp->result == QSEOS_RESULT_FAILURE) {
+			pr_err("Response result %d not supported\n",
+							resp->result);
+			return -EINVAL;
+		}
 	}
 	return ret;
 }
@@ -602,6 +607,10 @@
 	ret = scm_call(SCM_SVC_TZSCHEDULER, 1,  &req,
 				sizeof(struct qseecom_check_app_ireq),
 				&resp, sizeof(resp));
+	if (ret) {
+		pr_err("scm_call to check if app is already loaded failed\n");
+		return -EINVAL;
+	}
 
 	if (resp.result == QSEOS_RESULT_FAILURE)
 		app_id = 0;
@@ -625,7 +634,7 @@
 		struct qseecom_load_app_ireq load_req;
 
 		pr_warn("App (%s) does not exist, loading apps for first time\n",
-			(char *)(load_req.app_name));
+			(char *)(req.app_name));
 		/* Get the handle of the shared fd */
 		ihandle = ion_import_fd(qseecom.ion_clnt,
 					load_img_req.ifd_data_fd);
@@ -647,9 +656,13 @@
 		ret = scm_call(SCM_SVC_TZSCHEDULER, 1,  &load_req,
 				sizeof(struct qseecom_load_app_ireq),
 				&resp, sizeof(resp));
+		if (ret) {
+			pr_err("scm_call to load app failed\n");
+			return -EINVAL;
+		}
 
 		if (resp.result == QSEOS_RESULT_FAILURE) {
-			pr_err("scm_call failed resp.result QSEOS_RESULT_FAILURE -1\n");
+			pr_err("scm_call rsp.result is QSEOS_RESULT_FAILURE\n");
 			if (!IS_ERR_OR_NULL(ihandle))
 				ion_free(qseecom.ion_clnt, ihandle);
 			return -EFAULT;
@@ -692,8 +705,8 @@
 		spin_unlock_irqrestore(&qseecom.registered_app_list_lock,
 					flags);
 
-		pr_warn("App with id %d  (%s) now loaded\n", app_id,
-			(char *)(load_req.app_name));
+		pr_warn("App with id %d (%s) now loaded\n", app_id,
+			(char *)(req.app_name));
 	}
 	data->client.app_id = app_id;
 	load_img_req.app_id = app_id;
@@ -737,8 +750,6 @@
 					unload = __qseecom_cleanup_app(data);
 					list_del(&ptr_app->list);
 					kzfree(ptr_app);
-					pr_warn("App id %d now unloaded\n",
-							ptr_app->app_id);
 					break;
 				} else {
 					ptr_app->ref_cnt--;
@@ -769,8 +780,11 @@
 				sizeof(struct qseecom_unload_app_ireq),
 				&resp, sizeof(resp));
 		if (ret) {
-			pr_err("Fail to unload app id %d\n", req.app_id);
+			pr_err("scm_call to unload app (id = %d) failed\n",
+							req.app_id);
 			return -EFAULT;
+		} else {
+			pr_warn("App id %d now unloaded\n", req.app_id);
 		}
 		if (resp.result == QSEOS_RESULT_INCOMPLETE) {
 			ret = __qseecom_process_incomplete_cmd(data, &resp);
@@ -949,6 +963,12 @@
 			pr_err("process_incomplete_cmd failed err: %d\n", ret);
 			return ret;
 		}
+	} else {
+		if (resp.result != QSEOS_RESULT_SUCCESS) {
+			pr_err("Response result %d not supported\n",
+							resp.result);
+			ret = -EINVAL;
+		}
 	}
 	return ret;
 }