[Spice-devel] [spice-server v2 4/4] smartcard: Improve on_message_from_device readability

Christophe Fergeau cfergeau at redhat.com
Fri Feb 8 16:26:27 UTC 2019


This removes a not really useful switch/case, and changes the function
to exit early on error cases, rather than exiting early in the nominal
case.

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
---
 server/smartcard.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/server/smartcard.c b/server/smartcard.c
index eb0b06fad..34cfca230 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -198,11 +198,8 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
     vheader->length = ntohl(vheader->length);
     vheader->reader_id = ntohl(vheader->reader_id);
 
-    switch (vheader->type) {
-        case VSC_Init:
-            return NULL;
-        default:
-            break;
+    if (vheader->type == VSC_Init) {
+        return NULL;
     }
     /* We pass any VSC_Error right now - might need to ignore some? */
     if (dev->priv->reader_id == VSCARD_UNDEFINED_READER_ID) {
@@ -210,10 +207,10 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
                             "error: reader_id not assigned for message of type %d",
                             vheader->type);
     }
-    if (dev->priv->scc) {
-        return smartcard_new_vsc_msg_item(dev->priv->reader_id, vheader);
+    if (dev->priv->scc == NULL) {
+        return NULL;
     }
-    return NULL;
+    return smartcard_new_vsc_msg_item(dev->priv->reader_id, vheader);
 }
 
 static int smartcard_char_device_add_to_readers(RedsState *reds, SpiceCharDeviceInstance *char_device)
-- 
2.20.1



More information about the Spice-devel mailing list