]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: use ISPOWEROF2() at various places 24216/head
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Aug 2022 11:19:23 +0000 (13:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Aug 2022 11:37:29 +0000 (13:37 +0200)
src/fundamental/macro-fundamental.h
src/partition/repart.c

index 5c67d3e2f79711ecf6a93f2aacb6df7d79cc6870..8b483f0b50d21176049bd405f727ed0fbf94cee9 100644 (file)
         })
 
 static inline size_t ALIGN_TO(size_t l, size_t ali) {
-        /* Check that alignment is exponent of 2 */
-#if SIZE_MAX == UINT_MAX
-        assert(__builtin_popcount(ali) == 1);
-#elif SIZE_MAX == ULONG_MAX
-        assert(__builtin_popcountl(ali) == 1);
-#elif SIZE_MAX == ULLONG_MAX
-        assert(__builtin_popcountll(ali) == 1);
-#else
-        #error "Unexpected size_t"
-#endif
+        assert(ISPOWEROF2(ali));
 
         if (l > SIZE_MAX - (ali - 1))
                 return SIZE_MAX; /* indicate overflow */
@@ -357,7 +348,7 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
         __builtin_choose_expr(                                         \
                 __builtin_constant_p(l) &&                             \
                 __builtin_constant_p(ali) &&                           \
-                __builtin_popcountll(ali) == 1 && /* is power of 2? */ \
+                CONST_ISPOWEROF2(ali) &&                               \
                 (l <= SIZE_MAX - (ali - 1)),      /* overflow? */      \
                 ((l) + (ali) - 1) & ~((ali) - 1),                      \
                 VOID_0)
index 5cbe59cdf72cd2f8797c1d79db3e8d95a3574bcd..84e6c47d6745148b394cc262379b077803ef2c72 100644 (file)
@@ -1629,8 +1629,8 @@ static int context_load_partition_table(
         secsz = fdisk_get_sector_size(c);
 
         /* Insist on a power of two, and that it's a multiple of 512, i.e. the traditional sector size. */
-        if (secsz < 512 || secsz != 1UL << log2u64(secsz))
-                return log_error_errno(errno, "Sector size %lu is not a power of two larger than 512? Refusing.", secsz);
+        if (secsz < 512 || !ISPOWEROF2(secsz))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Sector size %lu is not a power of two larger than 512? Refusing.", secsz);
 
         /* Use at least 4K, and ensure it's a multiple of the sector size, regardless if that is smaller or
          * larger */