[ovs-dev] [PATCH 2/2] Eliminate most shadowing for local variable names.

Ben Pfaff blp at ovn.org
Wed Aug 2 15:56:36 UTC 2017


Shadowing is when a variable with a given name in an inner scope hides a
different variable with the same name in a surrounding scope.  This is
generally undesirable because it can confuse programmers.  This commit
eliminates most of it.

Found with -Wshadow=local in GCC 7.  The repo is not really ready to enable
this option by default because of a few cases that are harder to fix, and
harmless, such as nested use of CMAP_FOR_EACH.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 lib/classifier.c             |  2 --
 lib/daemon-unix.c            |  6 +++---
 lib/db-ctl-base.c            |  4 ++--
 lib/dpctl.c                  |  6 +++---
 lib/dpif-netdev.c            | 11 +++++-----
 lib/hash.c                   |  2 +-
 lib/learn.c                  |  7 +++----
 lib/lldp/lldpd.c             |  2 +-
 lib/netdev-dummy.c           | 12 +++++------
 lib/netdev-linux.c           |  2 +-
 lib/odp-util.c               | 10 ++++-----
 lib/ofp-print.c              |  4 ++--
 lib/ofp-util.c               |  1 -
 lib/ovsdb-idl.c              |  4 ++--
 lib/table.c                  |  3 +--
 lib/unixctl.c                |  6 ++----
 lib/vconn.c                  |  1 -
 lib/vlog.c                   |  3 ++-
 ofproto/ofproto-dpif-xlate.c | 15 +++++++-------
 ofproto/ofproto-dpif.c       | 13 ++++--------
 ovn/controller/ofctrl.c      |  1 -
 ovn/controller/patch.c       |  2 +-
 ovn/controller/physical.c    |  6 +++---
 ovn/lib/expr.c               | 12 +++++------
 ovn/northd/ovn-northd.c      | 36 ++++++++++++++-------------------
 ovn/utilities/ovn-trace.c    | 10 ++++-----
 ovsdb/jsonrpc-server.c       |  6 +++---
 ovsdb/replication.c          | 48 ++++++++++++++++++++++++--------------------
 tests/test-bundle.c          |  2 +-
 tests/test-ccmap.c           |  8 ++++----
 tests/test-classifier.c      |  8 +++-----
 tests/test-cmap.c            |  3 ---
 tests/test-odp.c             |  5 +----
 tests/test-ovn.c             |  1 -
 utilities/ovs-vsctl.c        |  3 +--
 vswitchd/bridge.c            | 30 ++++++++++-----------------
 vtep/vtep-ctl.c              |  1 -
 37 files changed, 129 insertions(+), 167 deletions(-)

