18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci#include <linux/kernel.h>
38c2ecf20Sopenharmony_ci#include <linux/module.h>
48c2ecf20Sopenharmony_ci#include <linux/suspend.h>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include "notifier-error-inject.h"
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cistatic int priority;
98c2ecf20Sopenharmony_cimodule_param(priority, int, 0);
108c2ecf20Sopenharmony_ciMODULE_PARM_DESC(priority, "specify PM notifier priority");
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistatic struct notifier_err_inject pm_notifier_err_inject = {
138c2ecf20Sopenharmony_ci	.actions = {
148c2ecf20Sopenharmony_ci		{ NOTIFIER_ERR_INJECT_ACTION(PM_HIBERNATION_PREPARE) },
158c2ecf20Sopenharmony_ci		{ NOTIFIER_ERR_INJECT_ACTION(PM_SUSPEND_PREPARE) },
168c2ecf20Sopenharmony_ci		{ NOTIFIER_ERR_INJECT_ACTION(PM_RESTORE_PREPARE) },
178c2ecf20Sopenharmony_ci		{}
188c2ecf20Sopenharmony_ci	}
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic struct dentry *dir;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic int err_inject_init(void)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	int err;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	dir = notifier_err_inject_init("pm", notifier_err_inject_dir,
288c2ecf20Sopenharmony_ci					&pm_notifier_err_inject, priority);
298c2ecf20Sopenharmony_ci	if (IS_ERR(dir))
308c2ecf20Sopenharmony_ci		return PTR_ERR(dir);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	err = register_pm_notifier(&pm_notifier_err_inject.nb);
338c2ecf20Sopenharmony_ci	if (err)
348c2ecf20Sopenharmony_ci		debugfs_remove_recursive(dir);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	return err;
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic void err_inject_exit(void)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	unregister_pm_notifier(&pm_notifier_err_inject.nb);
428c2ecf20Sopenharmony_ci	debugfs_remove_recursive(dir);
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cimodule_init(err_inject_init);
468c2ecf20Sopenharmony_cimodule_exit(err_inject_exit);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PM notifier error injection module");
498c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
508c2ecf20Sopenharmony_ciMODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
51