odp-util: Use switch for checking values of an enum.
authorBen Pfaff <blp@nicira.com>
Wed, 2 May 2012 21:23:28 +0000 (14:23 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 9 May 2012 19:58:53 +0000 (12:58 -0700)
The compiler warns when we forget to handle some value of an enum, whereas
it won't for a sequence of 'if' statements.

Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/odp-util.c
ofproto/ofproto-dpif.c

index fef42ba755623ce411f2125a4207e9f128cd19de..6fc34fe78c67f79625e46dcfa55072046ccd79a0 100644 (file)
@@ -189,12 +189,16 @@ format_odp_userspace_action(struct ds *ds, const struct nlattr *attr)
 
         memcpy(&cookie, &userdata, sizeof cookie);
 
-        if (cookie.type == USER_ACTION_COOKIE_SFLOW) {
+        switch (cookie.type) {
+        case USER_ACTION_COOKIE_SFLOW:
             ds_put_format(ds, ",sFlow,n_output=%"PRIu8","
                           "vid=%"PRIu16",pcp=%"PRIu8",ifindex=%"PRIu32,
                           cookie.n_output, vlan_tci_to_vid(cookie.vlan_tci),
                           vlan_tci_to_pcp(cookie.vlan_tci), cookie.data);
-        } else {
+            break;
+
+        case USER_ACTION_COOKIE_UNSPEC:
+        default:
             ds_put_format(ds, ",userdata=0x%"PRIx64, userdata);
         }
     }
index e4bb4764a7cd37cb3b3ff2a20d2f4d8a4db76a67..b8ea49a26247ba9461ae48d0fb2609719cc6dbb3 100644 (file)
@@ -3026,13 +3026,18 @@ handle_userspace_upcall(struct ofproto_dpif *ofproto,
         return;
     }
 
-    if (cookie.type == USER_ACTION_COOKIE_SFLOW) {
+    switch (cookie.type) {
+    case USER_ACTION_COOKIE_SFLOW:
         if (ofproto->sflow) {
             dpif_sflow_received(ofproto->sflow, upcall->packet, &flow,
                                 &cookie);
         }
-    } else {
+        break;
+
+    case USER_ACTION_COOKIE_UNSPEC:
+    default:
         VLOG_WARN_RL(&rl, "invalid user cookie : 0x%"PRIx64, upcall->userdata);
+        break;
     }
 }