Masami Hiramatsu | 540adea | 2018-01-13 02:55:03 +0900 | [diff] [blame] | 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__) |
Masami Hiramatsu | 663faf9 | 2018-01-13 02:55:33 +0900 | [diff] [blame] | 6 | enum { |
| 7 | EI_ETYPE_NONE, /* Dummy value for undefined case */ |
| 8 | EI_ETYPE_NULL, /* Return NULL if failure */ |
| 9 | EI_ETYPE_ERRNO, /* Return -ERRNO if failure */ |
| 10 | EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */ |
Benjamin Poirier | af3b854 | 2018-12-28 00:39:23 -0800 | [diff] [blame] | 11 | EI_ETYPE_TRUE, /* Return true if failure */ |
Masami Hiramatsu | 663faf9 | 2018-01-13 02:55:33 +0900 | [diff] [blame] | 12 | }; |
| 13 | |
| 14 | struct error_injection_entry { |
| 15 | unsigned long addr; |
| 16 | int etype; |
| 17 | }; |
| 18 | |
Leo Yan | 45880f7 | 2019-08-06 18:00:13 +0800 | [diff] [blame] | 19 | struct pt_regs; |
| 20 | |
Masami Hiramatsu | 540adea | 2018-01-13 02:55:03 +0900 | [diff] [blame] | 21 | #ifdef CONFIG_FUNCTION_ERROR_INJECTION |
| 22 | /* |
| 23 | * Whitelist ganerating macro. Specify functions which can be |
| 24 | * error-injectable using this macro. |
| 25 | */ |
Masami Hiramatsu | 663faf9 | 2018-01-13 02:55:33 +0900 | [diff] [blame] | 26 | #define ALLOW_ERROR_INJECTION(fname, _etype) \ |
| 27 | static struct error_injection_entry __used \ |
Joe Perches | 33def84 | 2020-10-21 19:36:07 -0700 | [diff] [blame] | 28 | __section("_error_injection_whitelist") \ |
Masami Hiramatsu | 663faf9 | 2018-01-13 02:55:33 +0900 | [diff] [blame] | 29 | _eil_addr_##fname = { \ |
| 30 | .addr = (unsigned long)fname, \ |
| 31 | .etype = EI_ETYPE_##_etype, \ |
| 32 | }; |
Leo Yan | 45880f7 | 2019-08-06 18:00:13 +0800 | [diff] [blame] | 33 | |
| 34 | void override_function_with_return(struct pt_regs *regs); |
Masami Hiramatsu | 540adea | 2018-01-13 02:55:03 +0900 | [diff] [blame] | 35 | #else |
Masami Hiramatsu | 663faf9 | 2018-01-13 02:55:33 +0900 | [diff] [blame] | 36 | #define ALLOW_ERROR_INJECTION(fname, _etype) |
Leo Yan | 45880f7 | 2019-08-06 18:00:13 +0800 | [diff] [blame] | 37 | |
| 38 | static inline void override_function_with_return(struct pt_regs *regs) { } |
Masami Hiramatsu | 540adea | 2018-01-13 02:55:03 +0900 | [diff] [blame] | 39 | #endif |
| 40 | #endif |
| 41 | |
| 42 | #endif /* _ASM_GENERIC_ERROR_INJECTION_H */ |