From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Amey Narkhede" <ameynarkhede03@gmail.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>
Subject: [PULL 5/5] hw/usb: Use lock guard macros
Date: Mon, 28 Sep 2020 15:16:38 +0200 [thread overview]
Message-ID: <20200928131638.9486-6-kraxel@redhat.com> (raw)
In-Reply-To: <20200928131638.9486-1-kraxel@redhat.com>
From: Amey Narkhede <ameynarkhede03@gmail.com>
Use qemu LOCK_GUARD macros from "qemu/lockable.h" in
hw/usb/ccid-card-emulated.c, saves manual unlock calls.
Signed-off-by: Amey Narkhede <ameynarkhede03@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200923134327.576139-1-ameynarkhede03@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/usb/ccid-card-emulated.c | 54 ++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
index 5e4649d36700..2d566f7db104 100644
--- a/hw/usb/ccid-card-emulated.c
+++ b/hw/usb/ccid-card-emulated.c
@@ -30,6 +30,7 @@
#include <libcacard.h>
#include "qemu/thread.h"
+#include "qemu/lockable.h"
#include "qemu/main-loop.h"
#include "qemu/module.h"
#include "ccid.h"
@@ -244,34 +245,34 @@ static void *handle_apdu_thread(void* arg)
card->quit_apdu_thread = 0; /* debugging */
break;
}
- qemu_mutex_lock(&card->vreader_mutex);
- while (!QSIMPLEQ_EMPTY(&card->guest_apdu_list)) {
- event = QSIMPLEQ_FIRST(&card->guest_apdu_list);
- assert((unsigned long)event > 1000);
- QSIMPLEQ_REMOVE_HEAD(&card->guest_apdu_list, entry);
- if (event->p.data.type != EMUL_GUEST_APDU) {
- DPRINTF(card, 1, "unexpected message in handle_apdu_thread\n");
+ WITH_QEMU_LOCK_GUARD(&card->vreader_mutex) {
+ while (!QSIMPLEQ_EMPTY(&card->guest_apdu_list)) {
+ event = QSIMPLEQ_FIRST(&card->guest_apdu_list);
+ assert((unsigned long)event > 1000);
+ QSIMPLEQ_REMOVE_HEAD(&card->guest_apdu_list, entry);
+ if (event->p.data.type != EMUL_GUEST_APDU) {
+ DPRINTF(card, 1, "unexpected message in handle_apdu_thread\n");
+ g_free(event);
+ continue;
+ }
+ if (card->reader == NULL) {
+ DPRINTF(card, 1, "reader is NULL\n");
+ g_free(event);
+ continue;
+ }
+ recv_len = sizeof(recv_data);
+ reader_status = vreader_xfr_bytes(card->reader,
+ event->p.data.data, event->p.data.len,
+ recv_data, &recv_len);
+ DPRINTF(card, 2, "got back apdu of length %d\n", recv_len);
+ if (reader_status == VREADER_OK) {
+ emulated_push_response_apdu(card, recv_data, recv_len);
+ } else {
+ emulated_push_error(card, reader_status);
+ }
g_free(event);
- continue;
}
- if (card->reader == NULL) {
- DPRINTF(card, 1, "reader is NULL\n");
- g_free(event);
- continue;
- }
- recv_len = sizeof(recv_data);
- reader_status = vreader_xfr_bytes(card->reader,
- event->p.data.data, event->p.data.len,
- recv_data, &recv_len);
- DPRINTF(card, 2, "got back apdu of length %d\n", recv_len);
- if (reader_status == VREADER_OK) {
- emulated_push_response_apdu(card, recv_data, recv_len);
- } else {
- emulated_push_error(card, reader_status);
- }
- g_free(event);
}
- qemu_mutex_unlock(&card->vreader_mutex);
}
return NULL;
}
@@ -365,7 +366,7 @@ static void card_event_handler(EventNotifier *notifier)
EmulEvent *event, *next;
event_notifier_test_and_clear(&card->notifier);
- qemu_mutex_lock(&card->event_list_mutex);
+ QEMU_LOCK_GUARD(&card->event_list_mutex);
QSIMPLEQ_FOREACH_SAFE(event, &card->event_list, entry, next) {
DPRINTF(card, 2, "event %s\n", emul_event_to_string(event->p.gen.type));
switch (event->p.gen.type) {
@@ -398,7 +399,6 @@ static void card_event_handler(EventNotifier *notifier)
g_free(event);
}
QSIMPLEQ_INIT(&card->event_list);
- qemu_mutex_unlock(&card->event_list_mutex);
}
static int init_event_notifier(EmulatedState *card, Error **errp)
--
2.27.0
next prev parent reply other threads:[~2020-09-28 13:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-28 13:16 [PULL 0/5] Usb 20200928 patches Gerd Hoffmann
2020-09-28 13:16 ` [PULL 1/5] usb/hcd-xhci: Make dma read/writes hooks pci free Gerd Hoffmann
2020-09-28 13:16 ` [PULL 2/5] usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c Gerd Hoffmann
2020-09-28 13:16 ` [PULL 3/5] usb/hcd-xhci: Split pci wrapper for xhci base model Gerd Hoffmann
2020-09-28 13:16 ` [PULL 4/5] usb: hcd-xhci-sysbus: Attach xhci to sysbus device Gerd Hoffmann
2020-09-28 13:16 ` Gerd Hoffmann [this message]
2020-09-28 18:26 ` [PULL 0/5] Usb 20200928 patches no-reply
2020-09-29 9:29 ` Peter Maydell
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=20200928131638.9486-6-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=ameynarkhede03@gmail.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).