eal: replace unsigned -1 with unsigned maximums
authorTyler Retzlaff <roretzla@linux.microsoft.com>
Tue, 16 Mar 2021 00:13:31 +0000 (17:13 -0700)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 19 Apr 2021 09:29:45 +0000 (11:29 +0200)
Use UINT64_MAX and UINT32_MAX instead of -1 or ~0 literal variations
of different explicit widths when creating masks and sentinel values.

Some compilers generate a warning when applying a '-' to an unsigned
literal so avoid this by initializing with unsigned preprocessor
definitions where appropriate.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
lib/librte_eal/common/eal_common_fbarray.c
lib/librte_eal/common/eal_common_log.c

index 592ec58..3a28a53 100644 (file)
@@ -138,7 +138,7 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
         */
        last = MASK_LEN_TO_IDX(arr->len);
        last_mod = MASK_LEN_TO_MOD(arr->len);
-       last_msk = ~(-1ULL << last_mod);
+       last_msk = ~(UINT64_MAX << last_mod);
 
        for (msk_idx = first; msk_idx < msk->n_masks; msk_idx++) {
                uint64_t cur_msk, lookahead_msk;
@@ -398,8 +398,8 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
        first_mod = MASK_LEN_TO_MOD(start);
        /* we're going backwards, so mask must start from the top */
        ignore_msk = first_mod == MASK_ALIGN - 1 ?
-                               -1ULL : /* prevent overflow */
-                               ~(-1ULL << (first_mod + 1));
+                               UINT64_MAX : /* prevent overflow */
+                               ~(UINT64_MAX << (first_mod + 1));
 
        /* go backwards, include zero */
        msk_idx = first;
@@ -513,7 +513,7 @@ find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
                                 * no runs in the space we've lookbehind-scanned
                                 * as well, so skip that on next iteration.
                                 */
-                               ignore_msk = -1ULL << need;
+                               ignore_msk = UINT64_MAX << need;
                                msk_idx = lookbehind_idx;
                                break;
                        }
@@ -560,8 +560,8 @@ find_prev(const struct rte_fbarray *arr, unsigned int start, bool used)
        first_mod = MASK_LEN_TO_MOD(start);
        /* we're going backwards, so mask must start from the top */
        ignore_msk = first_mod == MASK_ALIGN - 1 ?
-                               -1ULL : /* prevent overflow */
-                               ~(-1ULL << (first_mod + 1));
+                               UINT64_MAX : /* prevent overflow */
+                               ~(UINT64_MAX << (first_mod + 1));
 
        /* go backwards, include zero */
        idx = first;
index cedf9f0..ec8fe23 100644 (file)
@@ -31,7 +31,7 @@ static struct rte_logs {
        size_t dynamic_types_len;
        struct rte_log_dynamic_type *dynamic_types;
 } rte_logs = {
-       .type = ~0,
+       .type = UINT32_MAX,
        .level = RTE_LOG_DEBUG,
 };