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