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/suspend.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 PM notifier priority"); 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun static struct notifier_err_inject pm_notifier_err_inject = { 13*4882a593Smuzhiyun .actions = { 14*4882a593Smuzhiyun { NOTIFIER_ERR_INJECT_ACTION(PM_HIBERNATION_PREPARE) }, 15*4882a593Smuzhiyun { NOTIFIER_ERR_INJECT_ACTION(PM_SUSPEND_PREPARE) }, 16*4882a593Smuzhiyun { NOTIFIER_ERR_INJECT_ACTION(PM_RESTORE_PREPARE) }, 17*4882a593Smuzhiyun {} 18*4882a593Smuzhiyun } 19*4882a593Smuzhiyun }; 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun static struct dentry *dir; 22*4882a593Smuzhiyun err_inject_init(void)23*4882a593Smuzhiyunstatic int err_inject_init(void) 24*4882a593Smuzhiyun { 25*4882a593Smuzhiyun int err; 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun dir = notifier_err_inject_init("pm", notifier_err_inject_dir, 28*4882a593Smuzhiyun &pm_notifier_err_inject, priority); 29*4882a593Smuzhiyun if (IS_ERR(dir)) 30*4882a593Smuzhiyun return PTR_ERR(dir); 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun err = register_pm_notifier(&pm_notifier_err_inject.nb); 33*4882a593Smuzhiyun if (err) 34*4882a593Smuzhiyun debugfs_remove_recursive(dir); 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun return err; 37*4882a593Smuzhiyun } 38*4882a593Smuzhiyun err_inject_exit(void)39*4882a593Smuzhiyunstatic void err_inject_exit(void) 40*4882a593Smuzhiyun { 41*4882a593Smuzhiyun unregister_pm_notifier(&pm_notifier_err_inject.nb); 42*4882a593Smuzhiyun debugfs_remove_recursive(dir); 43*4882a593Smuzhiyun } 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun module_init(err_inject_init); 46*4882a593Smuzhiyun module_exit(err_inject_exit); 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun MODULE_DESCRIPTION("PM notifier error injection module"); 49*4882a593Smuzhiyun MODULE_LICENSE("GPL"); 50*4882a593Smuzhiyun MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>"); 51