1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright 2023 Red Hat
9 #include <linux/compiler.h>
13 /* Utilities for asserting that certain conditions are met */
15 #define STRINGIFY(X) #X
18 * A hack to apply the "warn if unused" attribute to an integral expression.
20 * Since GCC doesn't propagate the warn_unused_result attribute to conditional expressions
21 * incorporating calls to functions with that attribute, this function can be used to wrap such an
22 * expression. With optimization enabled, this function contributes no additional instructions, but
23 * the warn_unused_result attribute still applies to the code calling it.
25 static inline int __must_check
vdo_must_use(int value
)
30 /* Assert that an expression is true and return an error if it is not. */
31 #define VDO_ASSERT(expr, ...) vdo_must_use(__VDO_ASSERT(expr, __VA_ARGS__))
33 /* Log a message if the expression is not true. */
34 #define VDO_ASSERT_LOG_ONLY(expr, ...) __VDO_ASSERT(expr, __VA_ARGS__)
36 #define __VDO_ASSERT(expr, ...) \
37 (likely(expr) ? VDO_SUCCESS \
38 : vdo_assertion_failed(STRINGIFY(expr), __FILE__, __LINE__, __VA_ARGS__))
40 /* Log an assertion failure message. */
41 int vdo_assertion_failed(const char *expression_string
, const char *file_name
,
42 int line_number
, const char *format
, ...)
45 #endif /* PERMASSERT_H */