Skip to content

Commit

Permalink
swtpm: cuse: Lock thread_busy_lock reading thread_busy (Coverity)
Browse files Browse the repository at this point in the history
Coverity is complaining that thread_busy needs to be locked before
reading. For consistency reasons now also lock thread_busy before reading
it. However, in this case it does not make a difference whether this lock
is held when reading thread_busy since file_ops_lock is held when the
thread_busy flag is set and when it is read with a call to this function
(worker_thread_is_busy). Also while the thread is busy no further commands
can be submitted and it can then reset the thread_busy flag without holding
the file_ops_lock.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Apr 22, 2024
1 parent 89b6991 commit bfd6b82
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/swtpm/threadpool.c
Expand Up @@ -128,7 +128,13 @@ void worker_thread_mark_done(void)
*/
int worker_thread_is_busy(void)
{
return thread_busy;
int ret;

g_mutex_lock(THREAD_BUSY_LOCK);
ret = thread_busy;
g_mutex_unlock(THREAD_BUSY_LOCK);

return ret;
}

/*
Expand Down

0 comments on commit bfd6b82

Please sign in to comment.