162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _ASM_GENERIC_ERROR_INJECTION_H
362306a36Sopenharmony_ci#define _ASM_GENERIC_ERROR_INJECTION_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
662306a36Sopenharmony_cienum {
762306a36Sopenharmony_ci	EI_ETYPE_NULL,		/* Return NULL if failure */
862306a36Sopenharmony_ci	EI_ETYPE_ERRNO,		/* Return -ERRNO if failure */
962306a36Sopenharmony_ci	EI_ETYPE_ERRNO_NULL,	/* Return -ERRNO or NULL if failure */
1062306a36Sopenharmony_ci	EI_ETYPE_TRUE,		/* Return true if failure */
1162306a36Sopenharmony_ci};
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct error_injection_entry {
1462306a36Sopenharmony_ci	unsigned long	addr;
1562306a36Sopenharmony_ci	int		etype;
1662306a36Sopenharmony_ci};
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct pt_regs;
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#ifdef CONFIG_FUNCTION_ERROR_INJECTION
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * Whitelist generating macro. Specify functions which can be error-injectable
2362306a36Sopenharmony_ci * using this macro. If you unsure what is required for the error-injectable
2462306a36Sopenharmony_ci * functions, please read Documentation/fault-injection/fault-injection.rst
2562306a36Sopenharmony_ci * 'Error Injectable Functions' section.
2662306a36Sopenharmony_ci */
2762306a36Sopenharmony_ci#define ALLOW_ERROR_INJECTION(fname, _etype)				\
2862306a36Sopenharmony_cistatic struct error_injection_entry __used				\
2962306a36Sopenharmony_ci	__section("_error_injection_whitelist")				\
3062306a36Sopenharmony_ci	_eil_addr_##fname = {						\
3162306a36Sopenharmony_ci		.addr = (unsigned long)fname,				\
3262306a36Sopenharmony_ci		.etype = EI_ETYPE_##_etype,				\
3362306a36Sopenharmony_ci	}
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_civoid override_function_with_return(struct pt_regs *regs);
3662306a36Sopenharmony_ci#else
3762306a36Sopenharmony_ci#define ALLOW_ERROR_INJECTION(fname, _etype)
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_cistatic inline void override_function_with_return(struct pt_regs *regs) { }
4062306a36Sopenharmony_ci#endif
4162306a36Sopenharmony_ci#endif
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#endif /* _ASM_GENERIC_ERROR_INJECTION_H */
44