qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: nyoro.gachu@gmail.com
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, Samker <samkergachu@gmail.com>,
	M N Gachu <nyoro.gachu@gmail.com>
Subject: [PATCH] LockGuards: replace manual lock()/unlock() calls to WITH_QEMU_LOCK_GUARD()
Date: Sat,  5 Nov 2022 02:08:11 +0300	[thread overview]
Message-ID: <20221104230811.7188-1-nyoro.martin@gmail.com> (raw)

From: Samker <samkergachu@gmail.com>

LockGuards are preferred to manual lock()/unlock() calls. Lock guards
help prevent common bugs when locks are not released in error code
paths. This patch
replaces calls to manual lock()/unlock() with the much preferred
WITH_QEMU_LOCK_GUARD()

Signed-off-by: M N Gachu <nyoro.gachu@gmail.com>
---
 softmmu/physmem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index d9578ccfd4..fb00596777 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -24,6 +24,7 @@
 #include "qemu/cutils.h"
 #include "qemu/cacheflush.h"
 #include "qemu/madvise.h"
+#include "qemu/lockable.h"
 
 #ifdef CONFIG_TCG
 #include "hw/core/tcg-cpu-ops.h"
@@ -3114,13 +3115,12 @@ void cpu_register_map_client(QEMUBH *bh)
 {
     MapClient *client = g_malloc(sizeof(*client));
 
-    qemu_mutex_lock(&map_client_list_lock);
+    WITH_QEMU_LOCK_GUARD(&map_client_list_lock);
     client->bh = bh;
     QLIST_INSERT_HEAD(&map_client_list, client, link);
     if (!qatomic_read(&bounce.in_use)) {
         cpu_notify_map_clients_locked();
     }
-    qemu_mutex_unlock(&map_client_list_lock);
 }
 
 void cpu_exec_init_all(void)
@@ -3143,7 +3143,7 @@ void cpu_unregister_map_client(QEMUBH *bh)
 {
     MapClient *client;
 
-    qemu_mutex_lock(&map_client_list_lock);
+    WITH_QEMU_LOCK_GUARD(&map_client_list_lock);
     QLIST_FOREACH(client, &map_client_list, link) {
         if (client->bh == bh) {
             cpu_unregister_map_client_do(client);
-- 
2.25.1



             reply	other threads:[~2022-11-05  1:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 23:08 nyoro.gachu [this message]
2022-11-06 13:48 ` [PATCH] LockGuards: replace manual lock()/unlock() calls to WITH_QEMU_LOCK_GUARD() Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221104230811.7188-1-nyoro.martin@gmail.com \
    --to=nyoro.gachu@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=samkergachu@gmail.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).