diff options
| author | Manuel Traut <manut@linutronix.de> | 2019-01-11 08:23:02 +0100 |
|---|---|---|
| committer | John Ogness <john.ogness@linutronix.de> | 2019-01-28 19:58:39 +0106 |
| commit | 2268f2b2371e02762bf511cf1db1e3609b58f849 (patch) | |
| tree | 1f62bc6fc20bd6a1fd7e0bc1c7189513b29cfa10 /schulung_tools/drivers | |
| parent | b2647cbe2fbc104c8240203a11889aabb5928c23 (diff) | |
schulung_tools: add klist kernel module
this module can be used to show the usage of klist
Signed-off-by: Manuel Traut <manut@linutronix.de>
Diffstat (limited to 'schulung_tools/drivers')
| -rw-r--r-- | schulung_tools/drivers/modules/klist/0001-klist-example.patch | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/schulung_tools/drivers/modules/klist/0001-klist-example.patch b/schulung_tools/drivers/modules/klist/0001-klist-example.patch new file mode 100644 index 0000000..b52216a --- /dev/null +++ b/schulung_tools/drivers/modules/klist/0001-klist-example.patch @@ -0,0 +1,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 + |
