VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   35 Branches   59 Tags
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  1) // SPDX-License-Identifier: GPL-2.0-only
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  2) #include <linux/fault-inject.h>
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  3) #include <linux/fault-inject-usercopy.h>
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  4) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  5) static struct {
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  6) 	struct fault_attr attr;
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  7) } fail_usercopy = {
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  8) 	.attr = FAULT_ATTR_INITIALIZER,
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700  9) };
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 10) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 11) static int __init setup_fail_usercopy(char *str)
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 12) {
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 13) 	return setup_fault_attr(&fail_usercopy.attr, str);
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 14) }
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 15) __setup("fail_usercopy=", setup_fail_usercopy);
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 16) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 17) #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 18) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 19) static int __init fail_usercopy_debugfs(void)
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 20) {
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 21) 	struct dentry *dir;
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 22) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 23) 	dir = fault_create_debugfs_attr("fail_usercopy", NULL,
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 24) 					&fail_usercopy.attr);
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 25) 	if (IS_ERR(dir))
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 26) 		return PTR_ERR(dir);
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 27) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 28) 	return 0;
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 29) }
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 30) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 31) late_initcall(fail_usercopy_debugfs);
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 32) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 33) #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 34) 
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 35) bool should_fail_usercopy(void)
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 36) {
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 37) 	return should_fail(&fail_usercopy.attr, 1);
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 38) }
2c739ced5886c (Albert van der Linde 2020-10-15 20:13:46 -0700 39) EXPORT_SYMBOL_GPL(should_fail_usercopy);