pr_info("Bottom half tasklet ends\n");
}
-DECLARE_TASKLET_OLD(buttontask, bottomhalf_tasklet_fn);
+static DECLARE_TASKLET_OLD(buttontask, bottomhalf_tasklet_fn);
/* interrupt function triggered when a button is pressed */
static irqreturn_t button_isr(int irq, void *data)
/* Prototypes - this would normally go in a .h file */
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
-static ssize_t device_read(struct file *, char *, size_t, loff_t *);
-static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
+static ssize_t device_read(struct file *, char __user *, size_t, loff_t *);
+static ssize_t device_write(struct file *, const char __user *, size_t,
+ loff_t *);
#define SUCCESS 0
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
* read from it.
*/
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
- char *buffer, /* buffer to fill with data */
+ char __user *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t *offset)
{
}
/* Called when a process writes to dev file: echo "hi" > /dev/hello */
-static ssize_t device_write(struct file *filp, const char *buff, size_t len,
- loff_t *off)
+static ssize_t device_write(struct file *filp, const char __user *buff,
+ size_t len, loff_t *off)
{
pr_alert("Sorry, this operation is not supported.\n");
return -EINVAL;
* If the ioctl is write or read/write (meaning output is returned to the
* calling process), the ioctl call returns the output of this function.
*/
-long device_ioctl(struct file *file, /* ditto */
- unsigned int ioctl_num, /* number and param for ioctl */
- unsigned long ioctl_param)
+static long
+device_ioctl(struct file *file, /* ditto */
+ unsigned int ioctl_num, /* number and param for ioctl */
+ unsigned long ioctl_param)
{
int i;
char *temp;
temp = (char *)ioctl_param;
/* Find the length of the message */
- get_user(ch, temp);
+ get_user(ch, (char __user *)temp);
for (i = 0; ch && i < BUF_LEN; i++, temp++)
- get_user(ch, temp);
+ get_user(ch, (char __user *)temp);
- device_write(file, (char *)ioctl_param, i, 0);
+ device_write(file, (char __user *)ioctl_param, i, NULL);
break;
case IOCTL_GET_MSG:
/* Give the current message to the calling process - the parameter
* we got is a pointer, fill it.
*/
- i = device_read(file, (char *)ioctl_param, 99, 0);
+ i = device_read(file, (char __user *)ioctl_param, 99, NULL);
/* Put a zero at the end of the buffer, so it will be properly
* terminated.
*/
- put_user('\0', (char *)ioctl_param + i);
+ put_user('\0', (char __user *)ioctl_param + i);
break;
case IOCTL_GET_NTH_BYTE:
* is kept in the devices table, it can't be local to init_module. NULL is
* for unimplemented functions.
*/
-struct file_operations fops = {
+static struct file_operations fops = {
.read = device_read,
.write = device_write,
.unlocked_ioctl = device_ioctl,
return -1;
}
-void completions_exit(void)
+static void completions_exit(void)
{
wait_for_completion(&machine.crank_comp);
wait_for_completion(&machine.flywheel_comp);
pr_info("%s\n", str);
}
-int cryptosha256_init(void)
+static int cryptosha256_init(void)
{
char *plaintext = "This is a test";
char hash_sha256[SHA256_LENGTH];
return 0;
}
-void cryptosha256_exit(void)
+static void cryptosha256_exit(void)
{
}
return ret;
}
-int cryptoapi_init(void)
+static int cryptoapi_init(void)
{
/* The world's favorite password */
char *password = "password123";
return 0;
}
-void cryptoapi_exit(void)
+static void cryptoapi_exit(void)
{
test_skcipher_finish(&sk);
}
#include <linux/module.h>
#include <linux/mutex.h>
-DEFINE_MUTEX(mymutex);
+static DEFINE_MUTEX(mymutex);
static int example_mutex_init(void)
{
#include <linux/kernel.h>
#include <linux/module.h>
-DEFINE_RWLOCK(myrwlock);
+static DEFINE_RWLOCK(myrwlock);
static void example_read_lock(void)
{
#include <linux/module.h>
#include <linux/spinlock.h>
-DEFINE_SPINLOCK(sl_static);
-spinlock_t sl_dynamic;
+static DEFINE_SPINLOCK(sl_static);
+static spinlock_t sl_dynamic;
static void example_spinlock_static(void)
{
pr_info("Example tasklet ends\n");
}
-DECLARE_TASKLET_OLD(mytask, tasklet_fn);
+static DECLARE_TASKLET_OLD(mytask, tasklet_fn);
static int example_tasklet_init(void)
{
return retval;
}
-ssize_t test_ioctl_read(struct file *filp, char __user *buf, size_t count,
- loff_t *f_pos)
+static ssize_t test_ioctl_read(struct file *filp, char __user *buf,
+ size_t count, loff_t *f_pos)
{
struct test_ioctl_data *ioctl_data = filp->private_data;
unsigned char val;
return 0;
}
-struct file_operations fops = {
+static struct file_operations fops = {
.owner = THIS_MODULE,
.open = test_ioctl_open,
.release = test_ioctl_close,
MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs.");
-struct timer_list my_timer;
-struct tty_driver *my_driver;
-char kbledstatus = 0;
+static struct timer_list my_timer;
+static struct tty_driver *my_driver;
+static char kbledstatus = 0;
#define BLINK_DELAY HZ / 5
#define ALL_LEDS_ON 0x07
#define procfs_name "helloworld"
-struct proc_dir_entry *our_proc_file;
+static struct proc_dir_entry *our_proc_file;
-ssize_t procfile_read(struct file *filePointer, char *buffer,
- size_t buffer_length, loff_t *offset)
+static ssize_t procfile_read(struct file *filePointer, char __user *buffer,
+ size_t buffer_length, loff_t *offset)
{
char s[13] = "HelloWorld!\n";
int len = sizeof(s);
static unsigned long procfs_buffer_size = 0;
/* This function is called then the /proc file is read */
-ssize_t procfile_read(struct file *filePointer, char *buffer,
- size_t buffer_length, loff_t *offset)
+static ssize_t procfile_read(struct file *filePointer, char __user *buffer,
+ size_t buffer_length, loff_t *offset)
{
char s[13] = "HelloWorld!\n";
int len = sizeof(s);
}
/* This function is called with the /proc file is written. */
-static ssize_t procfile_write(struct file *file, const char *buff, size_t len,
- loff_t *off)
+static ssize_t procfile_write(struct file *file, const char __user *buff,
+ size_t len, loff_t *off)
{
procfs_buffer_size = len;
if (procfs_buffer_size > PROCFS_MAX_SIZE)
#define PROCFS_MAX_SIZE 2048
#define PROCFS_ENTRY_FILENAME "buffer2k"
-struct proc_dir_entry *our_proc_file;
+static struct proc_dir_entry *our_proc_file;
static char procfs_buffer[PROCFS_MAX_SIZE];
static unsigned long procfs_buffer_size = 0;
-static ssize_t procfs_read(struct file *filp, char *buffer, size_t length,
- loff_t *offset)
+static ssize_t procfs_read(struct file *filp, char __user *buffer,
+ size_t length, loff_t *offset)
{
static int finished = 0;
pr_debug("procfs_read: read %lu bytes\n", procfs_buffer_size);
return procfs_buffer_size;
}
-static ssize_t procfs_write(struct file *file, const char *buffer, size_t len,
- loff_t *off)
+static ssize_t procfs_write(struct file *file, const char __user *buffer,
+ size_t len, loff_t *off)
{
if (len > PROCFS_MAX_SIZE)
procfs_buffer_size = PROCFS_MAX_SIZE;
pr_debug("procfs_write: write %lu bytes\n", procfs_buffer_size);
return procfs_buffer_size;
}
-int procfs_open(struct inode *inode, struct file *file)
+static int procfs_open(struct inode *inode, struct file *file)
{
try_module_get(THIS_MODULE);
return 0;
}
-int procfs_close(struct inode *inode, struct file *file)
+static int procfs_close(struct inode *inode, struct file *file)
{
module_put(THIS_MODULE);
return 0;
* function.
*/
static ssize_t module_output(struct file *file, /* see include/linux/fs.h */
- char *buf, /* The buffer to put data to
+ char __user *buf, /* The buffer to put data to
(in the user segment) */
size_t len, /* The length of the buffer */
loff_t *offset)
* /proc file.
*/
static ssize_t module_input(struct file *file, /* The file itself */
- const char *buf, /* The buffer with input */
+ const char __user *buf, /* The buffer with input */
size_t length, /* The buffer's length */
loff_t *offset) /* offset to file - ignore */
{
}
/* 1 if the file is currently open by somebody */
-int already_open = 0;
+static int already_open = 0;
/* Queue of processes who want our file */
-DECLARE_WAIT_QUEUE_HEAD(waitq);
+static DECLARE_WAIT_QUEUE_HEAD(waitq);
/* Called when the /proc file is opened */
static int module_open(struct inode *inode, struct file *file)
}
/* Called when the /proc file is closed */
-int module_close(struct inode *inode, struct file *file)
+static int module_close(struct inode *inode, struct file *file)
{
/* Set already_open to zero, so one of the processes in the waitq will
* be able to set already_open back to one and to open the file. All
#include <linux/kernel.h> /* We are doing kernel work */
#include <linux/module.h> /* Specifically, a module */
-void cleanup_module()
+void cleanup_module(void)
{
pr_info("Short is the life of a kernel module\n");
}
#endif /* Version < v5.7 */
-unsigned long **sys_call_table;
+static unsigned long **sys_call_table;
/* UID we want to spy on - will be filled from the command line. */
static int uid;
* Another reason for this is that we can not get sys_open.
* It is a static variable, so it is not exported.
*/
-asmlinkage int (*original_call)(const char *, int, int);
+static asmlinkage int (*original_call)(const char *, int, int);
/* The function we will replace sys_open (the function called when you
* call the open system call) with. To find the exact prototype, with
* wreck havoc and require programs to be recompiled, since the system
* calls are the interface between the kernel and the processes).
*/
-asmlinkage int our_sys_open(const char *filename, int flags, int mode)
+static asmlinkage int our_sys_open(const char *filename, int flags, int mode)
{
int i = 0;
char ch;
/* Report the file, if relevant */
pr_info("Opened file by %d: ", uid);
do {
- get_user(ch, filename + i);
+ get_user(ch, (char __user *)filename + i);
i++;
pr_info("%c", ch);
} while (ch != 0);