diff mbox series

[ovs-dev] ofproto-dpif: Refactor the get capability code.

Message ID 1574363342-84181-1-git-send-email-u9012063@gmail.com
State Accepted
Commit 551c72854ef78d9c188a58872b023e529e9d8843
Headers show
Series [ovs-dev] ofproto-dpif: Refactor the get capability code. | expand

Commit Message

William Tu Nov. 21, 2019, 7:09 p.m. UTC
Make the code simpler by removing the use of
xasprintf and free, and use smap_add_format.

Cc: Ben Pfaff <blp@ovn.org>
Signed-off-by: William Tu <u9012063@gmail.com>
---
 ofproto/ofproto-dpif.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Comments

Ben Pfaff Nov. 22, 2019, 5:28 p.m. UTC | #1
On Thu, Nov 21, 2019 at 11:09:02AM -0800, William Tu wrote:
> Make the code simpler by removing the use of
> xasprintf and free, and use smap_add_format.
> 
> Cc: Ben Pfaff <blp@ovn.org>
> Signed-off-by: William Tu <u9012063@gmail.com>

Looks good to me.

Acked-by: Ben Pfaff <blp@ovn.org>
William Tu Dec. 3, 2019, 12:20 a.m. UTC | #2
On Fri, Nov 22, 2019 at 09:28:14AM -0800, Ben Pfaff wrote:
> On Thu, Nov 21, 2019 at 11:09:02AM -0800, William Tu wrote:
> > Make the code simpler by removing the use of
> > xasprintf and free, and use smap_add_format.
> > 
> > Cc: Ben Pfaff <blp@ovn.org>
> > Signed-off-by: William Tu <u9012063@gmail.com>
> 
> Looks good to me.
> 
> Acked-by: Ben Pfaff <blp@ovn.org>

Thank you, applied to master
diff mbox series

Patch

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index fa73d06a82f4..e55c46964279 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -5447,7 +5447,6 @@  ct_del_zone_timeout_policy(const char *datapath_type, uint16_t zone_id)
 static void
 get_datapath_cap(const char *datapath_type, struct smap *cap)
 {
-    char *str_value;
     struct odp_support odp;
     struct dpif_backer_support s;
     struct dpif_backer *backer = shash_find_data(&all_dpif_backers,
@@ -5459,14 +5458,9 @@  get_datapath_cap(const char *datapath_type, struct smap *cap)
     odp = s.odp;
 
     /* ODP_SUPPORT_FIELDS */
-    str_value = xasprintf("%"PRIuSIZE, odp.max_vlan_headers);
-    smap_add(cap, "max_vlan_headers", str_value);
-    free(str_value);
-
-    str_value = xasprintf("%"PRIuSIZE, odp.max_mpls_depth);
-    smap_add(cap, "max_mpls_depth", str_value);
-    free(str_value);
-
+    smap_add_format(cap, "max_vlan_headers", "%"PRIuSIZE,
+                    odp.max_vlan_headers);
+    smap_add_format(cap, "max_mpls_depth", "%"PRIuSIZE, odp.max_mpls_depth);
     smap_add(cap, "recirc", odp.recirc ? "true" : "false");
     smap_add(cap, "ct_state", odp.ct_state ? "true" : "false");
     smap_add(cap, "ct_zone", odp.ct_zone ? "true" : "false");
@@ -5485,11 +5479,7 @@  get_datapath_cap(const char *datapath_type, struct smap *cap)
     smap_add(cap, "sample_nesting", s.sample_nesting ? "true" : "false");
     smap_add(cap, "ct_eventmask", s.ct_eventmask ? "true" : "false");
     smap_add(cap, "ct_clear", s.ct_clear ? "true" : "false");
-
-    str_value = xasprintf("%"PRIuSIZE, s.max_hash_alg);
-    smap_add(cap, "max_hash_alg", str_value);
-    free(str_value);
-
+    smap_add_format(cap, "max_hash_alg", "%"PRIuSIZE, s.max_hash_alg);
     smap_add(cap, "check_pkt_len", s.check_pkt_len ? "true" : "false");
     smap_add(cap, "ct_timeout", s.ct_timeout ? "true" : "false");
 }