aboutsummaryrefslogtreecommitdiff
path: root/hw/usb
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-10-30 13:32:38 +0000
committerPeter Maydell <peter.maydell@linaro.org>2018-10-30 13:32:38 +0000
commite8b38d737144579b291d4e3ef737be33e7798161 (patch)
tree3489f90ad582e5dd70d7c35302f25c95cb0bc767 /hw/usb
parent0bbba1665ca2e7f1c80d4797077fe57bad58898e (diff)
parent7dea29e4af17fc1d27478de9f8ea38144deac54a (diff)
Merge remote-tracking branch 'remotes/kraxel/tags/usb-20181029-pull-request' into staging
usb: fixes for ohci and smart card emulation. # gpg: Signature made Mon 29 Oct 2018 20:02:34 GMT # gpg: using RSA key 4CB6D8EED3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" # gpg: aka "Gerd Hoffmann <gerd@kraxel.org>" # gpg: aka "Gerd Hoffmann (private) <kraxel@gmail.com>" # Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138 * remotes/kraxel/tags/usb-20181029-pull-request: hw: ccid-card-emulated: cleanup resource when realize in error path hw: ccid-card-emulated: introduce clean_event_notifier usb: ohci: make num_ports to an unsinged integer Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/usb')
-rw-r--r--hw/usb/ccid-card-emulated.c27
-rw-r--r--hw/usb/hcd-ohci.c6
2 files changed, 24 insertions, 9 deletions
diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
index 5c8b3c9907..25976ed84f 100644
--- a/hw/usb/ccid-card-emulated.c
+++ b/hw/usb/ccid-card-emulated.c
@@ -409,6 +409,12 @@ static int init_event_notifier(EmulatedState *card, Error **errp)
return 0;
}
+static void clean_event_notifier(EmulatedState *card)
+{
+ event_notifier_set_handler(&card->notifier, NULL);
+ event_notifier_cleanup(&card->notifier);
+}
+
#define CERTIFICATES_DEFAULT_DB "/etc/pki/nssdb"
#define CERTIFICATES_ARGS_TEMPLATE\
"db=\"%s\" use_hw=no soft=(,Virtual Reader,CAC,,%s,%s,%s)"
@@ -493,7 +499,7 @@ static void emulated_realize(CCIDCardState *base, Error **errp)
card->reader = NULL;
card->quit_apdu_thread = 0;
if (init_event_notifier(card, errp) < 0) {
- return;
+ goto out1;
}
card->backend = 0;
@@ -507,7 +513,7 @@ static void emulated_realize(CCIDCardState *base, Error **errp)
for (ptable = backend_enum_table; ptable->name != NULL; ++ptable) {
error_append_hint(errp, "%s\n", ptable->name);
}
- return;
+ goto out2;
}
/* TODO: a passthru backened that works on local machine. third card type?*/
@@ -517,31 +523,39 @@ static void emulated_realize(CCIDCardState *base, Error **errp)
} else {
error_setg(errp, "%s: you must provide all three certs for"
" certificates backend", TYPE_EMULATED_CCID);
- return;
+ goto out2;
}
} else {
if (card->backend != BACKEND_NSS_EMULATED) {
error_setg(errp, "%s: bad backend specified. The options are:%s"
" (default), %s.", TYPE_EMULATED_CCID,
BACKEND_NSS_EMULATED_NAME, BACKEND_CERTIFICATES_NAME);
- return;
+ goto out2;
}
if (card->cert1 != NULL || card->cert2 != NULL || card->cert3 != NULL) {
error_setg(errp, "%s: unexpected cert parameters to nss emulated "
"backend", TYPE_EMULATED_CCID);
- return;
+ goto out2;
}
/* default to mirroring the local hardware readers */
ret = wrap_vcard_emul_init(NULL);
}
if (ret != VCARD_EMUL_OK) {
error_setg(errp, "%s: failed to initialize vcard", TYPE_EMULATED_CCID);
- return;
+ goto out2;
}
qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread,
card, QEMU_THREAD_JOINABLE);
qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thread,
card, QEMU_THREAD_JOINABLE);
+
+out2:
+ clean_event_notifier(card);
+out1:
+ qemu_cond_destroy(&card->handle_apdu_cond);
+ qemu_mutex_destroy(&card->handle_apdu_mutex);
+ qemu_mutex_destroy(&card->vreader_mutex);
+ qemu_mutex_destroy(&card->event_list_mutex);
}
static void emulated_unrealize(CCIDCardState *base, Error **errp)
@@ -556,6 +570,7 @@ static void emulated_unrealize(CCIDCardState *base, Error **errp)
qemu_cond_signal(&card->handle_apdu_cond);
qemu_thread_join(&card->apdu_thread_id);
+ clean_event_notifier(card);
/* threads exited, can destroy all condvars/mutexes */
qemu_cond_destroy(&card->handle_apdu_cond);
qemu_mutex_destroy(&card->handle_apdu_mutex);
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 66656a1133..c34cf5b73a 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -57,7 +57,7 @@ typedef struct {
qemu_irq irq;
MemoryRegion mem;
AddressSpace *as;
- int num_ports;
+ uint32_t num_ports;
const char *name;
QEMUTimer *eof_timer;
@@ -1850,7 +1850,7 @@ static USBBusOps ohci_bus_ops = {
};
static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
- int num_ports, dma_addr_t localmem_base,
+ uint32_t num_ports, dma_addr_t localmem_base,
char *masterbus, uint32_t firstport,
AddressSpace *as, Error **errp)
{
@@ -1860,7 +1860,7 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
ohci->as = as;
if (num_ports > OHCI_MAX_PORTS) {
- error_setg(errp, "OHCI num-ports=%d is too big (limit is %d ports)",
+ error_setg(errp, "OHCI num-ports=%u is too big (limit is %u ports)",
num_ports, OHCI_MAX_PORTS);
return;
}