.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2015, Linaro Limited |
---|
3 | | - * |
---|
4 | | - * This software is licensed under the terms of the GNU General Public |
---|
5 | | - * License version 2, as published by the Free Software Foundation, and |
---|
6 | | - * may be copied, distributed, and modified under those terms. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope that it will be useful, |
---|
9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | | - * GNU General Public License for more details. |
---|
12 | | - * |
---|
13 | 4 | */ |
---|
14 | 5 | #include <linux/device.h> |
---|
15 | 6 | #include <linux/slab.h> |
---|
.. | .. |
---|
88 | 79 | { |
---|
89 | 80 | struct optee *optee = tee_get_drvdata(ctx->teedev); |
---|
90 | 81 | struct optee_supp *supp = &optee->supp; |
---|
91 | | - struct optee_supp_req *req = kzalloc(sizeof(*req), GFP_KERNEL); |
---|
| 82 | + struct optee_supp_req *req; |
---|
92 | 83 | bool interruptable; |
---|
93 | 84 | u32 ret; |
---|
| 85 | + unsigned long timeleft; |
---|
| 86 | + int id; |
---|
| 87 | + struct optee_supp_req *get_req; |
---|
94 | 88 | |
---|
| 89 | + /* |
---|
| 90 | + * Return in case there is no supplicant available and |
---|
| 91 | + * non-blocking request. |
---|
| 92 | + */ |
---|
| 93 | + if (!supp->ctx && ctx->supp_nowait) |
---|
| 94 | + return TEEC_ERROR_COMMUNICATION; |
---|
| 95 | + |
---|
| 96 | + req = kzalloc(sizeof(*req), GFP_KERNEL); |
---|
95 | 97 | if (!req) |
---|
96 | 98 | return TEEC_ERROR_OUT_OF_MEMORY; |
---|
97 | 99 | |
---|
.. | .. |
---|
115 | 117 | * exclusive access again. |
---|
116 | 118 | */ |
---|
117 | 119 | while (wait_for_completion_interruptible(&req->c)) { |
---|
| 120 | + pr_err("Warning, Interrupting an RPC to supplicant!\n"); |
---|
| 121 | + timeleft = wait_for_completion_timeout(&req->c, msecs_to_jiffies(2000)); |
---|
| 122 | + if (timeleft) { |
---|
| 123 | + /* get completion, it means tee-supplicant is alive. */ |
---|
| 124 | + break; |
---|
| 125 | + } else { |
---|
| 126 | + /* timeout, it means tee-supplicant is dead, interrupting an RPC. */ |
---|
| 127 | + interruptable = true; |
---|
| 128 | + } |
---|
| 129 | + |
---|
118 | 130 | mutex_lock(&supp->mutex); |
---|
119 | | - interruptable = !supp->ctx; |
---|
120 | 131 | if (interruptable) { |
---|
121 | 132 | /* |
---|
122 | 133 | * There's no supplicant available and since the |
---|
.. | .. |
---|
135 | 146 | list_del(&req->link); |
---|
136 | 147 | req->in_queue = false; |
---|
137 | 148 | } |
---|
| 149 | + |
---|
| 150 | + idr_for_each_entry(&supp->idr, get_req, id) { |
---|
| 151 | + if (get_req == req) { |
---|
| 152 | + idr_remove(&supp->idr, id); |
---|
| 153 | + supp->req_id = -1; |
---|
| 154 | + break; |
---|
| 155 | + } |
---|
| 156 | + } |
---|
138 | 157 | } |
---|
139 | 158 | mutex_unlock(&supp->mutex); |
---|
140 | 159 | |
---|