Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include "notifier-error-inject.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) static int priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) module_param(priority, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) MODULE_PARM_DESC(priority, "specify netdevice notifier priority");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static struct notifier_err_inject netdev_notifier_err_inject = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 	.actions = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_REGISTER) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGEMTU) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGENAME) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRE_UP) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRE_TYPE_CHANGE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_POST_INIT) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRECHANGEMTU) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRECHANGEUPPER) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 		{ NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGEUPPER) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 		{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static struct dentry *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int netdev_err_inject_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	dir = notifier_err_inject_init("netdev", notifier_err_inject_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 				       &netdev_notifier_err_inject, priority);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	if (IS_ERR(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		return PTR_ERR(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	err = register_netdevice_notifier(&netdev_notifier_err_inject.nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		debugfs_remove_recursive(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static void netdev_err_inject_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	unregister_netdevice_notifier(&netdev_notifier_err_inject.nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	debugfs_remove_recursive(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) module_init(netdev_err_inject_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) module_exit(netdev_err_inject_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) MODULE_DESCRIPTION("Netdevice notifier error injection module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) MODULE_AUTHOR("Nikolay Aleksandrov <razor@blackwall.org>");