[PATCH 09/11] kvm tools: narrow the C.S. of compat_mtx

From: Lai Jiangshan
Date: Mon Dec 12 2011 - 02:16:13 EST


The allocation and the copy are not required in the C.S.

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
---
tools/kvm/guest_compat.c | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/tools/kvm/guest_compat.c b/tools/kvm/guest_compat.c
index fac53f5..de97df5 100644
--- a/tools/kvm/guest_compat.c
+++ b/tools/kvm/guest_compat.c
@@ -21,20 +21,19 @@ int compat__add_message(const char *title, const char *desc)
{
struct compat_message *msg;

- mutex_lock(&compat_mtx);
msg = malloc(sizeof(*msg));
if (msg == NULL)
goto cleanup;

- *msg = (struct compat_message) {
- .id = id,
- .title = strdup(title),
- .desc = strdup(desc),
- };
+ msg->title = strdup(title);
+ msg->desc = strdup(desc);

if (msg->title == NULL || msg->desc == NULL)
goto cleanup;

+ mutex_lock(&compat_mtx);
+
+ msg->id = id;
list_add_tail(&msg->list, &messages);

mutex_unlock(&compat_mtx);
@@ -48,8 +47,6 @@ cleanup:
free(msg);
}

- mutex_unlock(&compat_mtx);
-
return -ENOMEM;
}

@@ -101,4 +98,4 @@ int compat__print_all_messages(void)
mutex_unlock(&compat_mtx);

return 0;
-}
\ No newline at end of file
+}
--
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/