hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/drivers/tee/optee/supp.c
....@@ -91,6 +91,9 @@
9191 struct optee_supp_req *req = kzalloc(sizeof(*req), GFP_KERNEL);
9292 bool interruptable;
9393 u32 ret;
94
+ unsigned long timeleft;
95
+ int id;
96
+ struct optee_supp_req *get_req;
9497
9598 if (!req)
9699 return TEEC_ERROR_OUT_OF_MEMORY;
....@@ -115,8 +118,17 @@
115118 * exclusive access again.
116119 */
117120 while (wait_for_completion_interruptible(&req->c)) {
121
+ pr_err("Warning, Interrupting an RPC to supplicant!\n");
122
+ timeleft = wait_for_completion_timeout(&req->c, msecs_to_jiffies(2000));
123
+ if (timeleft) {
124
+ /* get completion, it means tee-supplicant is alive. */
125
+ break;
126
+ } else {
127
+ /* timeout, it means tee-supplicant is dead, interrupting an RPC. */
128
+ interruptable = true;
129
+ }
130
+
118131 mutex_lock(&supp->mutex);
119
- interruptable = !supp->ctx;
120132 if (interruptable) {
121133 /*
122134 * There's no supplicant available and since the
....@@ -135,6 +147,14 @@
135147 list_del(&req->link);
136148 req->in_queue = false;
137149 }
150
+
151
+ idr_for_each_entry(&supp->idr, get_req, id) {
152
+ if (get_req == req) {
153
+ idr_remove(&supp->idr, id);
154
+ supp->req_id = -1;
155
+ break;
156
+ }
157
+ }
138158 }
139159 mutex_unlock(&supp->mutex);
140160