is_all_zeros() and is_all_ones() operate on bytes, but just like with
memset, it is easier to use if the first argument is a void *.

Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com>
---
 lib/meta-flow.c |   14 +++++++-------
 lib/odp-util.c  |    7 +++----
 lib/util.c      |    6 ++++--
 lib/util.h      |    4 ++--
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/lib/meta-flow.c b/lib/meta-flow.c
index b76c11d..3b82e62 100644
--- a/lib/meta-flow.c
+++ b/lib/meta-flow.c
@@ -1057,8 +1057,8 @@ mf_is_mask_valid(const struct mf_field *mf, const union 
mf_value *mask)
 {
     switch (mf->maskable) {
     case MFM_NONE:
-        return (is_all_zeros((const uint8_t *) mask, mf->n_bytes) ||
-                is_all_ones((const uint8_t *) mask, mf->n_bytes));
+        return (is_all_zeros(mask, mf->n_bytes) ||
+                is_all_ones(mask, mf->n_bytes));
 
     case MFM_FULLY:
         return true;
@@ -1904,7 +1904,7 @@ mf_is_zero(const struct mf_field *mf, const struct flow 
*flow)
     union mf_value value;
 
     mf_get_value(mf, flow, &value);
-    return is_all_zeros((const uint8_t *) &value, mf->n_bytes);
+    return is_all_zeros(&value, mf->n_bytes);
 }
 
 /* Makes 'match' wildcard field 'mf'.
@@ -2130,10 +2130,10 @@ mf_set(const struct mf_field *mf,
        const union mf_value *value, const union mf_value *mask,
        struct match *match)
 {
-    if (!mask || is_all_ones((const uint8_t *) mask, mf->n_bytes)) {
+    if (!mask || is_all_ones(mask, mf->n_bytes)) {
         mf_set_value(mf, value, match);
         return mf->usable_protocols;
-    } else if (is_all_zeros((const uint8_t *) mask, mf->n_bytes)) {
+    } else if (is_all_zeros(mask, mf->n_bytes)) {
         mf_set_wild(mf, match);
         return OFPUTIL_P_ANY;
     }
@@ -2861,10 +2861,10 @@ mf_format(const struct mf_field *mf,
           struct ds *s)
 {
     if (mask) {
-        if (is_all_zeros((const uint8_t *) mask, mf->n_bytes)) {
+        if (is_all_zeros(mask, mf->n_bytes)) {
             ds_put_cstr(s, "ANY");
             return;
-        } else if (is_all_ones((const uint8_t *) mask, mf->n_bytes)) {
+        } else if (is_all_ones(mask, mf->n_bytes)) {
             mask = NULL;
         }
     }
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 475502b..5c17f06 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -706,7 +706,7 @@ parse_odp_action(const char *s, const struct simap 
*port_names,
         size = nl_attr_get_size(mask);
         if (size == nl_attr_get_size(key)) {
             /* Change to masked set action if not fully masked. */
-            if (!is_all_ones((uint8_t *)(mask + 1), size)) {
+            if (!is_all_ones(mask + 1, size)) {
                 key->nla_len += size;
                 ofpbuf_put(actions, mask + 1, size);
                 /* 'actions' may have been reallocated by ofpbuf_put(). */
@@ -1097,7 +1097,7 @@ odp_mask_attr_is_exact(const struct nlattr *ma)
                                | FLOW_TNL_F_OAM)) {
             /* The flags are exact match, check the remaining fields. */
             tun_mask.flags = 0xffff;
-            is_exact = is_all_ones((uint8_t *)&tun_mask,
+            is_exact = is_all_ones(&tun_mask,
                                    offsetof(struct flow_tnl, ip_ttl));
         }
     } else {
@@ -3341,8 +3341,7 @@ parse_l2_5_onward(const struct nlattr 
*attrs[OVS_KEY_ATTR_MAX + 1],
                     memcpy(flow->arp_sha, nd_key->nd_sll, ETH_ADDR_LEN);
                     memcpy(flow->arp_tha, nd_key->nd_tll, ETH_ADDR_LEN);
                     if (is_mask) {
-                        if (!is_all_zeros((const uint8_t *) nd_key,
-                                          sizeof *nd_key) &&
+                        if (!is_all_zeros(nd_key, sizeof *nd_key) &&
                             (flow->tp_src != htons(0xffff) ||
                              flow->tp_dst != htons(0xffff))) {
                             return ODP_FIT_ERROR;
diff --git a/lib/util.c b/lib/util.c
index 4493ee0..f3e47b1 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -1025,8 +1025,9 @@ const uint8_t count_1bits_8[256] = {
 
 /* Returns true if the 'n' bytes starting at 'p' are zeros. */
 bool
-is_all_zeros(const uint8_t *p, size_t n)
+is_all_zeros(const void *p_, size_t n)
 {
+    const uint8_t *p = p_;
     size_t i;
 
     for (i = 0; i < n; i++) {
@@ -1039,8 +1040,9 @@ is_all_zeros(const uint8_t *p, size_t n)
 
 /* Returns true if the 'n' bytes starting at 'p' are 0xff. */
 bool
-is_all_ones(const uint8_t *p, size_t n)
+is_all_ones(const void *p_, size_t n)
 {
+    const uint8_t *p = p_;
     size_t i;
 
     for (i = 0; i < n; i++) {
diff --git a/lib/util.h b/lib/util.h
index dc34ee5..261b4b3 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -485,8 +485,8 @@ leftmost_1bit_idx(uint32_t x)
     return x ? log_2_floor(x) : 32;
 }
 
-bool is_all_zeros(const uint8_t *, size_t);
-bool is_all_ones(const uint8_t *, size_t);
+bool is_all_zeros(const void *, size_t);
+bool is_all_ones(const void *, size_t);
 void bitwise_copy(const void *src, unsigned int src_len, unsigned int src_ofs,
                   void *dst, unsigned int dst_len, unsigned int dst_ofs,
                   unsigned int n_bits);
-- 
1.7.10.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to