@@ -289,7 +289,7 @@ static const char * __must_check get_page_state_name(enum vdo_page_buffer_state
"UDS_FREE", "INCOMING", "FAILED", "RESIDENT", "DIRTY", "OUTGOING"
};
- STATIC_ASSERT(ARRAY_SIZE(state_names) == PAGE_STATE_COUNT);
+ BUILD_BUG_ON(ARRAY_SIZE(state_names) != PAGE_STATE_COUNT);
result = ASSERT(state < ARRAY_SIZE(state_names), "Unknown page_state value %d", state);
if (result != UDS_SUCCESS)
@@ -2754,7 +2754,7 @@ static int __must_check initialize_block_map_zone(struct block_map *map,
block_count_t i;
struct block_map_zone *zone = &map->zones[zone_number];
- STATIC_ASSERT_SIZEOF(struct page_descriptor, sizeof(u64));
+ BUILD_BUG_ON(sizeof(struct page_descriptor) != sizeof(u64));
zone->zone_number = zone_number;
zone->thread_id = vdo->thread_config.logical_threads[zone_number];
@@ -2909,9 +2909,9 @@ int vdo_decode_block_map(struct block_map_state_2_0 state,
int result;
zone_count_t zone = 0;
- STATIC_ASSERT(VDO_BLOCK_MAP_ENTRIES_PER_PAGE ==
- ((VDO_BLOCK_SIZE - sizeof(struct block_map_page)) /
- sizeof(struct block_map_entry)));
+ BUILD_BUG_ON(VDO_BLOCK_MAP_ENTRIES_PER_PAGE !=
+ ((VDO_BLOCK_SIZE - sizeof(struct block_map_page)) /
+ sizeof(struct block_map_entry)));
result = ASSERT(cache_size > 0, "block map cache size is specified");
if (result != UDS_SUCCESS)
return result;
@@ -790,7 +790,7 @@ static int initialize_data_vio(struct data_vio *data_vio, struct vdo *vdo)
struct bio *bio;
int result;
- STATIC_ASSERT(VDO_BLOCK_SIZE <= PAGE_SIZE);
+ BUILD_BUG_ON(VDO_BLOCK_SIZE > PAGE_SIZE);
result = uds_allocate_memory(VDO_BLOCK_SIZE, 0, "data_vio data", &data_vio->vio.data);
if (result != VDO_SUCCESS)
return uds_log_error_strerror(result, "data_vio data allocation failure");
@@ -1374,8 +1374,8 @@ void handle_data_vio_error(struct vdo_completion *completion)
*/
const char *get_data_vio_operation_name(struct data_vio *data_vio)
{
- STATIC_ASSERT((MAX_VIO_ASYNC_OPERATION_NUMBER - MIN_VIO_ASYNC_OPERATION_NUMBER) ==
- ARRAY_SIZE(ASYNC_OPERATION_NAMES));
+ BUILD_BUG_ON((MAX_VIO_ASYNC_OPERATION_NUMBER - MIN_VIO_ASYNC_OPERATION_NUMBER) !=
+ ARRAY_SIZE(ASYNC_OPERATION_NAMES));
return ((data_vio->last_async_operation < MAX_VIO_ASYNC_OPERATION_NUMBER) ?
ASYNC_OPERATION_NAMES[data_vio->last_async_operation] :
@@ -379,7 +379,7 @@ struct pbn_lock *vdo_get_duplicate_lock(struct data_vio *data_vio)
static const char *get_hash_lock_state_name(enum hash_lock_state state)
{
/* Catch if a state has been added without updating the name array. */
- STATIC_ASSERT((VDO_HASH_LOCK_BYPASSING + 1) == ARRAY_SIZE(LOCK_STATE_NAMES));
+ BUILD_BUG_ON((VDO_HASH_LOCK_BYPASSING + 1) != ARRAY_SIZE(LOCK_STATE_NAMES));
return (state < ARRAY_SIZE(LOCK_STATE_NAMES)) ? LOCK_STATE_NAMES[state] : "INVALID";
}
@@ -341,7 +341,7 @@ vdo_validate_block_map_page(struct block_map_page *page,
nonce_t nonce,
physical_block_number_t pbn)
{
- STATIC_ASSERT_SIZEOF(struct block_map_page_header, PAGE_HEADER_4_1_SIZE);
+ BUILD_BUG_ON(sizeof(struct block_map_page_header) != PAGE_HEADER_4_1_SIZE);
if (!vdo_are_same_version(BLOCK_MAP_4_1, vdo_unpack_version_number(page->version)) ||
!page->header.initialized ||
@@ -986,7 +986,7 @@ static void encode_layout(u8 *buffer, size_t *offset, const struct layout *layou
size_t initial_offset;
struct header header = VDO_LAYOUT_HEADER_3_0;
- STATIC_ASSERT_SIZEOF(enum partition_id, sizeof(u8));
+ BUILD_BUG_ON(sizeof(enum partition_id) != sizeof(u8));
ASSERT_LOG_ONLY(layout->num_partitions <= U8_MAX,
"layout partition count must fit in a byte");
@@ -253,10 +253,10 @@ size_t vdo_int_map_size(const struct int_map *map)
*/
static struct bucket *dereference_hop(struct bucket *neighborhood, unsigned int hop_offset)
{
+ BUILD_BUG_ON(NULL_HOP_OFFSET != 0);
if (hop_offset == NULL_HOP_OFFSET)
return NULL;
- STATIC_ASSERT(NULL_HOP_OFFSET == 0);
return &neighborhood[hop_offset - 1];
}
@@ -116,7 +116,7 @@ int __must_check uds_reallocate_memory(void *ptr,
__extension__({ \
int _result; \
TYPE1 **_ptr = (PTR); \
- STATIC_ASSERT(__alignof__(TYPE1) >= __alignof__(TYPE2)); \
+ BUILD_BUG_ON(__alignof__(TYPE1) < __alignof__(TYPE2)); \
_result = uds_do_allocation(COUNT, \
sizeof(TYPE2), \
sizeof(TYPE1), \
@@ -379,7 +379,7 @@ static void initialize_compressed_block(struct compressed_block *block, u16 size
* Make sure the block layout isn't accidentally changed by changing the length of the
* block header.
*/
- STATIC_ASSERT_SIZEOF(struct compressed_block_header, COMPRESSED_BLOCK_1_0_SIZE);
+ BUILD_BUG_ON(sizeof(struct compressed_block_header) != COMPRESSED_BLOCK_1_0_SIZE);
block->header.version = vdo_pack_version_number(COMPRESSED_BLOCK_1_0);
block->header.sizes[0] = __cpu_to_le16(size);
@@ -46,20 +46,4 @@ int uds_assertion_failed(const char *expression_string,
...)
__printf(4, 5);
-#define STATIC_ASSERT(expr) \
- do { \
- switch (0) { \
- case 0: \
- ; \
- fallthrough; \
- case expr: \
- ; \
- fallthrough; \
- default: \
- break; \
- } \
- } while (0)
-
-#define STATIC_ASSERT_SIZEOF(type, expected_size) STATIC_ASSERT(sizeof(type) == (expected_size))
-
#endif /* PERMASSERT_H */
@@ -223,10 +223,10 @@ size_t vdo_pointer_map_size(const struct pointer_map *map)
*/
static struct bucket *dereference_hop(struct bucket *neighborhood, unsigned int hop_offset)
{
+ BUILD_BUG_ON(NULL_HOP_OFFSET != 0);
if (hop_offset == NULL_HOP_OFFSET)
return NULL;
- STATIC_ASSERT(NULL_HOP_OFFSET == 0);
return &neighborhood[hop_offset - 1];
}
@@ -669,9 +669,9 @@ static int initialize_recovery_block(struct vdo *vdo,
/*
* Ensure that a block is large enough to store RECOVERY_JOURNAL_ENTRIES_PER_BLOCK entries.
*/
- STATIC_ASSERT(RECOVERY_JOURNAL_ENTRIES_PER_BLOCK
- <= ((VDO_BLOCK_SIZE - sizeof(struct packed_journal_header)) /
- sizeof(struct packed_recovery_journal_entry)));
+ BUILD_BUG_ON(RECOVERY_JOURNAL_ENTRIES_PER_BLOCK >
+ ((VDO_BLOCK_SIZE - sizeof(struct packed_journal_header)) /
+ sizeof(struct packed_recovery_journal_entry)));
/*
* Allocate a full block for the journal block even though not all of the space is used
@@ -4168,7 +4168,7 @@ static int allocate_components(struct slab_depot *depot,
depot->origin = depot->first_block;
/* block size must be a multiple of entry size */
- STATIC_ASSERT((VDO_BLOCK_SIZE % sizeof(struct slab_summary_entry)) == 0);
+ BUILD_BUG_ON((VDO_BLOCK_SIZE % sizeof(struct slab_summary_entry)) != 0);
depot->summary_origin = summary_partition->offset;
depot->hint_shift = vdo_get_slab_summary_hint_shift(depot->slab_size_shift);
@@ -58,8 +58,8 @@ static void do_status_code_registration(void)
{
int result;
- STATIC_ASSERT((VDO_STATUS_CODE_LAST - VDO_STATUS_CODE_BASE) ==
- ARRAY_SIZE(vdo_status_list));
+ BUILD_BUG_ON((VDO_STATUS_CODE_LAST - VDO_STATUS_CODE_BASE) !=
+ ARRAY_SIZE(vdo_status_list));
result = uds_register_error_block("VDO Status",
VDO_STATUS_CODE_BASE,
@@ -132,7 +132,7 @@ int create_multi_block_metadata_vio(struct vdo *vdo,
int result;
/* If struct vio grows past 256 bytes, we'll lose benefits of VDOSTORY-176. */
- STATIC_ASSERT(sizeof(struct vio) <= 256);
+ BUILD_BUG_ON(sizeof(struct vio) > 256);
/*
* Metadata vios should use direct allocation and not use the buffer pool, which is
@@ -1248,7 +1248,7 @@ encode_record_page(const struct volume *volume,
* Sort the record pointers by using just the names in the records, which is less work than
* sorting the entire record values.
*/
- STATIC_ASSERT(offsetof(struct uds_volume_record, name) == 0);
+ BUILD_BUG_ON(offsetof(struct uds_volume_record, name) != 0);
result = uds_radix_sort(volume->radix_sorter,
(const u8 **) record_pointers,
records_per_page,