swtpm: cuse: Add lock comments to thread and variables (Coverity)
Coverity is complaining that ptm_response in the worker_thread needs to
be locked via the file_ops_lock since it is always locked when
ptm_response is accessed. However, once the thread has been started any
concurrent modification of the ptm_response is prevented with the
thread_busy flag. Therefore, add comments to the thread and ptm_reponse
variable about the locking.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/src/swtpm/cuse_tpm.c b/src/swtpm/cuse_tpm.c
index a981de1..5977b63 100644
--- a/src/swtpm/cuse_tpm.c
+++ b/src/swtpm/cuse_tpm.c
@@ -89,7 +89,7 @@
/* buffer containing the TPM request */
static unsigned char *ptm_request;
-/* buffer containing the TPM response */
+/* buffer containing the TPM response; protected by file_ops_lock and thread_busy_lock */
static unsigned char *ptm_response;
/* offset from where to read from; reset when ptm_response is set */
@@ -101,7 +101,7 @@
/* locality applied to TPM commands */
static TPM_MODIFIER_INDICATOR locality;
-/* whether the TPM is running (TPM_Init was received) */
+/* whether the TPM is running (TPM_Init was received); protected by file_ops_lock */
static bool tpm_running;
/* flags on how to handle locality */
@@ -468,6 +468,8 @@
{
struct thread_message *msg = (struct thread_message *)data;
+ /* file_ops_lock not needed since thread_busy is set */
+
switch (msg->type) {
case MESSAGE_TPM_CMD:
TPMLIB_Process(&ptm_response, &ptm_res_len, &ptm_res_tot,