1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only 2*4882a593Smuzhiyun #include <linux/kernel.h> 3*4882a593Smuzhiyun #include <linux/module.h> 4*4882a593Smuzhiyun #include <linux/memory.h> 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun #include "notifier-error-inject.h" 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun static int priority; 9*4882a593Smuzhiyun module_param(priority, int, 0); 10*4882a593Smuzhiyun MODULE_PARM_DESC(priority, "specify memory notifier priority"); 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun static struct notifier_err_inject memory_notifier_err_inject = { 13*4882a593Smuzhiyun .actions = { 14*4882a593Smuzhiyun { NOTIFIER_ERR_INJECT_ACTION(MEM_GOING_ONLINE) }, 15*4882a593Smuzhiyun { NOTIFIER_ERR_INJECT_ACTION(MEM_GOING_OFFLINE) }, 16*4882a593Smuzhiyun {} 17*4882a593Smuzhiyun } 18*4882a593Smuzhiyun }; 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun static struct dentry *dir; 21*4882a593Smuzhiyun err_inject_init(void)22*4882a593Smuzhiyunstatic int err_inject_init(void) 23*4882a593Smuzhiyun { 24*4882a593Smuzhiyun int err; 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun dir = notifier_err_inject_init("memory", notifier_err_inject_dir, 27*4882a593Smuzhiyun &memory_notifier_err_inject, priority); 28*4882a593Smuzhiyun if (IS_ERR(dir)) 29*4882a593Smuzhiyun return PTR_ERR(dir); 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun err = register_memory_notifier(&memory_notifier_err_inject.nb); 32*4882a593Smuzhiyun if (err) 33*4882a593Smuzhiyun debugfs_remove_recursive(dir); 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun return err; 36*4882a593Smuzhiyun } 37*4882a593Smuzhiyun err_inject_exit(void)38*4882a593Smuzhiyunstatic void err_inject_exit(void) 39*4882a593Smuzhiyun { 40*4882a593Smuzhiyun unregister_memory_notifier(&memory_notifier_err_inject.nb); 41*4882a593Smuzhiyun debugfs_remove_recursive(dir); 42*4882a593Smuzhiyun } 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun module_init(err_inject_init); 45*4882a593Smuzhiyun module_exit(err_inject_exit); 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun MODULE_DESCRIPTION("memory notifier error injection module"); 48*4882a593Smuzhiyun MODULE_LICENSE("GPL"); 49*4882a593Smuzhiyun MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>"); 50