162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Kernel module for testing static keys.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2015 Akamai Technologies Inc. All Rights Reserved
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Authors:
862306a36Sopenharmony_ci *      Jason Baron       <jbaron@akamai.com>
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/module.h>
1262306a36Sopenharmony_ci#include <linux/jump_label.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/* old keys */
1562306a36Sopenharmony_cistruct static_key base_old_true_key = STATIC_KEY_INIT_TRUE;
1662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_old_true_key);
1762306a36Sopenharmony_cistruct static_key base_inv_old_true_key = STATIC_KEY_INIT_TRUE;
1862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_old_true_key);
1962306a36Sopenharmony_cistruct static_key base_old_false_key = STATIC_KEY_INIT_FALSE;
2062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_old_false_key);
2162306a36Sopenharmony_cistruct static_key base_inv_old_false_key = STATIC_KEY_INIT_FALSE;
2262306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_old_false_key);
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/* new keys */
2562306a36Sopenharmony_ciDEFINE_STATIC_KEY_TRUE(base_true_key);
2662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_true_key);
2762306a36Sopenharmony_ciDEFINE_STATIC_KEY_TRUE(base_inv_true_key);
2862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_true_key);
2962306a36Sopenharmony_ciDEFINE_STATIC_KEY_FALSE(base_false_key);
3062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_false_key);
3162306a36Sopenharmony_ciDEFINE_STATIC_KEY_FALSE(base_inv_false_key);
3262306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(base_inv_false_key);
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistatic void invert_key(struct static_key *key)
3562306a36Sopenharmony_ci{
3662306a36Sopenharmony_ci	if (static_key_enabled(key))
3762306a36Sopenharmony_ci		static_key_disable(key);
3862306a36Sopenharmony_ci	else
3962306a36Sopenharmony_ci		static_key_enable(key);
4062306a36Sopenharmony_ci}
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistatic int __init test_static_key_base_init(void)
4362306a36Sopenharmony_ci{
4462306a36Sopenharmony_ci	invert_key(&base_inv_old_true_key);
4562306a36Sopenharmony_ci	invert_key(&base_inv_old_false_key);
4662306a36Sopenharmony_ci	invert_key(&base_inv_true_key.key);
4762306a36Sopenharmony_ci	invert_key(&base_inv_false_key.key);
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	return 0;
5062306a36Sopenharmony_ci}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistatic void __exit test_static_key_base_exit(void)
5362306a36Sopenharmony_ci{
5462306a36Sopenharmony_ci}
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_cimodule_init(test_static_key_base_init);
5762306a36Sopenharmony_cimodule_exit(test_static_key_base_exit);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ciMODULE_AUTHOR("Jason Baron <jbaron@akamai.com>");
6062306a36Sopenharmony_ciMODULE_LICENSE("GPL");
61