Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #include <linux/kernel.h>
0003 #include <linux/module.h>
0004 #include <linux/suspend.h>
0005 
0006 #include "notifier-error-inject.h"
0007 
0008 static int priority;
0009 module_param(priority, int, 0);
0010 MODULE_PARM_DESC(priority, "specify PM notifier priority");
0011 
0012 static struct notifier_err_inject pm_notifier_err_inject = {
0013     .actions = {
0014         { NOTIFIER_ERR_INJECT_ACTION(PM_HIBERNATION_PREPARE) },
0015         { NOTIFIER_ERR_INJECT_ACTION(PM_SUSPEND_PREPARE) },
0016         { NOTIFIER_ERR_INJECT_ACTION(PM_RESTORE_PREPARE) },
0017         {}
0018     }
0019 };
0020 
0021 static struct dentry *dir;
0022 
0023 static int err_inject_init(void)
0024 {
0025     int err;
0026 
0027     dir = notifier_err_inject_init("pm", notifier_err_inject_dir,
0028                     &pm_notifier_err_inject, priority);
0029     if (IS_ERR(dir))
0030         return PTR_ERR(dir);
0031 
0032     err = register_pm_notifier(&pm_notifier_err_inject.nb);
0033     if (err)
0034         debugfs_remove_recursive(dir);
0035 
0036     return err;
0037 }
0038 
0039 static void err_inject_exit(void)
0040 {
0041     unregister_pm_notifier(&pm_notifier_err_inject.nb);
0042     debugfs_remove_recursive(dir);
0043 }
0044 
0045 module_init(err_inject_init);
0046 module_exit(err_inject_exit);
0047 
0048 MODULE_DESCRIPTION("PM notifier error injection module");
0049 MODULE_LICENSE("GPL");
0050 MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");