From 4ad2802695284467b559ca6790cd890359ffa159 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 10 Aug 2011 12:40:10 -0700 Subject: [PATCH] dpif-netdev: Avoid pointlessly maintaining a port count. 'n_ports' was only used for testing for nonzero, and we can rewrite the code that does that to more straightforwardly use LIST_FOR_EACH_SAFE. --- lib/dpif-netdev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 9f281c26..ffcc28a8 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -91,7 +91,6 @@ struct dp_netdev { long long int n_lost; /* Number of misses not passed to client. */ /* Ports. */ - int n_ports; struct dp_netdev_port *ports[MAX_PORTS]; struct list port_list; unsigned int serial; @@ -265,10 +264,10 @@ dp_netdev_purge_queues(struct dp_netdev *dp) static void dp_netdev_free(struct dp_netdev *dp) { + struct dp_netdev_port *port, *next; + dp_netdev_flow_flush(dp); - while (dp->n_ports > 0) { - struct dp_netdev_port *port = CONTAINER_OF( - dp->port_list.next, struct dp_netdev_port, node); + LIST_FOR_EACH_SAFE (port, next, node, &dp->port_list) { do_del_port(dp, port->port_no); } dp_netdev_purge_queues(dp); @@ -386,7 +385,6 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type, list_push_back(&dp->port_list, &port->node); dp->ports[port_no] = port; - dp->n_ports++; dp->serial++; return 0; @@ -464,7 +462,6 @@ do_del_port(struct dp_netdev *dp, uint16_t port_no) list_remove(&port->node); dp->ports[port->port_no] = NULL; - dp->n_ports--; dp->serial++; name = xstrdup(netdev_get_name(port->netdev)); -- 2.30.2