> On Aug 14, 2018, at 11:56 AM, Yi-Hung Wei <yihung....@gmail.com> wrote:
> 
> +/* The caller takes ownership of 'struct ct_dpif_zone_limit *', and is
> + * responsible to free that struct. */
> +struct ct_dpif_zone_limit *
> +ct_dpif_pop_zone_limit(struct ovs_list *zone_limits)
> +{
> +    struct ct_dpif_zone_limit *zone_limit;
> +    LIST_FOR_EACH_POP (zone_limit, node, zone_limits) {
> +        return zone_limit;
> +    }
> +    OVS_NOT_REACHED();
> +}

Aborting seems like a pretty serious action to take on calling this when it's 
not empty--especially if there's not a comment about it in the description.  I 
think we would normally just return NULL if it's not empty.  However, I think 
the function may not be needed since it's only used by 
ct_dpif_free_zone_limits() and could be simplified somewhat.

What do you think of the incremental at the end?  (I've only compile-tested it.)

--Justin


-=-=-=-=-=-=-=-=-


diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c
index bb809d9920b5..d3e8c936d7e6 100644
--- a/lib/ct-dpif.c
+++ b/lib/ct-dpif.c
@@ -609,24 +609,14 @@ ct_dpif_push_zone_limit(struct ovs_list *zone_limits, 
uint16_t zone,
     ovs_list_push_back(zone_limits, &zone_limit->node);
 }
 
-/* The caller takes ownership of 'struct ct_dpif_zone_limit *', and is
- * responsible to free that struct. */
-struct ct_dpif_zone_limit *
-ct_dpif_pop_zone_limit(struct ovs_list *zone_limits)
-{
-    struct ct_dpif_zone_limit *zone_limit;
-    LIST_FOR_EACH_POP (zone_limit, node, zone_limits) {
-        return zone_limit;
-    }
-    OVS_NOT_REACHED();
-}
-
 void
 ct_dpif_free_zone_limits(struct ovs_list *zone_limits)
 {
     while (!ovs_list_is_empty(zone_limits)) {
-        struct ct_dpif_zone_limit *p = ct_dpif_pop_zone_limit(zone_limits);
-        free(p);
+        struct ovs_list *entry = ovs_list_pop_front(zone_limits);
+        struct ct_dpif_zone_limit* cdzl;
+        cdzl = CONTAINER_OF(entry, struct ct_dpif_zone_limit, node);
+        free(cdzl);
     }
 }
 
diff --git a/lib/ct-dpif.h b/lib/ct-dpif.h
index 71a1a2269522..decc14ffc2a0 100644
--- a/lib/ct-dpif.h
+++ b/lib/ct-dpif.h
@@ -221,7 +221,6 @@ void ct_dpif_format_tcp_stat(struct ds *, int, int);
 bool ct_dpif_parse_tuple(struct ct_dpif_tuple *, const char *s, struct ds *);
 void ct_dpif_push_zone_limit(struct ovs_list *, uint16_t zone, uint32_t limit,
                              uint32_t count);
-struct ct_dpif_zone_limit * ct_dpif_pop_zone_limit(struct ovs_list *);
 void ct_dpif_free_zone_limits(struct ovs_list *);
 bool ct_dpif_parse_zone_limit_tuple(const char *s, uint16_t *pzone,
                                     uint32_t *plimit, struct ds *);




_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to