Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / md / dm-vdo / permassert.h
blobc34f2ba650e1e67993b89644413c93932736a656
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright 2023 Red Hat
4 */
6 #ifndef PERMASSERT_H
7 #define PERMASSERT_H
9 #include <linux/compiler.h>
11 #include "errors.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)
27 return 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, ...)
43 __printf(4, 5);
45 #endif /* PERMASSERT_H */