1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 2014-2015, 2018, 2020-2021 ARM Limited. All rights reserved. 5 * 6 * This program is free software and is provided to you under the terms of the 7 * GNU General Public License version 2 as published by the Free Software 8 * Foundation, and any use by you of this program is subject to the terms 9 * of such GNU license. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, you can access it online at 18 * http://www.gnu.org/licenses/gpl-2.0.html. 19 * 20 */ 21 22 /** 23 * Kernel-wide include for common macros and types. 24 */ 25 26 #ifndef _MALISW_H_ 27 #define _MALISW_H_ 28 29 #include <linux/version.h> 30 31 /** 32 * MIN - Return the lesser of two values. 33 * @x: value1 34 * @y: value2 35 * 36 * As a macro it may evaluate its arguments more than once. 37 * Refer to MAX macro for more details 38 */ 39 #define MIN(x, y) ((x) < (y) ? (x) : (y)) 40 41 /** 42 * MAX - Return the greater of two values. 43 * @x: value1 44 * @y: value2 45 * 46 * As a macro it may evaluate its arguments more than once. 47 * If called on the same two arguments as MIN it is guaranteed to return 48 * the one that MIN didn't return. This is significant for types where not 49 * all values are comparable e.g. NaNs in floating-point types. But if you want 50 * to retrieve the min and max of two values, consider using a conditional swap 51 * instead. 52 */ 53 #define MAX(x, y) ((x) < (y) ? (y) : (x)) 54 55 /** 56 * Function-like macro for suppressing unused variable warnings. 57 * @x: unused variable 58 * 59 * Where possible such variables should be removed; this macro is present for 60 * cases where we much support API backwards compatibility. 61 */ 62 #define CSTD_UNUSED(x) ((void)(x)) 63 64 /** 65 * Function-like macro for use where "no behavior" is desired. 66 * @...: no-op 67 * 68 * This is useful when compile time macros turn a function-like macro in to a 69 * no-op, but where having no statement is otherwise invalid. 70 */ 71 #define CSTD_NOP(...) ((void)#__VA_ARGS__) 72 73 /** 74 * Function-like macro for stringizing a single level macro. 75 * @x: macro's value 76 * 77 * @code 78 * #define MY_MACRO 32 79 * CSTD_STR1( MY_MACRO ) 80 * > "MY_MACRO" 81 * @endcode 82 */ 83 #define CSTD_STR1(x) #x 84 85 /** 86 * Function-like macro for stringizing a macro's value. 87 * @x: macro's value 88 * 89 * This should not be used if the macro is defined in a way which may have no 90 * value; use the alternative @c CSTD_STR2N macro should be used instead. 91 * @code 92 * #define MY_MACRO 32 93 * CSTD_STR2( MY_MACRO ) 94 * > "32" 95 * @endcode 96 */ 97 #define CSTD_STR2(x) CSTD_STR1(x) 98 99 /* LINUX_VERSION_CODE < 5.4 */ 100 #if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) 101 #if defined(GCC_VERSION) && GCC_VERSION >= 70000 102 #ifndef __fallthrough 103 #define __fallthrough __attribute__((fallthrough)) 104 #endif /* __fallthrough */ 105 #define fallthrough __fallthrough 106 #else 107 #define fallthrough CSTD_NOP(...) /* fallthrough */ 108 #endif /* GCC_VERSION >= 70000 */ 109 #endif /* KERNEL_VERSION(5, 4, 0) */ 110 111 #endif /* _MALISW_H_ */ 112