Skip to contentSkip to conversation

usb/dev-smartcard-reader: convert to realize

PATCH In review Mao Zhongyi 2 participants 3 messages Sep 9, 2017 – Sep 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb/dev-smartcard-reader: convert to realize

Convert CCID Device to realize and rename the ccid_card_init() to ccid_card_realize().

---
 hw/usb/dev-smartcard-reader.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
hw/usb/dev-smartcard-reader.c +8 -10
index bef1f03..27cd48d 100644
@@ -1306,27 +1306,25 @@ 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;
 
     if (card->slot != 0) {
-        warn_report("usb-ccid supports one slot, can't add %d",
+        error_setg(errp, "usb-ccid supports one slot, can't add %d",
                     card->slot);
-        return -1;
+        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) {
+
+    if (!ccid_card_initfn(card)) {
         s->card = card;
     }
-    return ret;
 }
 
 static void ccid_realize(USBDevice *dev, Error **errp)
@@ -1496,7 +1494,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;
 }
Signature · 1 line
2.9.4
#1 lore raw

Hi

Quoted 35 lines · Mao Zhongyi

Convert CCID Device to realize and rename the ccid_card_init() to ccid_card_realize().

---
 hw/usb/dev-smartcard-reader.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
hw/usb/dev-smartcard-reader.c +3 -6
index bef1f03..27cd48d 100644
@@ -1306,27 +1306,25 @@ 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;
 
     if (card->slot != 0) {
-        warn_report("usb-ccid supports one slot, can't add %d",
+        error_setg(errp, "usb-ccid supports one slot, can't add %d",
                     card->slot);
-        return -1;
+        return;
     }
     if (s->card != NULL) {
-        warn_report("usb-ccid card already full, not adding");
-        return -1;

hw/usb/dev-smartcard-reader.c static int ccid_card_exit(DeviceState *qdev) · line 1328

Quoted 10 lines
hw/usb/dev-smartcard-reader.c +4 -2
+        error_setg(errp, "usb-ccid card already full, not adding");
+        return;
     }
-    ret = ccid_card_initfn(card);
-    if (ret == 0) {
+
+    if (!ccid_card_initfn(card)) {
         s->card = card;
     }
 

You should set an error here, or the caller won't be aware of card init error anymore. Best would be to convert ccid_card_initfn() and callbacks to take an Error **.

- return ret;

Quoted 19 lines
hw/usb/dev-smartcard-reader.c +1 -1
 }
 
 static void ccid_realize(USBDevice *dev, Error **errp)
@@ -1496,7 +1494,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;

}
--
2.9.4

Quoted 1 line

--

Marc-André Lureau

#2 lore raw
Quoted 50 lines · Marc-André Lureau

Hi

On Sat, Sep 9, 2017 at 10:33 AM Mao Zhongyi <[email protected] <mailto:[email protected]>> wrote:

    Convert CCID Device to realize and rename the ccid_card_init()
    to ccid_card_realize().

    Cc: Gerd Hoffmann <[email protected] <mailto:[email protected]>>
    Signed-off-by: Mao Zhongyi <[email protected] <mailto:[email protected]>>
    ---
     hw/usb/dev-smartcard-reader.c | 18 ++++++++----------
     1 file changed, 8 insertions(+), 10 deletions(-)

    diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
    index bef1f03..27cd48d 100644
    --- a/hw/usb/dev-smartcard-reader.c
    +++ b/hw/usb/dev-smartcard-reader.c
    @@ -1306,27 +1306,25 @@ 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;

         if (card->slot != 0) {
    -        warn_report("usb-ccid supports one slot, can't add %d",
    +        error_setg(errp, "usb-ccid supports one slot, can't add %d",
                         card->slot);
    -        return -1;
    +        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) {
    +
    +    if (!ccid_card_initfn(card)) {
             s->card = card;
         }
Quoted 1 line

You should set an error here, or the caller won't be aware of card init error anymore. Best would be to convert ccid_card_initfn() and callbacks to take an Error **.

Thanks for the info, I will.

--
Mao

Quoted 22 lines
    -    return ret;
     }

     static void ccid_realize(USBDevice *dev, Error **errp)
    @@ -1496,7 +1494,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;
     }
    --
    2.9.4

--
Marc-André Lureau