mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
hw/usb/ccid: Make ccid_card_init() take an error parameter
Replace init() of CCIDCardClass with realize, then convert ccid_card_init(), ccid_card_initfn() and it's callbacks to take an Error** in ordor to report the error more clearly. Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 20180125171432.13554-2-f4bug@amsat.org [PMD: fixed s->card assignation in ccid_card_realize()] Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
395b953959
commit
cc847bfd16
4 changed files with 50 additions and 45 deletions
|
@ -510,14 +510,18 @@ static void ccid_card_exitfn(CCIDCardState *card)
|
|||
|
||||
}
|
||||
|
||||
static int ccid_card_initfn(CCIDCardState *card)
|
||||
static void ccid_card_initfn(CCIDCardState *card, Error **errp)
|
||||
{
|
||||
CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (cc->initfn) {
|
||||
return cc->initfn(card);
|
||||
if (cc->realize) {
|
||||
cc->realize(card, &local_err);
|
||||
if (local_err != NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool ccid_has_pending_answers(USBCCIDState *s)
|
||||
|
@ -1295,27 +1299,28 @@ static int ccid_card_exit(DeviceState *qdev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ccid_card_init(DeviceState *qdev)
|
||||
static void ccid_card_realize(DeviceState *qdev, Error **errp)
|
||||
{
|
||||
CCIDCardState *card = CCID_CARD(qdev);
|
||||
USBDevice *dev = USB_DEVICE(qdev->parent_bus->parent);
|
||||
USBCCIDState *s = USB_CCID_DEV(dev);
|
||||
int ret = 0;
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (card->slot != 0) {
|
||||
warn_report("usb-ccid supports one slot, can't add %d",
|
||||
card->slot);
|
||||
return -1;
|
||||
error_setg(errp, "usb-ccid supports one slot, can't add %d",
|
||||
card->slot);
|
||||
return;
|
||||
}
|
||||
if (s->card != NULL) {
|
||||
warn_report("usb-ccid card already full, not adding");
|
||||
return -1;
|
||||
error_setg(errp, "usb-ccid card already full, not adding");
|
||||
return;
|
||||
}
|
||||
ret = ccid_card_initfn(card);
|
||||
if (ret == 0) {
|
||||
s->card = card;
|
||||
ccid_card_initfn(card, &local_err);
|
||||
if (local_err != NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
return ret;
|
||||
s->card = card;
|
||||
}
|
||||
|
||||
static void ccid_realize(USBDevice *dev, Error **errp)
|
||||
|
@ -1477,7 +1482,7 @@ static void ccid_card_class_init(ObjectClass *klass, void *data)
|
|||
{
|
||||
DeviceClass *k = DEVICE_CLASS(klass);
|
||||
k->bus_type = TYPE_CCID_BUS;
|
||||
k->init = ccid_card_init;
|
||||
k->realize = ccid_card_realize;
|
||||
k->exit = ccid_card_exit;
|
||||
k->props = ccid_props;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue