diff options
author | Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | 2018-01-25 14:14:30 -0300 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2018-01-26 07:59:33 +0100 |
commit | cc847bfd16d894fd8c1a2ce25f31772f6cdbbc74 (patch) | |
tree | 3b7c74e4164cc7d1c15bda1fd13c33fa9f42dade /hw/usb/dev-smartcard-reader.c | |
parent | 395b95395934785ca86baafd314d0c31b307d16d (diff) |
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>
Diffstat (limited to 'hw/usb/dev-smartcard-reader.c')
-rw-r--r-- | hw/usb/dev-smartcard-reader.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index e334d3be11..0092493f4e 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -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; } |