18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Kernel module for testing static keys.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2015 Akamai Technologies Inc. All Rights Reserved
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Authors:
88c2ecf20Sopenharmony_ci *      Jason Baron       <jbaron@akamai.com>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/jump_label.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* old keys */
158c2ecf20Sopenharmony_cistruct static_key base_old_true_key = STATIC_KEY_INIT_TRUE;
168c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_old_true_key);
178c2ecf20Sopenharmony_cistruct static_key base_inv_old_true_key = STATIC_KEY_INIT_TRUE;
188c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_old_true_key);
198c2ecf20Sopenharmony_cistruct static_key base_old_false_key = STATIC_KEY_INIT_FALSE;
208c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_old_false_key);
218c2ecf20Sopenharmony_cistruct static_key base_inv_old_false_key = STATIC_KEY_INIT_FALSE;
228c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_old_false_key);
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* new keys */
258c2ecf20Sopenharmony_ciDEFINE_STATIC_KEY_TRUE(base_true_key);
268c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_true_key);
278c2ecf20Sopenharmony_ciDEFINE_STATIC_KEY_TRUE(base_inv_true_key);
288c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_true_key);
298c2ecf20Sopenharmony_ciDEFINE_STATIC_KEY_FALSE(base_false_key);
308c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_false_key);
318c2ecf20Sopenharmony_ciDEFINE_STATIC_KEY_FALSE(base_inv_false_key);
328c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_false_key);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic void invert_key(struct static_key *key)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	if (static_key_enabled(key))
378c2ecf20Sopenharmony_ci		static_key_disable(key);
388c2ecf20Sopenharmony_ci	else
398c2ecf20Sopenharmony_ci		static_key_enable(key);
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic int __init test_static_key_base_init(void)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	invert_key(&base_inv_old_true_key);
458c2ecf20Sopenharmony_ci	invert_key(&base_inv_old_false_key);
468c2ecf20Sopenharmony_ci	invert_key(&base_inv_true_key.key);
478c2ecf20Sopenharmony_ci	invert_key(&base_inv_false_key.key);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	return 0;
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic void __exit test_static_key_base_exit(void)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cimodule_init(test_static_key_base_init);
578c2ecf20Sopenharmony_cimodule_exit(test_static_key_base_exit);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jason Baron <jbaron@akamai.com>");
608c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
61