blob: 7ddd9dc10ce9666f5c07f687c0c075cc81860751 [file] [log] [blame]
Masami Hiramatsu540adea2018-01-13 02:55:03 +09001/* 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 Hiramatsu663faf92018-01-13 02:55:33 +09006enum {
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 Poirieraf3b8542018-12-28 00:39:23 -080011 EI_ETYPE_TRUE, /* Return true if failure */
Masami Hiramatsu663faf92018-01-13 02:55:33 +090012};
13
14struct error_injection_entry {
15 unsigned long addr;
16 int etype;
17};
18
Leo Yan45880f72019-08-06 18:00:13 +080019struct pt_regs;
20
Masami Hiramatsu540adea2018-01-13 02:55:03 +090021#ifdef CONFIG_FUNCTION_ERROR_INJECTION
22/*
23 * Whitelist ganerating macro. Specify functions which can be
24 * error-injectable using this macro.
25 */
Masami Hiramatsu663faf92018-01-13 02:55:33 +090026#define ALLOW_ERROR_INJECTION(fname, _etype) \
27static struct error_injection_entry __used \
Joe Perches33def842020-10-21 19:36:07 -070028 __section("_error_injection_whitelist") \
Masami Hiramatsu663faf92018-01-13 02:55:33 +090029 _eil_addr_##fname = { \
30 .addr = (unsigned long)fname, \
31 .etype = EI_ETYPE_##_etype, \
32 };
Leo Yan45880f72019-08-06 18:00:13 +080033
34void override_function_with_return(struct pt_regs *regs);
Masami Hiramatsu540adea2018-01-13 02:55:03 +090035#else
Masami Hiramatsu663faf92018-01-13 02:55:33 +090036#define ALLOW_ERROR_INJECTION(fname, _etype)
Leo Yan45880f72019-08-06 18:00:13 +080037
38static inline void override_function_with_return(struct pt_regs *regs) { }
Masami Hiramatsu540adea2018-01-13 02:55:03 +090039#endif
40#endif
41
42#endif /* _ASM_GENERIC_ERROR_INJECTION_H */