/* Define GPIOs for BUTTONS
Change the numbers for the GPIO on your board. */
-static struct gpio buttons[] = {{17, GPIOF_IN, "LED 1 ON BUTTON"},
- {18, GPIOF_IN, "LED 1 OFF BUTTON"}};
+static struct gpio buttons[] = {
+ {17, GPIOF_IN, "LED 1 ON BUTTON"},
+ {18, GPIOF_IN, "LED 1 OFF BUTTON"},
+};
/* Tasklet containing some non-trivial amount of processing */
static void bottomhalf_tasklet_fn(unsigned long data)
return IRQ_HANDLED;
}
-int init_module()
+static int __init bottomhalf_init(void)
{
int ret = 0;
return ret;
}
-void cleanup_module()
+static void __exit bottomhalf_exit(void)
{
int i;
gpio_free_array(buttons, ARRAY_SIZE(buttons));
}
+module_init(bottomhalf_init);
+module_exit(bottomhalf_exit);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Interrupt with top and bottom half");
.release = device_release,
};
-/* This function is called when the module is loaded. */
-int init_module(void)
+static int __init chardev_init(void)
{
major = register_chrdev(0, DEVICE_NAME, &chardev_fops);
return SUCCESS;
}
-/* This function is called when the module is unloaded. */
-void cleanup_module(void)
+static void __exit chardev_exit(void)
{
device_destroy(cls, MKDEV(major, 0));
class_destroy(cls);
return -EINVAL;
}
+module_init(chardev_init);
+module_exit(chardev_exit);
+
MODULE_LICENSE("GPL");
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/irq.h>
-#include <linux/kernel.h> /* We're doing kernel work */
+#include <linux/kernel.h> /* We are doing kernel work */
#include <linux/module.h> /* Specifically, a module */
#include <linux/poll.h>
.release = device_release, /* a.k.a. close */
};
-/*
- * Initialize the module - Register the character device
- */
-int init_module()
+/* Initialize the module - Register the character device */
+static int __init chardev2_init(void)
{
- int ret_val;
- /*
- * Register the character device (atleast try)
- */
- ret_val = register_chrdev(MAJOR_NUM, DEVICE_NAME, &Fops);
+ /* Register the character device (atleast try) */
+ int ret_val = register_chrdev(MAJOR_NUM, DEVICE_NAME, &Fops);
- /*
- * Negative values signify an error
- */
+ /* Negative values signify an error */
if (ret_val < 0) {
pr_alert("%s failed with %d\n",
"Sorry, registering the character device ", ret_val);
return 0;
}
-/*
- * Cleanup - unregister the appropriate file from /proc
- */
-void cleanup_module()
+/* Cleanup - unregister the appropriate file from /proc */
+static void __exit chardev2_exit(void)
{
device_destroy(cls, MKDEV(Major, 0));
class_destroy(cls);
- /*
- * Unregister the device
- */
+ /* Unregister the device */
unregister_chrdev(Major, DEVICE_NAME);
}
+module_init(chardev2_init);
+module_exit(chardev2_exit);
+
MODULE_LICENSE("GPL");
platform_driver_unregister(&devicemodel_driver);
}
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Linux Device Model example");
-
module_init(devicemodel_init);
module_exit(devicemodel_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Linux Device Model example");
{
pr_info("Hello world 1.\n");
- /*
- * A non 0 return means init_module failed; module can't be loaded.
- */
+ /* A non 0 return means init_module failed; module can't be loaded. */
return 0;
}
return IRQ_HANDLED;
}
-int init_module()
+static int __init intrpt_init(void)
{
int ret = 0;
return ret;
}
-void cleanup_module()
+static void __exit intrpt_exit(void)
{
int i;
gpio_free_array(buttons, ARRAY_SIZE(buttons));
}
+module_init(intrpt_init);
+module_exit(intrpt_exit);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Handle some GPIO interrupts");
};
#endif
-int init_module()
+static int __init procfs1_init(void)
{
Our_Proc_File = proc_create(procfs_name, 0644, NULL, &proc_file_fops);
if (NULL == Our_Proc_File) {
return 0;
}
-void cleanup_module()
+static void __exit procfs1_exit(void)
{
proc_remove(Our_Proc_File);
pr_info("/proc/%s removed\n", procfs_name);
}
+module_init(procfs1_init);
+module_exit(procfs1_exit);
+
MODULE_LICENSE("GPL");
};
#endif
-/**
- *This function is called when the module is loaded
- *
- */
-int init_module()
+static int __init procfs2_init(void)
{
Our_Proc_File = proc_create(PROCFS_NAME, 0644, NULL, &proc_file_fops);
if (NULL == Our_Proc_File) {
return 0;
}
-/**
- *This function is called when the module is unloaded
- *
- */
-void cleanup_module()
+static void __exit procfs2_exit(void)
{
proc_remove(Our_Proc_File);
pr_info("/proc/%s removed\n", PROCFS_NAME);
}
+module_init(procfs2_init);
+module_exit(procfs2_exit);
+
MODULE_LICENSE("GPL");
};
#endif
-int init_module()
+static int __init procfs3_init(void)
{
Our_Proc_File = proc_create(PROCFS_ENTRY_FILENAME, 0644, NULL,
&File_Ops_4_Our_Proc_File);
pr_debug("/proc/%s created\n", PROCFS_ENTRY_FILENAME);
return 0;
}
-void cleanup_module()
+
+static void __exit procfs3_exit(void)
{
remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);
pr_debug("/proc/%s removed\n", PROCFS_ENTRY_FILENAME);
}
+module_init(procfs3_init);
+module_exit(procfs3_exit);
+
MODULE_LICENSE("GPL");
#define PROC_NAME "iter"
-MODULE_LICENSE("GPL");
-
/* This function is called at the beginning of a sequence.
* ie, when:
* - the /proc file is read (first time)
};
#endif
-/* This function is called when the module is loaded. */
-int init_module(void)
+static int __init procfs4_init(void)
{
struct proc_dir_entry *entry;
return 0;
}
-/* This function is called when the module is unloaded. */
-void cleanup_module(void)
+static void __exit procfs4_exit(void)
{
remove_proc_entry(PROC_NAME, NULL);
pr_debug("/proc/%s removed\n", PROC_NAME);
}
+
+module_init(procfs4_init);
+module_exit(procfs4_exit);
+
+MODULE_LICENSE("GPL");
pr_info("work handler function.\n");
}
-int init_module()
+static int __init sched_init(void)
{
queue = alloc_workqueue("HELLOWORLD", WQ_UNBOUND, 1);
INIT_WORK(&work, work_handler);
return 0;
}
-void cleanup_module()
+static void __exit sched_exit(void)
{
destroy_workqueue(queue);
}
+module_init(sched_init);
+module_exit(sched_exit);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Workqueue example");
};
#endif
-/*
- * Module initialization and cleanup
- */
-
-/*
- * Initialize the module - register the proc file
- */
-
-int init_module()
+/* Initialize the module - register the proc file */
+static int __init sleep_init(void)
{
Our_Proc_File =
proc_create(PROC_ENTRY_FILENAME, 0644, NULL, &File_Ops_4_Our_Proc_File);
return 0;
}
-/*
- * Cleanup - unregister our file from /proc. This could get dangerous if
+/* Cleanup - unregister our file from /proc. This could get dangerous if
* there are still processes waiting in WaitQ, because they are inside our
* open function, which will get unloaded. I'll explain how to avoid removal
* of a kernel module in such a case in chapter 10.
*/
-void cleanup_module()
+static void __exit sleep_exit(void)
{
remove_proc_entry(PROC_ENTRY_FILENAME, NULL);
pr_debug("/proc/%s removed\n", PROC_ENTRY_FILENAME);
}
+module_init(sleep_init);
+module_exit(sleep_exit);
+
MODULE_LICENSE("GPL");