diff --git a/lib/classifier.c b/lib/classifier.c
index 1b652df8df34..ca0650afb423 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -793,8 +793,6 @@ check_priority:
             && --subtable->max_count == 0) {
             /* Find the new 'max_priority' and 'max_count'. */
             int max_priority = INT_MIN;
-            struct cls_match *head;
-
             CMAP_FOR_EACH (head, cmap_node, &subtable->rules) {
                 if (head->priority > max_priority) {
                     max_priority = head->priority;
diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c
index 28f76da44c6e..5721373b7461 100644
--- a/lib/daemon-unix.c
+++ b/lib/daemon-unix.c
@@ -999,11 +999,11 @@ daemon_set_new_user(const char *user_spec)
         grpstr += strspn(grpstr, " \t\r\n");
 
         if (*grpstr) {
-            struct group grp, *res;
+            struct group grp, *gres;
 
             bufsize = init_bufsize;
             buf = xmalloc(bufsize);
-            while ((e = getgrnam_r(grpstr, &grp, buf, bufsize, &res))
+            while ((e = getgrnam_r(grpstr, &grp, buf, bufsize, &gres))
                          == ERANGE) {
                 if (!enlarge_buffer(&buf, &bufsize)) {
                     break;
@@ -1015,7 +1015,7 @@ daemon_set_new_user(const char *user_spec)
                            "(%s), aborting.", pidfile, grpstr,
                            ovs_strerror(e));
             }
-            if (res == NULL) {
+            if (gres == NULL) {
                 VLOG_FATAL("%s: group %s not found, aborting.", pidfile,
                            grpstr);
             }
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 90629d5d9913..d597c6c2af6f 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -313,9 +313,9 @@ get_row_by_id(struct ctl_context *ctx,
         if (!id->key) {
             name = datum->n == 1 ? &datum->keys[0] : NULL;
         } else {
-            const union ovsdb_atom key
+            const union ovsdb_atom key_atom
                 = { .string = CONST_CAST(char *, id->key) };
-            unsigned int i = ovsdb_datum_find_key(datum, &key,
+            unsigned int i = ovsdb_datum_find_key(datum, &key_atom,
                                                   OVSDB_TYPE_STRING);
             name = i == UINT_MAX ? NULL : &datum->values[i];
         }
diff --git a/lib/dpctl.c b/lib/dpctl.c
index 6aa6c8e9e2b0..c8b7b86caa71 100644
--- a/lib/dpctl.c
+++ b/lib/dpctl.c
@@ -336,7 +336,8 @@ dpctl_set_if(int argc, const char *argv[], struct dpctl_params *dpctl_p)
         struct smap args;
         odp_port_t port_no;
         char *option;
-        int error = 0;
+
+        error = 0;
 
         argcopy = xstrdup(argv[i]);
         name = strtok_r(argcopy, ",", &save_ptr);
@@ -1689,8 +1690,7 @@ dpctl_normalize_actions(int argc, const char *argv[],
     qsort(afs, n_afs, sizeof *afs, compare_actions_for_flow);
 
     for (i = 0; i < n_afs; i++) {
-        struct actions_for_flow *af = afs[i];
-
+        af = afs[i];
         sort_output_actions(af->actions.data, af->actions.size);
 
         for (encaps = 0; encaps < FLOW_MAX_VLAN_HEADERS; encaps ++) {
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 47a9fa0c5ff4..7b059268c982 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1010,14 +1010,13 @@ dpif_netdev_pmd_info(struct unixctl_conn *conn, int argc, const char *argv[],
         } else {
             unsigned long long stats[DP_N_STATS];
             uint64_t cycles[PMD_N_CYCLES];
-            int i;
 
             /* Read current stats and cycle counters */
-            for (i = 0; i < ARRAY_SIZE(stats); i++) {
-                atomic_read_relaxed(&pmd->stats.n[i], &stats[i]);
+            for (size_t j = 0; j < ARRAY_SIZE(stats); j++) {
+                atomic_read_relaxed(&pmd->stats.n[j], &stats[j]);
             }
-            for (i = 0; i < ARRAY_SIZE(cycles); i++) {
-                atomic_read_relaxed(&pmd->cycles.n[i], &cycles[i]);
+            for (size_t j = 0; j < ARRAY_SIZE(cycles); j++) {
+                atomic_read_relaxed(&pmd->cycles.n[j], &cycles[j]);
             }
 
             if (type == PMD_INFO_CLEAR_STATS) {
@@ -3306,7 +3305,6 @@ static void
 reconfigure_pmd_threads(struct dp_netdev *dp)
     OVS_REQUIRES(dp->port_mutex)
 {
-    struct dp_netdev_pmd_thread *pmd;
     struct ovs_numa_dump *pmd_cores;
     bool changed = false;
 
@@ -3325,6 +3323,7 @@ reconfigure_pmd_threads(struct dp_netdev *dp)
     if (ovs_numa_dump_count(pmd_cores) != cmap_count(&dp->poll_threads) - 1) {
         changed = true;
     } else {
+        struct dp_netdev_pmd_thread *pmd;
         CMAP_FOR_EACH (pmd, node, &dp->poll_threads) {
             if (pmd->core_id != NON_PMD_CORE_ID
                 && !ovs_numa_dump_contains_core(pmd_cores,
diff --git a/lib/hash.c b/lib/hash.c
index 321f9d927020..5ad63f2298c0 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -87,7 +87,6 @@ hash_bytes128(const void *p_, size_t len, uint32_t basis, ovs_u128 *out)
     uint32_t h2 = basis;
     uint32_t h3 = basis;
     uint32_t h4 = basis;
-    uint32_t k1, k2, k3, k4;
 
     /* Body */
     for (int i = 0; i < nblocks; i++) {
@@ -134,6 +133,7 @@ hash_bytes128(const void *p_, size_t len, uint32_t basis, ovs_u128 *out)
     }
 
     /* Tail */
+    uint32_t k1, k2, k3, k4;
     k1 = k2 = k3 = k4 = 0;
     tail = data + nblocks * 16;
     switch (len & 15) {
diff --git a/lib/learn.c b/lib/learn.c
index 4658b8611857..9e321371c0a5 100644
--- a/lib/learn.c
+++ b/lib/learn.c
@@ -342,14 +342,13 @@ learn_parse_spec(const char *orig, char *name, char *value,
                                  name, value);
             }
 
-            char *error = learn_parse_load_immediate(&imm, dst_value + 2, value, spec,
-                                                     ofpacts);
+            error = learn_parse_load_immediate(&imm, dst_value + 2, value, spec,
+                                               ofpacts);
             if (error) {
                 return error;
             }
         } else {
             struct ofpact_reg_move move;
-            char *error;
 
             error = nxm_parse_reg_move(&move, value);
             if (error) {
@@ -363,7 +362,7 @@ learn_parse_spec(const char *orig, char *name, char *value,
             spec->dst = move.dst;
         }
     } else if (!strcmp(name, "output")) {
-        char *error = mf_parse_subfield(&spec->src, value);
+        error = mf_parse_subfield(&spec->src, value);
         if (error) {
             return error;
         }
diff --git a/lib/lldp/lldpd.c b/lib/lldp/lldpd.c
index 60858b0d7ce7..e9d1cf18e036 100644
--- a/lib/lldp/lldpd.c
+++ b/lib/lldp/lldpd.c
@@ -339,7 +339,7 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s,
 
     /* No, but do we already know the system? */
     if (!oport) {
-        bool found = false;
+        found = false;
         VLOG_DBG("MSAP is unknown, search for the chassis");
 
         LIST_FOR_EACH (ochassis, list, &cfg->g_chassis) {
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index cad781104782..b4035e0e99d0 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -1102,11 +1102,11 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
 
         /* Reply to ARP requests for 'dev''s assigned IP address. */
         if (dev->address.s_addr) {
-            struct dp_packet packet;
+            struct dp_packet dp;
             struct flow flow;
 
-            dp_packet_use_const(&packet, buffer, size);
-            flow_extract(&packet, &flow);
+            dp_packet_use_const(&dp, buffer, size);
+            flow_extract(&dp, &flow);
             if (flow.dl_type == htons(ETH_TYPE_ARP)
                 && flow.nw_proto == ARP_OP_REQUEST
                 && flow.nw_dst == dev->address.s_addr) {
@@ -1118,10 +1118,10 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
         }
 
         if (dev->tx_pcap) {
-            struct dp_packet packet;
+            struct dp_packet dp;
 
-            dp_packet_use_const(&packet, buffer, size);
-            ovs_pcap_write(dev->tx_pcap, &packet);
+            dp_packet_use_const(&dp, buffer, size);
+            ovs_pcap_write(dev->tx_pcap, &dp);
             fflush(dev->tx_pcap);
         }
 
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index e1d87019f7f2..34f779638ff5 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -5373,7 +5373,7 @@ get_stats_via_netlink(const struct netdev *netdev_, struct netdev_stats *stats)
             netdev_stats_from_rtnl_link_stats64(stats, nl_attr_get(a));
             error = 0;
         } else {
-            const struct nlattr *a = nl_attr_find(reply, 0, IFLA_STATS);
+            a = nl_attr_find(reply, 0, IFLA_STATS);
             if (a && nl_attr_get_size(a) >= sizeof(struct rtnl_link_stats)) {
                 netdev_stats_from_rtnl_link_stats(stats, nl_attr_get(a));
                 error = 0;
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 9d95d5348e33..f7e9f4bf1475 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -4264,13 +4264,11 @@ static int
 parse_odp_key_mask_attr(const char *s, const struct simap *port_names,
                         struct ofpbuf *key, struct ofpbuf *mask)
 {
-    ovs_u128 ufid;
-    int len;
-
     /* Skip UFID. */
-    len = odp_ufid_from_string(s, &ufid);
-    if (len) {
-        return len;
+    ovs_u128 ufid;
+    int ufid_len = odp_ufid_from_string(s, &ufid);
+    if (ufid_len) {
+        return ufid_len;
     }
 
     SCAN_SINGLE("skb_priority(", uint32_t, u32, OVS_KEY_ATTR_PRIORITY);
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 92c000b61dea..16d617ab5008 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -2344,12 +2344,12 @@ ofp_async_config_reason_to_string(uint32_t reason,
 #define OFP_ASYNC_CONFIG_REASON_BUFSIZE (INT_STRLEN(int) + 1)
 static void
 ofp_print_set_async_config(struct ds *string, const struct ofp_header *oh,
-                           enum ofptype type)
+                           enum ofptype ofptype)
 {
     struct ofputil_async_cfg basis = OFPUTIL_ASYNC_CFG_INIT;
     struct ofputil_async_cfg ac;
 
-    bool is_reply = type == OFPTYPE_GET_ASYNC_REPLY;
+    bool is_reply = ofptype == OFPTYPE_GET_ASYNC_REPLY;
     enum ofperr error = ofputil_decode_set_async_config(oh, is_reply,
                                                         &basis, &ac);
     if (error) {
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 6ee7e11f87a5..354a6ce0ef99 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -8314,7 +8314,6 @@ ofputil_pull_ofp14_port_stats(struct ofputil_port_stats *ops,
                                                         len);
     while (properties.size > 0) {
         struct ofpbuf payload;
-        enum ofperr error;
         uint64_t type = 0;
 
         error = ofpprop_pull(&properties, &payload, &type);
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 893143c551f6..b6eb110f2331 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -787,10 +787,10 @@ ovsdb_idl_check_consistency(const struct ovsdb_idl *idl)
                     ok = false;
                 }
             }
-            for (size_t i = 0; i < n_dsts; i++) {
+            for (size_t j = 0; j < n_dsts; j++) {
                 VLOG_ERR("%s row "UUID_FMT" missing arc to row "UUID_FMT,
                          table->class->name, UUID_ARGS(&row->uuid),
-                         UUID_ARGS(&dsts[i]));
+                         UUID_ARGS(&dsts[j]));
                 ok = false;
             }
         }
diff --git a/lib/table.c b/lib/table.c
index 6136beb2fabd..e454dfbc8bf7 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -490,7 +490,6 @@ table_print_json__(const struct table *table, const struct table_style *style)
 {
     struct json *json, *headings, *data;
     size_t x, y;
-    char *s;
 
     json = json_object_create();
     if (table->caption) {
@@ -526,7 +525,7 @@ table_print_json__(const struct table *table, const struct table_style *style)
     }
     json_object_put(json, "data", data);
 
-    s = json_to_string(json, style->json_flags);
+    char *s = json_to_string(json, style->json_flags);
     json_destroy(json);
     puts(s);
     free(s);
diff --git a/lib/unixctl.c b/lib/unixctl.c
index 57d6577b219b..33c5412f1253 100644
--- a/lib/unixctl.c
+++ b/lib/unixctl.c
@@ -371,14 +371,11 @@ kill_connection(struct unixctl_conn *conn)
 void
 unixctl_server_run(struct unixctl_server *server)
 {
-    struct unixctl_conn *conn, *next;
-    int i;
-
     if (!server) {
         return;
     }
 
-    for (i = 0; i < 10; i++) {
+    for (int i = 0; i < 10; i++) {
         struct stream *stream;
         int error;
 
@@ -396,6 +393,7 @@ unixctl_server_run(struct unixctl_server *server)
         }
     }
 
+    struct unixctl_conn *conn, *next;
     LIST_FOR_EACH_SAFE (conn, next, node, &server->conns) {
         int error = run_connection(conn);
         if (error && error != EAGAIN) {
diff --git a/lib/vconn.c b/lib/vconn.c
index 8a9f0ca8fa96..17ecdab5ca95 100644
--- a/lib/vconn.c
+++ b/lib/vconn.c
@@ -877,7 +877,6 @@ vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *request,
     for (;;) {
         struct ofpbuf *msg;
         ovs_be32 msg_xid;
-        int error;
 
         error = vconn_recv_block(vconn, &msg);
         if (error) {
diff --git a/lib/vlog.c b/lib/vlog.c
index 08b57b6f5eea..6e87665fcd11 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -843,7 +843,6 @@ vlog_get_levels(void)
     struct ds s = DS_EMPTY_INITIALIZER;
     struct vlog_module *mp;
     struct svec lines = SVEC_EMPTY_INITIALIZER;
-    char *line;
     size_t i;
 
     ds_put_format(&s, "                 console    syslog    file\n");
@@ -869,6 +868,8 @@ vlog_get_levels(void)
     ovs_mutex_unlock(&log_file_mutex);
 
     svec_sort(&lines);
+
+    char *line;
     SVEC_FOR_EACH (i, line, &lines) {
         ds_put_cstr(&s, line);
     }
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index b2698b93b674..2f1f90784455 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -1899,14 +1899,14 @@ mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle,
             }
         } else if (xvlan.v[0].vid != out_vlan
                    && !eth_addr_is_reserved(ctx->xin->flow.dl_dst)) {
-            struct xbundle *xbundle;
+            struct xbundle *xb;
             uint16_t old_vid = xvlan.v[0].vid;
 
             xvlan.v[0].vid = out_vlan;
-            LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
-                if (xbundle_includes_vlan(xbundle, &xvlan)
-                    && !xbundle_mirror_out(xbridge, xbundle)) {
-                    output_normal(ctx, xbundle, &xvlan);
+            LIST_FOR_EACH (xb, list_node, &xbridge->xbundles) {
+                if (xbundle_includes_vlan(xb, &xvlan)
+                    && !xbundle_mirror_out(xbridge, xb)) {
+                    output_normal(ctx, xb, &xvlan);
                 }
             }
             xvlan.v[0].vid = old_vid;
@@ -6956,8 +6956,9 @@ xlate_send_packet(const struct ofport_dpif *ofport, bool oam,
     }
 
     if (oam) {
-        const ovs_be16 oam = htons(NX_TUN_FLAG_OAM);
-        ofpact_put_set_field(&ofpacts, mf_from_id(MFF_TUN_FLAGS), &oam, &oam);
+        const ovs_be16 flag = htons(NX_TUN_FLAG_OAM);
+        ofpact_put_set_field(&ofpacts, mf_from_id(MFF_TUN_FLAGS),
+                             &flag, &flag);
     }
 
     ofpact_put_OUTPUT(&ofpacts)->port = xport->ofp_port;
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index b82ed55d24d3..62972e6d03c2 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -4722,7 +4722,6 @@ group_dpif_credit_stats(struct group_dpif *group,
         bucket->stats.packet_count += stats->n_packets;
         bucket->stats.byte_count += stats->n_bytes;
     } else { /* Credit to all buckets */
-        struct ofputil_bucket *bucket;
         LIST_FOR_EACH (bucket, list_node, &group->up.buckets) {
             bucket->stats.packet_count += stats->n_packets;
             bucket->stats.byte_count += stats->n_bytes;
@@ -5203,14 +5202,10 @@ dpif_show_backer(const struct dpif_backer *backer, struct ds *ds)
 
             smap_init(&config);
             if (!netdev_get_config(ofport->netdev, &config)) {
-                const struct smap_node **nodes;
-                size_t i;
-
-                nodes = smap_sort(&config);
-                for (i = 0; i < smap_count(&config); i++) {
-                    const struct smap_node *node = nodes[i];
-                    ds_put_format(ds, "%c %s=%s", i ? ',' : ':',
-                                  node->key, node->value);
+                const struct smap_node **nodes = smap_sort(&config);
+                for (size_t k = 0; k < smap_count(&config); k++) {
+                    ds_put_format(ds, "%c %s=%s", k ? ',' : ':',
+                                  nodes[k]->key, nodes[k]->value);
                 }
                 free(nodes);
             }
diff --git a/ovn/controller/ofctrl.c b/ovn/controller/ofctrl.c
index 7164ff061b64..fc88a410b404 100644
--- a/ovn/controller/ofctrl.c
+++ b/ovn/controller/ofctrl.c
@@ -1026,7 +1026,6 @@ ofctrl_put(struct hmap *flow_table, struct shash *pending_ct_zones,
         }
 
         /* Store the barrier's xid with any newly sent ct flushes. */
-        struct shash_node *iter;
         SHASH_FOR_EACH(iter, pending_ct_zones) {
             struct ct_zone_pending_entry *ctzpe = iter->data;
             if (ctzpe->state == CT_ZONE_OF_SENT && !ctzpe->of_xid) {
diff --git a/ovn/controller/patch.c b/ovn/controller/patch.c
index 47cf7947f73f..d0cdd315cb52 100644
--- a/ovn/controller/patch.c
+++ b/ovn/controller/patch.c
@@ -256,7 +256,7 @@ patch_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
      * database but shouldn't.  Delete them from the database. */
     struct shash_node *port_node, *port_next_node;
     SHASH_FOR_EACH_SAFE (port_node, port_next_node, &existing_ports) {
-        struct ovsrec_port *port = port_node->data;
+        port = port_node->data;
         shash_delete(&existing_ports, port_node);
         remove_port(ctx, port);
     }
diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c
index 719b020ce7fe..36f9bf644de0 100644
--- a/ovn/controller/physical.c
+++ b/ovn/controller/physical.c
@@ -816,11 +816,11 @@ consider_mc_group(enum mf_field_id mff_ovn_geneve,
                      remote_ofpacts_p);
         }
 
-        const char *chassis;
+        const char *chassis_name;
         const struct chassis_tunnel *prev = NULL;
-        SSET_FOR_EACH (chassis, &remote_chassis) {
+        SSET_FOR_EACH (chassis_name, &remote_chassis) {
             const struct chassis_tunnel *tun
-                = chassis_tunnel_find(chassis);
+                = chassis_tunnel_find(chassis_name);
             if (!tun) {
                 continue;
             }
diff --git a/ovn/lib/expr.c b/ovn/lib/expr.c
index ba1fb03bf995..060e9ee3d088 100644
--- a/ovn/lib/expr.c
+++ b/ovn/lib/expr.c
@@ -2377,9 +2377,9 @@ expr_sort(struct expr *expr)
     qsort(subs, n, sizeof *subs, compare_expr_sort);
 
     ovs_list_init(&expr->andor);
-    for (int i = 0; i < n; ) {
+    for (i = 0; i < n; ) {
         if (subs[i].relop) {
-            int j;
+            size_t j;
             for (j = i + 1; j < n; j++) {
                 if (subs[i].relop != subs[j].relop) {
                     break;
@@ -2391,7 +2391,7 @@ expr_sort(struct expr *expr)
                 crushed = crush_cmps(subs[i].expr, subs[i].relop);
             } else {
                 struct expr *combined = subs[i].expr;
-                for (int k = i + 1; k < j; k++) {
+                for (size_t k = i + 1; k < j; k++) {
                     combined = expr_combine(EXPR_T_AND, combined,
                                             subs[k].expr);
                 }
@@ -2400,7 +2400,7 @@ expr_sort(struct expr *expr)
             }
             if (crushed->type == EXPR_T_BOOLEAN) {
                 if (!crushed->boolean) {
-                    for (int k = j; k < n; k++) {
+                    for (size_t k = j; k < n; k++) {
                         expr_destroy(subs[k].expr);
                     }
                     expr_destroy(expr);
@@ -2528,9 +2528,9 @@ expr_normalize_or(struct expr *expr)
         return expr_create_boolean(false);
     }
     if (ovs_list_is_short(&expr->andor)) {
-        struct expr *sub = expr_from_node(ovs_list_pop_front(&expr->andor));
+        struct expr *e = expr_from_node(ovs_list_pop_front(&expr->andor));
         free(expr);
-        return sub;
+        return e;
     }
 
     return expr;
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 10e0c7ce044b..3e3a789e51fb 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -1847,10 +1847,10 @@ ovn_port_update_sbrec(struct northd_context *ctx,
     if (op->nbrp) {
         /* If the router is for l3 gateway, it resides on a chassis
          * and its port type is "l3gateway". */
-        const char *chassis = smap_get(&op->od->nbr->options, "chassis");
+        const char *chassis_name = smap_get(&op->od->nbr->options, "chassis");
         if (op->derived) {
             sbrec_port_binding_set_type(op->sb, "chassisredirect");
-        } else if (chassis) {
+        } else if (chassis_name) {
             sbrec_port_binding_set_type(op->sb, "l3gateway");
         } else {
             sbrec_port_binding_set_type(op->sb, "patch");
@@ -1925,8 +1925,8 @@ ovn_port_update_sbrec(struct northd_context *ctx,
         } else {
             const char *peer = op->peer ? op->peer->key : "<error>";
             smap_add(&new, "peer", peer);
-            if (chassis) {
-                smap_add(&new, "l3gateway-chassis", chassis);
+            if (chassis_name) {
+                smap_add(&new, "l3gateway-chassis", chassis_name);
             }
         }
         sbrec_port_binding_set_options(op->sb, &new);
@@ -2764,9 +2764,7 @@ build_dhcpv6_action(struct ovn_port *op, struct in6_addr *offer_ip,
     /* Check whether the dhcpv6 options should be configured as stateful.
      * Only reply with ia_addr option for dhcpv6 stateful address mode. */
     if (!smap_get_bool(options_map, "dhcpv6_stateless", false)) {
-        char ia_addr[INET6_ADDRSTRLEN + 1];
         ipv6_string_mapped(ia_addr, offer_ip);
-
         ds_put_format(options_action, "ia_addr = %s, ", ia_addr);
     }
 
@@ -3722,7 +3720,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                 if (build_dhcpv4_action(
                         op, op->lsp_addrs[i].ipv4_addrs[j].addr,
                         &options_action, &response_action, &ipv4_addr_match)) {
-                    struct ds match = DS_EMPTY_INITIALIZER;
+                    ds_clear(&match);
                     ds_put_format(
                         &match, "inport == %s && eth.src == %s && "
                         "ip4.src == 0.0.0.0 && ip4.dst == 255.255.255.255 && "
@@ -3761,7 +3759,6 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                     ovn_lflow_add(lflows, op->od, S_SWITCH_IN_DHCP_RESPONSE,
                                   100, ds_cstr(&match),
                                   ds_cstr(&response_action));
-                    ds_destroy(&match);
                     ds_destroy(&options_action);
                     ds_destroy(&response_action);
                     ds_destroy(&ipv4_addr_match);
@@ -3775,7 +3772,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                 if (build_dhcpv6_action(
                         op, &op->lsp_addrs[i].ipv6_addrs[j].addr,
                         &options_action, &response_action)) {
-                    struct ds match = DS_EMPTY_INITIALIZER;
+                    ds_clear(&match);
                     ds_put_format(
                         &match, "inport == %s && eth.src == %s"
                         " && ip6.dst == ff02::1:2 && udp.src == 546 &&"
@@ -3790,7 +3787,6 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                     ds_put_cstr(&match, " && "REGBIT_DHCP_OPTS_RESULT);
                     ovn_lflow_add(lflows, op->od, S_SWITCH_IN_DHCP_RESPONSE, 100,
                                   ds_cstr(&match), ds_cstr(&response_action));
-                    ds_destroy(&match);
                     ds_destroy(&options_action);
                     ds_destroy(&response_action);
                     break;
@@ -3807,10 +3803,9 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
            continue;
         }
 
-        struct ds match;
-        struct ds action;
-        ds_init(&match);
-        ds_init(&action);
+        struct ds action = DS_EMPTY_INITIALIZER;
+
+        ds_clear(&match);
         ds_put_cstr(&match, "udp.dst == 53");
         ds_put_format(&action,
                       REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
@@ -3829,7 +3824,6 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                       "flags.loopback = 1; output;");
         ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
                       ds_cstr(&match), ds_cstr(&action));
-        ds_destroy(&match);
         ds_destroy(&action);
     }
 
@@ -3937,9 +3931,9 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                  * distributed logical routers. */
                 if (op->peer->od->l3dgw_port
                     && op->peer == op->peer->od->l3dgw_port) {
-                    for (int i = 0; i < op->peer->od->nbr->n_nat; i++) {
+                    for (int j = 0; j < op->peer->od->nbr->n_nat; j++) {
                         const struct nbrec_nat *nat
-                                                  = op->peer->od->nbr->nat[i];
+                                                  = op->peer->od->nbr->nat[j];
                         if (!strcmp(nat->type, "dnat_and_snat")
                             && nat->logical_port && nat->external_mac
                             && eth_addr_from_string(nat->external_mac, &mac)) {
@@ -4170,7 +4164,7 @@ build_static_route_flow(struct hmap *lflows, struct ovn_datapath *od,
         free(error);
 
         struct in6_addr ip6;
-        char *error = ipv6_parse_cidr(route->nexthop, &ip6, &plen);
+        error = ipv6_parse_cidr(route->nexthop, &ip6, &plen);
         if (!error) {
             if (plen != 128) {
                 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
@@ -5148,8 +5142,8 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
                               "clone { ct_clear; "
                               "inport = outport; outport = \"\"; "
                               "flags = 0; flags.loopback = 1; ");
-                for (int i = 0; i < MFF_N_LOG_REGS; i++) {
-                    ds_put_format(&actions, "reg%d = 0; ", i);
+                for (int j = 0; j < MFF_N_LOG_REGS; j++) {
+                    ds_put_format(&actions, "reg%d = 0; ", j);
                 }
                 ds_put_format(&actions, REGBIT_EGRESS_LOOPBACK" = 1; "
                               "next(pipeline=ingress, table=0); };");
@@ -5874,7 +5868,7 @@ sync_dns_entries(struct northd_context *ctx, struct hmap *datapaths)
     struct dns_info *dns_info;
     HMAP_FOR_EACH_POP (dns_info, hmap_node, &dns_map) {
         if (!dns_info->sb_dns) {
-            struct sbrec_dns *sbrec_dns = sbrec_dns_insert(ctx->ovnsb_txn);
+            sbrec_dns = sbrec_dns_insert(ctx->ovnsb_txn);
             dns_info->sb_dns = sbrec_dns;
             char *dns_id = xasprintf(
                 UUID_FMT, UUID_ARGS(&dns_info->nb_dns->header_.uuid));
diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
index 0fe05f839cc6..59083eebe270 100644
--- a/ovn/utilities/ovn-trace.c
+++ b/ovn/utilities/ovn-trace.c
@@ -948,7 +948,7 @@ ovntrace_port_lookup_by_name(const char *name)
 
     struct shash_node *node;
     SHASH_FOR_EACH (node, &ports) {
-        const struct ovntrace_port *port = node->data;
+        port = node->data;
 
         if (port->name2 && !strcmp(port->name2, name)) {
             if (match) {
@@ -960,9 +960,8 @@ ovntrace_port_lookup_by_name(const char *name)
     }
 
     if (uuid_is_partial_string(name) >= 4) {
-        struct shash_node *node;
         SHASH_FOR_EACH (node, &ports) {
-            const struct ovntrace_port *port = node->data;
+            port = node->data;
 
             struct uuid name_uuid;
             if (uuid_is_partial_match(&port->uuid, name)
@@ -1562,17 +1561,16 @@ execute_put_dhcp_opts(const struct ovnact_put_dhcp_opts *pdo,
     }
     ovntrace_node_append(super, OVNTRACE_NODE_MODIFY, "%s(%s)",
                          name, ds_cstr(&s));
-    ds_destroy(&s);
 
     struct mf_subfield dst = expr_resolve_field(&pdo->dst);
     if (!mf_is_register(dst.field->id)) {
         /* Format assignment. */
-        struct ds s = DS_EMPTY_INITIALIZER;
+        ds_clear(&s);
         expr_field_format(&pdo->dst, &s);
         ovntrace_node_append(super, OVNTRACE_NODE_MODIFY,
                              "%s = 1", ds_cstr(&s));
-        ds_destroy(&s);
     }
+    ds_destroy(&s);
 
     struct mf_subfield sf = expr_resolve_field(&pdo->dst);
     union mf_subvalue sv = { .u8_val = 1 };
diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 1770c2616b57..27cbd8449e3f 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -1480,10 +1480,10 @@ ovsdb_jsonrpc_monitor_cond_change(struct ovsdb_jsonrpc_session *s,
                                     &m->unflushed, m->condition, m->version);
     if (update_json) {
         struct jsonrpc_msg *msg;
-        struct json *params;
+        struct json *p;
 
-        params = json_array_create_2(json_clone(m->monitor_id), update_json);
-        msg = ovsdb_jsonrpc_create_notify(m, params);
+        p = json_array_create_2(json_clone(m->monitor_id), update_json);
+        msg = ovsdb_jsonrpc_create_notify(m, p);
         jsonrpc_session_send(s->js, msg);
     }
 
diff --git a/ovsdb/replication.c b/ovsdb/replication.c
index b896adc4121b..304212d9d93a 100644
--- a/ovsdb/replication.c
+++ b/ovsdb/replication.c
@@ -145,6 +145,30 @@ replication_add_local_db(const char *database, struct ovsdb *db)
     shash_add_assert(&local_dbs, database, db);
 }
 
+static void
+send_schema_requests(const struct json *result)
+{
+    for (size_t i = 0; i < result->u.array.n; i++) {
+        const struct json *name = result->u.array.elems[i];
+        if (name->type == JSON_STRING) {
+            /* Send one schema request for each remote DB. */
+            const char *db_name = json_string(name);
+            struct ovsdb *db = find_db(db_name);
+            if (db) {
+                struct jsonrpc_msg *request =
+                    jsonrpc_create_request(
+                        "get_schema",
+                        json_array_create_1(
+                            json_string_create(db_name)),
+                        NULL);
+
+                request_ids_add(request->id, db);
+                jsonrpc_session_send(session, request);
+            }
+        }
+    }
+}
+
 void
 replication_run(void)
 {
@@ -245,26 +269,7 @@ replication_run(void)
                     ovsdb_error_assert(error);
                     state = RPL_S_ERR;
                 } else {
-                    size_t i;
-                    for (i = 0; i < msg->result->u.array.n; i++) {
-                        const struct json *name = msg->result->u.array.elems[i];
-                        if (name->type == JSON_STRING) {
-                            /* Send one schema request for each remote DB. */
-                            const char *db_name = json_string(name);
-                            struct ovsdb *db = find_db(db_name);
-                            if (db) {
-                                struct jsonrpc_msg *request =
-                                    jsonrpc_create_request(
-                                        "get_schema",
-                                        json_array_create_1(
-                                            json_string_create(db_name)),
-                                        NULL);
-
-                                request_ids_add(request->id, db);
-                                jsonrpc_session_send(session, request);
-                            }
-                        }
-                    }
+                    send_schema_requests(msg->result);
                     VLOG_DBG("Send schema requests");
                     state = RPL_S_SCHEMA_REQUESTED;
                 }
@@ -299,7 +304,7 @@ replication_run(void)
 
                     SHASH_FOR_EACH_SAFE (node, next, replication_dbs) {
                         db = node->data;
-                        struct ovsdb_error *error = reset_database(db);
+                        error = reset_database(db);
                         if (error) {
                             const char *db_name = db->schema->name;
                             shash_find_and_delete(replication_dbs, db_name);
@@ -315,7 +320,6 @@ replication_run(void)
                     } else {
                         SHASH_FOR_EACH (node, replication_dbs) {
                             db = node->data;
-                            struct ovsdb *db = node->data;
                             struct jsonrpc_msg *request =
                                 create_monitor_request(db);
 
diff --git a/tests/test-bundle.c b/tests/test-bundle.c
index af25432002eb..124ad5b434d1 100644
--- a/tests/test-bundle.c
+++ b/tests/test-bundle.c
@@ -218,7 +218,7 @@ test_bundle_main(int argc, char *argv[])
                mask_str(mask, sg.n_slaves), disruption, perfect);
 
         for (j = 0 ; j < sg.n_slaves; j++) {
-            struct slave *slave = &sg.slaves[j];
+            slave = &sg.slaves[j];
             double flow_percent;
 
             flow_percent = slave->flow_count / (double)N_FLOWS;
diff --git a/tests/test-ccmap.c b/tests/test-ccmap.c
index 5ebc659dd77b..5c51bbe83619 100644
--- a/tests/test-ccmap.c
+++ b/tests/test-ccmap.c
@@ -58,8 +58,8 @@ check_ccmap(struct ccmap *ccmap, const int values[], size_t n, hash_func *hash)
 
     /* Check that all the values are there in lookup. */
     for (i = 0; i < n; i++) {
-        uint32_t hash = hashes[i];
-        size_t count = ccmap_find(ccmap, hash);
+        uint32_t h = hashes[i];
+        size_t count = ccmap_find(ccmap, h);
 
         assert(count);   /* Must have at least one. */
         assert(i + count <= n); /* May not have too many. */
@@ -67,11 +67,11 @@ check_ccmap(struct ccmap *ccmap, const int values[], size_t n, hash_func *hash)
         /* Skip colliding hash values and assert they were in the count. */
         while (--count) {
             i++;
-            assert(hashes[i] == hash);
+            assert(hashes[i] == h);
         }
         /* Make sure next hash is different. */
         if (i + 1 < n) {
-            assert(hashes[i + 1] != hash);
+            assert(hashes[i + 1] != h);
         }
     }
 
diff --git a/tests/test-classifier.c b/tests/test-classifier.c
index 37baad2a4bab..33de3db3c5ee 100644
--- a/tests/test-classifier.c
+++ b/tests/test-classifier.c
@@ -1537,7 +1537,6 @@ static bool
 next_random_flow(struct flow *flow, unsigned int idx)
 {
     uint32_t *flow_u32 = (uint32_t *) flow;
-    int i;
 
     memset(flow, 0, sizeof *flow);
 
@@ -1547,14 +1546,14 @@ next_random_flow(struct flow *flow, unsigned int idx)
     }
 
     /* All flows with a small number of consecutive nonzero values. */
-    for (i = 1; i <= 4; i++) {
+    for (int i = 1; i <= 4; i++) {
         if (init_consecutive_values(i, flow, &idx)) {
             return true;
         }
     }
 
     /* All flows with a large number of consecutive nonzero values. */
-    for (i = FLOW_U32S - 4; i <= FLOW_U32S; i++) {
+    for (int i = FLOW_U32S - 4; i <= FLOW_U32S; i++) {
         if (init_consecutive_values(i, flow, &idx)) {
             return true;
         }
@@ -1581,9 +1580,8 @@ next_random_flow(struct flow *flow, unsigned int idx)
     /* 16 randomly chosen flows with N >= 3 nonzero values. */
     if (choose(16 * (FLOW_U32S - 4), &idx)) {
         int n = idx / 16 + 3;
-        int i;
 
-        for (i = 0; i < n; i++) {
+        for (int i = 0; i < n; i++) {
             flow_u32[i] = random_value();
         }
         shuffle_u32s(flow_u32, FLOW_U32S);
diff --git a/tests/test-cmap.c b/tests/test-cmap.c
index 2c6fa89eb775..07054756066c 100644
--- a/tests/test-cmap.c
+++ b/tests/test-cmap.c
@@ -78,7 +78,6 @@ check_cmap(struct cmap *cmap, const int values[], size_t n,
     /* Here we test iteration with cmap_next_position() */
     i = 0;
     while ((node = cmap_next_position(cmap, &pos))) {
-        struct element *e = NULL;
         e = OBJECT_CONTAINING(node, e, node);
 
         assert(i < n);
@@ -128,8 +127,6 @@ check_cmap(struct cmap *cmap, const int values[], size_t n,
         map = cmap_find_batch(cmap, map, hashes, nodes);
 
         ULLONG_FOR_EACH_1(k, map) {
-            struct element *e;
-
             CMAP_NODE_FOR_EACH (e, node, nodes[k]) {
                 count += e->value == values[i + k];
             }
diff --git a/tests/test-odp.c b/tests/test-odp.c
index bccdcf8bde33..1f1ff9ad630f 100644
--- a/tests/test-odp.c
+++ b/tests/test-odp.c
@@ -178,14 +178,11 @@ parse_filter(char *filter_parse)
         struct ofpbuf odp_key;
         struct ofpbuf odp_mask;
         struct ds out;
-        int error;
 
         /* Convert string to OVS DP key. */
         ofpbuf_init(&odp_key, 0);
         ofpbuf_init(&odp_mask, 0);
-        error = odp_flow_from_string(ds_cstr(&in), NULL,
-                                     &odp_key, &odp_mask);
-        if (error) {
+        if (odp_flow_from_string(ds_cstr(&in), NULL, &odp_key, &odp_mask)) {
             printf("odp_flow_from_string: error\n");
             goto next;
         }
diff --git a/tests/test-ovn.c b/tests/test-ovn.c
index a216b820a02c..694bc794a923 100644
--- a/tests/test-ovn.c
+++ b/tests/test-ovn.c
@@ -373,7 +373,6 @@ test_evaluate_expr(struct ovs_cmdl_context *ctx)
     ds_init(&input);
     while (!ds_get_test_line(&input, stdin)) {
         struct expr *expr;
-        char *error;
 
         expr = expr_parse_string(ds_cstr(&input), &symtab, NULL, &error);
         if (!error) {
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 992c0dd13187..548992e42845 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -1503,7 +1503,6 @@ add_port(struct ctl_context *ctx,
          char *settings[], int n_settings)
 {
     struct vsctl_context *vsctl_ctx = vsctl_context_cast(ctx);
-    struct vsctl_port *vsctl_port;
     struct vsctl_bridge *bridge;
     struct ovsrec_interface **ifaces;
     struct ovsrec_port *port;
@@ -1593,7 +1592,7 @@ add_port(struct ctl_context *ctx,
     bridge_insert_port((bridge->parent ? bridge->parent->br_cfg
                         : bridge->br_cfg), port);
 
-    vsctl_port = add_port_to_cache(vsctl_ctx, bridge, port);
+    struct vsctl_port *vsctl_port = add_port_to_cache(vsctl_ctx, bridge, port);
     for (i = 0; i < n_ifaces; i++) {
         add_iface_to_cache(vsctl_ctx, vsctl_port, ifaces[i]);
     }
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 16d83c9a7c71..3dca0eb17c0f 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -1740,8 +1740,7 @@ add_del_bridges(const struct ovsrec_open_vswitch *cfg)
     /* Add new bridges. */
     SHASH_FOR_EACH(node, &new_br) {
         const struct ovsrec_bridge *br_cfg = node->data;
-        struct bridge *br = bridge_lookup(br_cfg->name);
-        if (!br) {
+        if (!bridge_lookup(br_cfg->name)) {
             bridge_create(br_cfg);
         }
     }
@@ -1874,9 +1873,6 @@ iface_create(struct bridge *br, const struct ovsrec_interface *iface_cfg,
 
         if (ofproto_port_query_by_name(br->ofproto, port->name,
                                        &ofproto_port)) {
-            struct netdev *netdev;
-            int error;
-
             error = netdev_open(port->name, "internal", &netdev);
             if (!error) {
                 ofp_port_t fake_ofp_port = OFPP_NONE;
@@ -3417,11 +3413,11 @@ bridge_del_ports(struct bridge *br, const struct shash *wanted_ports)
 
     /* Update iface->cfg and iface->type in interfaces that still exist. */
     SHASH_FOR_EACH (port_node, wanted_ports) {
-        const struct ovsrec_port *port = port_node->data;
+        const struct ovsrec_port *port_rec = port_node->data;
         size_t i;
 
-        for (i = 0; i < port->n_interfaces; i++) {
-            const struct ovsrec_interface *cfg = port->interfaces[i];
+        for (i = 0; i < port_rec->n_interfaces; i++) {
+            const struct ovsrec_interface *cfg = port_rec->interfaces[i];
             struct iface *iface = iface_lookup(br, cfg->name);
             const char *type = iface_get_type(cfg, br->cfg);
             const char *dp_type = br->cfg->datapath_type;
@@ -3684,7 +3680,7 @@ bridge_configure_tables(struct bridge *br)
 {
     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
     int n_tables;
-    int i, j, k;
+    int i, j;
 
     n_tables = ofproto_get_n_tables(br->ofproto);
     j = 0;
@@ -3712,7 +3708,7 @@ bridge_configure_tables(struct bridge *br)
                                  && !strcmp(cfg->overflow_policy, "evict"));
             if (cfg->n_groups) {
                 s.groups = xmalloc(cfg->n_groups * sizeof *s.groups);
-                for (k = 0; k < cfg->n_groups; k++) {
+                for (int k = 0; k < cfg->n_groups; k++) {
                     const char *string = cfg->groups[k];
                     char *msg;
 
@@ -3733,7 +3729,7 @@ bridge_configure_tables(struct bridge *br)
 
             /* Prefix lookup fields. */
             s.n_prefix_fields = 0;
-            for (k = 0; k < cfg->n_prefixes; k++) {
+            for (int k = 0; k < cfg->n_prefixes; k++) {
                 const char *name = cfg->prefixes[k];
                 const struct mf_field *mf;
 
@@ -3768,9 +3764,8 @@ bridge_configure_tables(struct bridge *br)
             memcpy(s.prefix_fields, default_prefix_fields,
                    sizeof default_prefix_fields);
         } else {
-            int k;
             struct ds ds = DS_EMPTY_INITIALIZER;
-            for (k = 0; k < s.n_prefix_fields; k++) {
+            for (int k = 0; k < s.n_prefix_fields; k++) {
                 if (k) {
                     ds_put_char(&ds, ',');
                 }
@@ -3904,8 +3899,7 @@ bridge_configure_aa(struct bridge *br)
 
     /* Add new mappings and reconfigure existing ones. */
     for (i = 0; i < auto_attach->n_mappings; ++i) {
-        struct aa_mapping *m =
-            bridge_aa_mapping_find(br, auto_attach->key_mappings[i]);
+        m = bridge_aa_mapping_find(br, auto_attach->key_mappings[i]);
 
         if (!m) {
             VLOG_INFO("Adding isid=%"PRId64", vlan=%"PRId64,
@@ -4524,7 +4518,7 @@ iface_configure_qos(struct iface *iface, const struct ovsrec_qos *qos)
         queue_zero = false;
         for (i = 0; i < qos->n_queues; i++) {
             const struct ovsrec_queue *queue = qos->value_queues[i];
-            unsigned int queue_id = qos->key_queues[i];
+            queue_id = qos->key_queues[i];
 
             if (queue_id == 0) {
                 queue_zero = true;
@@ -4542,8 +4536,6 @@ iface_configure_qos(struct iface *iface, const struct ovsrec_qos *qos)
             netdev_set_queue(iface->netdev, queue_id, &queue->other_config);
         }
         if (!queue_zero) {
-            struct smap details;
-
             smap_init(&details);
             netdev_set_queue(iface->netdev, 0, &details);
             smap_destroy(&details);
@@ -4688,7 +4680,7 @@ bridge_configure_mirrors(struct bridge *br)
     /* Add new mirrors and reconfigure existing ones. */
     for (i = 0; i < br->cfg->n_mirrors; i++) {
         const struct ovsrec_mirror *cfg = br->cfg->mirrors[i];
-        struct mirror *m = mirror_find_by_uuid(br, &cfg->header_.uuid);
+        m = mirror_find_by_uuid(br, &cfg->header_.uuid);
         if (!m) {
             m = mirror_create(br, cfg);
         }
diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c
index 17afa0c591b4..0b984f0a59a3 100644
--- a/vtep/vtep-ctl.c
+++ b/vtep/vtep-ctl.c
@@ -1086,7 +1086,6 @@ vtep_ctl_context_populate_cache(struct ctl_context *ctx)
             port = add_port_to_cache(vtepctl_ctx, ps, port_cfg);
 
             for (k = 0; k < port_cfg->n_vlan_bindings; k++) {
-                struct vteprec_logical_switch *ls_cfg;
                 struct vtep_ctl_lswitch *ls;
                 char *vlan;
 
-- 
2.10.2



More information about the dev mailing list