pm-notifier-error-inject.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/suspend.h>
  4. #include "notifier-error-inject.h"
  5. static int priority;
  6. module_param(priority, int, 0);
  7. MODULE_PARM_DESC(priority, "specify PM notifier priority");
  8. static struct notifier_err_inject pm_notifier_err_inject = {
  9. .actions = {
  10. { NOTIFIER_ERR_INJECT_ACTION(PM_HIBERNATION_PREPARE) },
  11. { NOTIFIER_ERR_INJECT_ACTION(PM_SUSPEND_PREPARE) },
  12. { NOTIFIER_ERR_INJECT_ACTION(PM_RESTORE_PREPARE) },
  13. {}
  14. }
  15. };
  16. static struct dentry *dir;
  17. static int err_inject_init(void)
  18. {
  19. int err;
  20. dir = notifier_err_inject_init("pm", notifier_err_inject_dir,
  21. &pm_notifier_err_inject, priority);
  22. if (IS_ERR(dir))
  23. return PTR_ERR(dir);
  24. err = register_pm_notifier(&pm_notifier_err_inject.nb);
  25. if (err)
  26. debugfs_remove_recursive(dir);
  27. return err;
  28. }
  29. static void err_inject_exit(void)
  30. {
  31. unregister_pm_notifier(&pm_notifier_err_inject.nb);
  32. debugfs_remove_recursive(dir);
  33. }
  34. module_init(err_inject_init);
  35. module_exit(err_inject_exit);
  36. MODULE_DESCRIPTION("PM notifier error injection module");
  37. MODULE_LICENSE("GPL");
  38. MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");