1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
From 504db8a2bae95d7bafb9b68074fdc46c49f08c9f Mon Sep 17 00:00:00 2001
From: Manuel Traut <manut@linutronix.de>
Date: Fri, 4 Jan 2019 09:32:18 +0100
Subject: [PATCH] klist example
this can be used to show the usage of klists
Signed-off-by: Manuel Traut <manut@linutronix.de>
---
drivers/staging/Kconfig | 2 +
drivers/staging/Makefile | 1 +
drivers/staging/klist/Kconfig | 5 +++
drivers/staging/klist/Makefile | 1 +
drivers/staging/klist/klist.c | 68 +++++++++++++++++++++++++++++++++
5 files changed, 77 insertions(+)
create mode 100644 drivers/staging/klist/Kconfig
create mode 100644 drivers/staging/klist/Makefile
create mode 100644 drivers/staging/klist/klist.c
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index bfa2bf720a03..98541d7a41be 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -24,6 +24,8 @@ menuconfig STAGING
if STAGING
+source "drivers/staging/klist/Kconfig"
+
source "drivers/staging/wlan-ng/Kconfig"
source "drivers/staging/comedi/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 25b3a8eafaa1..7a6d82750008 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -2,6 +2,7 @@
# Makefile for staging directory
obj-y += media/
+obj-$(CONFIG_KLISTEXAMPLE) += klist/
obj-$(CONFIG_PRISM2_USB) += wlan-ng/
obj-$(CONFIG_COMEDI) += comedi/
obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/
diff --git a/drivers/staging/klist/Kconfig b/drivers/staging/klist/Kconfig
new file mode 100644
index 000000000000..18f517e56cb9
--- /dev/null
+++ b/drivers/staging/klist/Kconfig
@@ -0,0 +1,4 @@
+config KLISTEXAMPLE
+ tristate "module to teach klist usage"
+ ---help---
+ This is only useful for learning the usage of klist.
diff --git a/drivers/staging/klist/Makefile b/drivers/staging/klist/Makefile
new file mode 100644
index 000000000000..2939c11d72ff
--- /dev/null
+++ b/drivers/staging/klist/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_KLISTEXAMPLE) += klist.o
diff --git a/drivers/staging/klist/klist.c b/drivers/staging/klist/klist.c
new file mode 100644
index 000000000000..365acaa3263a
--- /dev/null
+++ b/drivers/staging/klist/klist.c
@@ -0,0 +1,68 @@
+/*
+ * Example driver for using klist
+ * Copyright (C) 2019, Manuel Traut <manut@linutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+
+#define DRV_NAME "klist"
+
+struct mynode {
+ struct list_head node;
+ unsigned long val;
+};
+
+static struct list_head mylist;
+static char mystring[] = "1 2 3 4 5\n";
+
+static void klist_free_list(void) {
+ struct mynode *n, *tmp;
+ list_for_each_entry_safe(n, tmp, &mylist, node)
+ kfree(n);
+}
+
+static void klist_init_list(void) {
+ unsigned long val;
+ struct mynode *n;
+ char *tok;
+ char *b = kstrdup(mystring, GFP_KERNEL);
+
+ INIT_LIST_HEAD(&mylist);
+
+ while ((tok = strsep(&b, " ")) && *tok) {
+ printk(KERN_INFO "adding %s to list\n", tok);
+ if (kstrtoul(tok, 0, &val)) {
+ printk(KERN_ERR "failed to convert %s to int\n", tok);
+ goto exit_init;
+ }
+ n = kzalloc(sizeof(*n), GFP_KERNEL);
+ n->val = val;
+ list_add_tail(&n->node, &mylist);
+ }
+exit_init:
+ kfree(b);
+}
+
+static int __init klist_init(void) {
+ printk(KERN_INFO "%s\n", __func__);
+ klist_init_list();
+ return 0;
+}
+
+static void __exit klist_exit(void) {
+ printk(KERN_INFO "%s\n", __func__);
+ klist_free_list();
+}
+
+module_init(klist_init);
+module_exit(klist_exit);
+MODULE_AUTHOR("Manuel Traut");
+MODULE_LICENSE("GPL");
--
2.19.2
|