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:
Lai Jiangshan
2011-12-12 15:15:54 +08:00
committed by Will Deacon
parent 572d69b1a8
commit f36b3554be
+3 -2
View File
@@ -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) {