2 * Copyright (C) 2010 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
25 #include <linux/kref.h>
27 MODULE_LICENSE("GPL");
28 MODULE_AUTHOR("Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>");
29 MODULE_DESCRIPTION("Hello, world");
37 static struct hello *global_hello;
39 static char default_greeting[] = "Hello, world!\n";
41 static void hello_release(struct kref *ref)
43 struct hello *hello = container_of(ref, struct hello, ref);
44 printk(KERN_DEBUG "releasing hello\n");
48 static int hello_init(void)
50 static struct hello *hello;
51 hello = kmalloc(sizeof(*hello) + sizeof(default_greeting), GFP_KERNEL);
54 kref_init(&hello->ref);
55 kref_get(&hello->ref);
57 memcpy(hello->greeting, default_greeting, sizeof(default_greeting));
58 printk("%s\n", hello->greeting);
59 printk("%p %p %p\n", hello, hello->greeting,
60 container_of(&hello->greeting, struct hello, greeting));
61 printk("size %d\n", ARRAY_SIZE(default_greeting));
62 kref_put(&hello->ref, hello_release);
66 static __exit void hello_exit(void)
68 kref_put(&global_hello->ref, hello_release);
71 module_init(hello_init);
72 module_exit(hello_exit);