1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_GENERIC_ERROR_INJECTION_H 3 #define _ASM_GENERIC_ERROR_INJECTION_H 4 5 #if defined(__KERNEL__) && !defined(__ASSEMBLY__) 6 enum { 7 EI_ETYPE_NULL, /* Return NULL if failure */ 8 EI_ETYPE_ERRNO, /* Return -ERRNO if failure */ 9 EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */ 10 EI_ETYPE_TRUE, /* Return true if failure */ 11 }; 12 13 struct error_injection_entry { 14 unsigned long addr; 15 int etype; 16 }; 17 18 struct pt_regs; 19 20 #ifdef CONFIG_FUNCTION_ERROR_INJECTION 21 /* 22 * Whitelist generating macro. Specify functions which can be 23 * error-injectable using this macro. 24 */ 25 #define ALLOW_ERROR_INJECTION(fname, _etype) \ 26 static struct error_injection_entry __used \ 27 __section("_error_injection_whitelist") \ 28 _eil_addr_##fname = { \ 29 .addr = (unsigned long)fname, \ 30 .etype = EI_ETYPE_##_etype, \ 31 } 32 33 void override_function_with_return(struct pt_regs *regs); 34 #else 35 #define ALLOW_ERROR_INJECTION(fname, _etype) 36 37 static inline void override_function_with_return(struct pt_regs *regs) { } 38 #endif 39 #endif 40 41 #endif /* _ASM_GENERIC_ERROR_INJECTION_H */ 42