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