test_static_key_base.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Kernel module for testing static keys.
  3. *
  4. * Copyright 2015 Akamai Technologies Inc. All Rights Reserved
  5. *
  6. * Authors:
  7. * Jason Baron <jbaron@akamai.com>
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/jump_label.h>
  20. /* old keys */
  21. struct static_key base_old_true_key = STATIC_KEY_INIT_TRUE;
  22. EXPORT_SYMBOL_GPL(base_old_true_key);
  23. struct static_key base_inv_old_true_key = STATIC_KEY_INIT_TRUE;
  24. EXPORT_SYMBOL_GPL(base_inv_old_true_key);
  25. struct static_key base_old_false_key = STATIC_KEY_INIT_FALSE;
  26. EXPORT_SYMBOL_GPL(base_old_false_key);
  27. struct static_key base_inv_old_false_key = STATIC_KEY_INIT_FALSE;
  28. EXPORT_SYMBOL_GPL(base_inv_old_false_key);
  29. /* new keys */
  30. DEFINE_STATIC_KEY_TRUE(base_true_key);
  31. EXPORT_SYMBOL_GPL(base_true_key);
  32. DEFINE_STATIC_KEY_TRUE(base_inv_true_key);
  33. EXPORT_SYMBOL_GPL(base_inv_true_key);
  34. DEFINE_STATIC_KEY_FALSE(base_false_key);
  35. EXPORT_SYMBOL_GPL(base_false_key);
  36. DEFINE_STATIC_KEY_FALSE(base_inv_false_key);
  37. EXPORT_SYMBOL_GPL(base_inv_false_key);
  38. static void invert_key(struct static_key *key)
  39. {
  40. if (static_key_enabled(key))
  41. static_key_disable(key);
  42. else
  43. static_key_enable(key);
  44. }
  45. static int __init test_static_key_base_init(void)
  46. {
  47. invert_key(&base_inv_old_true_key);
  48. invert_key(&base_inv_old_false_key);
  49. invert_key(&base_inv_true_key.key);
  50. invert_key(&base_inv_false_key.key);
  51. return 0;
  52. }
  53. static void __exit test_static_key_base_exit(void)
  54. {
  55. }
  56. module_init(test_static_key_base_init);
  57. module_exit(test_static_key_base_exit);
  58. MODULE_AUTHOR("Jason Baron <jbaron@akamai.com>");
  59. MODULE_LICENSE("GPL");