bridge: Properly test for out-of-range values.
authorBen Pfaff <blp@nicira.com>
Fri, 15 Apr 2011 16:40:50 +0000 (09:40 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 18 Apr 2011 17:32:50 +0000 (10:32 -0700)
This code was trying to check for priorities greater than UINT16_MAX and
reset them, but it assigned the value to a uint16_t before it checked it,
which of course hid the problem.

Fixes the following GCC warning:

vswitchd/bridge.c:3034: warning: comparison is always false due to limited
range of data type

Reported-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
vswitchd/bridge.c

index ab4d5078f6673d307f07fc153d7526c240191e7c..f526715653789cd2b3f2c0635e8cdc110a31f46f 100644 (file)
@@ -3094,6 +3094,7 @@ port_reconfigure_lacp(struct port *port)
 {
     static struct lacp_settings s;
     struct iface *iface;
+    int priority;
 
     if (!enable_lacp(port, &s.active)) {
         lacp_destroy(port->lacp);
@@ -3103,16 +3104,17 @@ port_reconfigure_lacp(struct port *port)
 
     s.name = port->name;
     memcpy(s.id, port->bridge->ea, ETH_ADDR_LEN);
-    s.priority = atoi(get_port_other_config(port->cfg, "lacp-system-priority",
-                                            "0"));
+
+    /* Prefer bondable links if unspecified. */
+    priority = atoi(get_port_other_config(port->cfg, "lacp-system-priority",
+                                          "0"));
+    s.priority = (priority > 0 && priority <= UINT16_MAX
+                  ? priority
+                  : UINT16_MAX - !list_is_short(&port->ifaces));
+
     s.fast = !strcmp(get_port_other_config(port->cfg, "lacp-time", "slow"),
                      "fast");
 
-    if (s.priority <= 0 || s.priority > UINT16_MAX) {
-        /* Prefer bondable links if unspecified. */
-        s.priority = UINT16_MAX - !list_is_short(&port->ifaces);
-    }
-
     if (!port->lacp) {
         port->lacp = lacp_create();
     }