summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuren Baghdasaryan <surenb@google.com>2022-07-31 09:15:12 -0700
committerSuren Baghdasaryan <surenb@google.com>2022-08-30 20:00:15 +0000
commit2c6a7c53b2e0ade59d2f33028c163ee6b27550e6 (patch)
tree2eb6589e9d32f3be437b591df77e075aac381877
parent3651c41f3c379227616a08dc013e9271b4b76fb3 (diff)
TESTING: drivers/staging: add module for testing code tagging module support
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
-rw-r--r--drivers/staging/Kconfig2
-rw-r--r--drivers/staging/Makefile1
-rw-r--r--drivers/staging/ctagmod/Kconfig9
-rw-r--r--drivers/staging/ctagmod/Makefile2
-rw-r--r--drivers/staging/ctagmod/ctagmod.c50
5 files changed, 64 insertions, 0 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 3bd80f9695ac..6dd05a794746 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -84,4 +84,6 @@ source "drivers/staging/qlge/Kconfig"
source "drivers/staging/vme_user/Kconfig"
+source "drivers/staging/ctagmod/Kconfig"
+
endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 1d9ae39fea14..d0ee659e4ed4 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -31,3 +31,4 @@ obj-$(CONFIG_PI433) += pi433/
obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/
obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
obj-$(CONFIG_QLGE) += qlge/
+obj-$(CONFIG_CTAGMOD) += ctagmod/
diff --git a/drivers/staging/ctagmod/Kconfig b/drivers/staging/ctagmod/Kconfig
new file mode 100644
index 000000000000..f267ffc6afbb
--- /dev/null
+++ b/drivers/staging/ctagmod/Kconfig
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+config CTAGMOD
+ tristate "Code tagging test module"
+ depends on CODE_TAGGING
+ help
+ Code tagging test module.
+
+ To compile this driver as a module, choose M here: the module
+ will be called ctagmod.
diff --git a/drivers/staging/ctagmod/Makefile b/drivers/staging/ctagmod/Makefile
new file mode 100644
index 000000000000..63342b42d82c
--- /dev/null
+++ b/drivers/staging/ctagmod/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_CTAGMOD) += ctagmod.o
diff --git a/drivers/staging/ctagmod/ctagmod.c b/drivers/staging/ctagmod/ctagmod.c
new file mode 100644
index 000000000000..b6e97719a60a
--- /dev/null
+++ b/drivers/staging/ctagmod/ctagmod.c
@@ -0,0 +1,50 @@
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+MODULE_LICENSE("GPL");
+
+static struct page *pg_data;
+static void *slab_data;
+
+static int __init ctagmod_start(void)
+{
+ printk(KERN_INFO "Loading ctagmod module...\n");
+
+#ifdef CONFIG_PAGE_ALLOC_TAGGING
+ pg_data = alloc_pages(GFP_KERNEL, 0);
+ if (unlikely(!pg_data)) {
+ printk(KERN_ERR "Failed to allocate a page!\n");
+ return -ENOMEM;
+ }
+ printk(KERN_INFO "Page is allocated\n");
+#else
+ printk(KERN_INFO "CONFIG_PAGE_ALLOC_TAGGING is undefined\n");
+#endif
+
+#ifdef CONFIG_SLAB_ALLOC_TAGGING
+ slab_data = kmalloc(10, GFP_KERNEL);
+ if (unlikely(!slab_data)) {
+ printk(KERN_ERR "Failed to allocate a slab object!\n");
+ return -ENOMEM;
+ }
+ printk(KERN_INFO "Slab object is allocated\n");
+#else
+ printk(KERN_INFO "CONFIG_SLAB_ALLOC_TAGGING is undefined\n");
+#endif
+ return 0;
+}
+
+static void __exit ctagmod_end(void)
+{
+ if (slab_data)
+ kfree(slab_data);
+ if (pg_data)
+ free_pages((unsigned long)page_address(pg_data), 0);
+ printk(KERN_INFO "Unloading ctagmod\n");
+}
+
+module_init(ctagmod_start);
+module_exit(ctagmod_end);