mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-06-15 18:05:49 +00:00
kvm tools: protect shared global id in compat_mtx C.S.
The global id is shared, protect it when access it. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
committed by
Will Deacon
parent
572d69b1a8
commit
f36b3554be
+3
-2
@@ -20,6 +20,7 @@ static LIST_HEAD(messages);
|
||||
int compat__add_message(const char *title, const char *desc)
|
||||
{
|
||||
struct compat_message *msg;
|
||||
int msg_id;
|
||||
|
||||
msg = malloc(sizeof(*msg));
|
||||
if (msg == NULL)
|
||||
@@ -33,12 +34,12 @@ int compat__add_message(const char *title, const char *desc)
|
||||
|
||||
mutex_lock(&compat_mtx);
|
||||
|
||||
msg->id = id;
|
||||
msg->id = msg_id = id++;
|
||||
list_add_tail(&msg->list, &messages);
|
||||
|
||||
mutex_unlock(&compat_mtx);
|
||||
|
||||
return id++;
|
||||
return msg_id;
|
||||
|
||||
cleanup:
|
||||
if (msg) {
|
||||
|
||||
Reference in New Issue
Block a user