usb: fixes for ohci and smart card emulation.

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJb12daAAoJEEy22O7T6HE4Y2QP/1zveNh7yw25ZocZYo+R4Lg2
 IzAfIeI5zSyf3yOjAwvrTiDveaPVvbiF1GXe2R3s2KSNFEvSETjZgUgL30q2I2Xu
 4W0JqxrYKI3ZmxrJukRMCx2ZUALZ00q8hjw7P0NFivrn3oNPuS8NTw75RdBBBT48
 EbtK76ejUoLX7vob+qj38euLPXSde8KiskbYq+AJrPYqnoMWabv87B49Q4485lu7
 9jt4JpiS86c0u9fvCinKntf7HxnME/g7tgKNBl6R5OgD8WB8J7f9xk/v57+AACuh
 YqUWmjD7oVznsxEkB4+FO0emexN1fibbK6xeZ//P/FzCQArHngl3KMcRcPutjxOA
 AhSHVHfYclonadrINXyxlLBAAvH81AnBibJehBBxDewmjTrisisnd9BLaMFj+xKC
 lwjXmGKozJJESz9FZdRXKr4G4pxDH8zjdDBo+EQNmOWA4Er1AFF+9nOltdkNCwMA
 fxpVQwFTKH2PlFgEc7nY0JrBV2RfUcAHMVtHydPIoViJ33xnbc35qeuGy4Nj1C9Q
 BpWpatHav0cTfV27Qhy1RiGtdcPbJ4BYUXIGvC92HkNtXlVCFBJ+c3Nk+C1b3z+D
 UUoxU3E+LsttE0Fx8bgz9nmqag4BVguEDs8fsAus7KC1g5HAhSKJZAez7Yy4UH63
 Q87jKFe93lZoahcmQR18
 =PQZI
 -----END PGP SIGNATURE-----

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>
This commit is contained in:
Peter Maydell 2018-10-30 13:32:38 +00:00
commit e8b38d7371
2 changed files with 24 additions and 9 deletions

View File

@ -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);

View File

@ -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;
}