Jesse Brandeburg | c348c16 | 2020-06-04 16:50:27 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * Copyright (C) 2020 Intel Corporation |
| 4 | */ |
| 5 | |
| 6 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 7 | |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/printk.h> |
| 11 | |
| 12 | /* a tiny module only meant to test set/clear_bit */ |
| 13 | |
| 14 | /* use an enum because thats the most common BITMAP usage */ |
| 15 | enum bitops_fun { |
| 16 | BITOPS_4 = 4, |
| 17 | BITOPS_7 = 7, |
| 18 | BITOPS_11 = 11, |
| 19 | BITOPS_31 = 31, |
| 20 | BITOPS_88 = 88, |
| 21 | BITOPS_LAST = 255, |
| 22 | BITOPS_LENGTH = 256 |
| 23 | }; |
| 24 | |
| 25 | static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH); |
| 26 | |
| 27 | static int __init test_bitops_startup(void) |
| 28 | { |
| 29 | pr_warn("Loaded test module\n"); |
| 30 | set_bit(BITOPS_4, g_bitmap); |
| 31 | set_bit(BITOPS_7, g_bitmap); |
| 32 | set_bit(BITOPS_11, g_bitmap); |
| 33 | set_bit(BITOPS_31, g_bitmap); |
| 34 | set_bit(BITOPS_88, g_bitmap); |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static void __exit test_bitops_unstartup(void) |
| 39 | { |
| 40 | int bit_set; |
| 41 | |
| 42 | clear_bit(BITOPS_4, g_bitmap); |
| 43 | clear_bit(BITOPS_7, g_bitmap); |
| 44 | clear_bit(BITOPS_11, g_bitmap); |
| 45 | clear_bit(BITOPS_31, g_bitmap); |
| 46 | clear_bit(BITOPS_88, g_bitmap); |
| 47 | |
| 48 | bit_set = find_first_bit(g_bitmap, BITOPS_LAST); |
| 49 | if (bit_set != BITOPS_LAST) |
| 50 | pr_err("ERROR: FOUND SET BIT %d\n", bit_set); |
| 51 | |
| 52 | pr_warn("Unloaded test module\n"); |
| 53 | } |
| 54 | |
| 55 | module_init(test_bitops_startup); |
| 56 | module_exit(test_bitops_unstartup); |
| 57 | |
| 58 | MODULE_AUTHOR("Jesse Brandeburg <jesse.brandeburg@intel.com>"); |
| 59 | MODULE_LICENSE("GPL"); |
| 60 | MODULE_DESCRIPTION("Bit testing module"); |