1
0
mirror of https://github.com/sysprog21/lkmpg.git synced 2021-08-03 01:33:29 +03:00

Enforce the customized style for example code

Instead of using tab for indention, the style defaults to 4 spaces for
the sake of compact layout.
This commit is contained in:
Jim Huang
2021-07-22 06:58:13 +08:00
parent 936d82fad7
commit 50b8dfe6c2
33 changed files with 421 additions and 422 deletions

15
examples/.clang-format Normal file
View File

@@ -0,0 +1,15 @@
BasedOnStyle: Chromium
Language: Cpp
MaxEmptyLinesToKeep: 3
IndentCaseLabels: false
AllowShortIfStatementsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
DerivePointerAlignment: false
PointerAlignment: Right
SpaceAfterCStyleCast: true
TabWidth: 4
UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Linux
AccessModifierOffset: -4

View File

@@ -9,26 +9,22 @@
* Press one button to turn on a LED and another to turn it off
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
static int button_irqs[] = {-1, -1};
/* Define GPIOs for LEDs.
Change the numbers for the GPIO on your board. */
static struct gpio leds[] = {
{ 4, GPIOF_OUT_INIT_LOW, "LED 1" }
};
static struct gpio leds[] = {{4, GPIOF_OUT_INIT_LOW, "LED 1"}};
/* 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)
@@ -80,8 +76,7 @@ int init_module()
goto fail1;
}
pr_info("Current button1 value: %d\n",
gpio_get_value(buttons[0].gpio));
pr_info("Current button1 value: %d\n", gpio_get_value(buttons[0].gpio));
ret = gpio_to_irq(buttons[0].gpio);
@@ -92,8 +87,7 @@ int init_module()
button_irqs[0] = ret;
pr_info("Successfully requested BUTTON1 IRQ # %d\n",
button_irqs[0]);
pr_info("Successfully requested BUTTON1 IRQ # %d\n", button_irqs[0]);
ret = request_irq(button_irqs[0], button_isr,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
@@ -114,8 +108,7 @@ int init_module()
button_irqs[1] = ret;
pr_info("Successfully requested BUTTON2 IRQ # %d\n",
button_irqs[1]);
pr_info("Successfully requested BUTTON2 IRQ # %d\n", button_irqs[1]);
ret = request_irq(button_irqs[1], button_isr,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,

View File

@@ -3,18 +3,18 @@
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/cdev.h>
/*
* Prototypes - this would normally go in a .h file
@@ -42,12 +42,10 @@ static char *msg_Ptr;
static struct class *cls;
static struct file_operations chardev_fops = {
.read = device_read,
static struct file_operations chardev_fops = {.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
.release = device_release};
/*
* This function is called when the module is loaded
@@ -149,7 +147,6 @@ static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
* Actually put the data into the buffer
*/
while (length && *msg_Ptr) {
/*
* The buffer is in the user data segment, not the kernel
* segment so "*" assignment won't work. We have to use

View File

@@ -2,18 +2,18 @@
* chardev2.c - Create an input/output character device
*/
#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/module.h> /* Specifically, a module */
#include <linux/fs.h>
#include <linux/init.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/module.h> /* Specifically, a module */
#include <linux/poll.h>
#include <linux/cdev.h>
#include "chardev.h"
#define SUCCESS 0
@@ -110,7 +110,6 @@ static ssize_t device_read(struct file *file, /* see include/linux/fs.h */
* Actually put the data into the buffer
*/
while (length && *Message_Ptr) {
/*
* Because the buffer is in the user data segment,
* not the kernel data segment, assignment wouldn't
@@ -138,9 +137,10 @@ static ssize_t device_read(struct file *file, /* see include/linux/fs.h */
* This function is called when somebody tries to
* write into our device file.
*/
static ssize_t
device_write(struct file *file,
const char __user * buffer, size_t length, loff_t * offset)
static ssize_t device_write(struct file *file,
const char __user *buffer,
size_t length,
loff_t *offset)
{
int i;

View File

@@ -1,8 +1,8 @@
#include <linux/completion.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/completion.h>
#include <linux/module.h>
static struct {
struct completion crank_comp;
@@ -37,15 +37,12 @@ static int completions_init(void)
init_completion(&machine.crank_comp);
init_completion(&machine.flywheel_comp);
crank_thread =
kthread_create(machine_crank_thread,
NULL, "KThread Crank");
crank_thread = kthread_create(machine_crank_thread, NULL, "KThread Crank");
if (IS_ERR(crank_thread))
goto ERROR_THREAD_1;
flywheel_thread =
kthread_create(machine_flywheel_spinup_thread,
NULL, "KThread Flywheel");
flywheel_thread = kthread_create(machine_flywheel_spinup_thread, NULL,
"KThread Flywheel");
if (IS_ERR(flywheel_thread))
goto ERROR_THREAD_2;

View File

@@ -1,5 +1,5 @@
#include <linux/module.h>
#include <crypto/internal/hash.h>
#include <linux/module.h>
#define SHA256_LENGTH 32
@@ -26,8 +26,7 @@ int cryptosha256_init(void)
if (IS_ERR(sha256))
return -1;
shash =
kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(sha256),
shash = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(sha256),
GFP_KERNEL);
if (!shash)
return -ENOMEM;
@@ -51,9 +50,7 @@ int cryptosha256_init(void)
return 0;
}
void cryptosha256_exit(void)
{
}
void cryptosha256_exit(void) {}
module_init(cryptosha256_init);
module_exit(cryptosha256_exit);

View File

@@ -1,6 +1,6 @@
#include <crypto/internal/skcipher.h>
#include <linux/module.h>
#include <linux/crypto.h>
#include <linux/module.h>
#define SYMMETRIC_KEY_LENGTH 32
#define CIPHER_BLOCK_SIZE 16
@@ -42,18 +42,17 @@ static int test_skcipher_result(struct skcipher_def * sk, int rc)
case 0:
break;
case -EINPROGRESS || -EBUSY:
rc = wait_for_completion_interruptible(
&sk->result.completion);
rc = wait_for_completion_interruptible(&sk->result.completion);
if (!rc && !sk->result.err) {
reinit_completion(&sk->result.completion);
break;
}
pr_info("skcipher encrypt returned with %d result %d\n",
rc, sk->result.err);
pr_info("skcipher encrypt returned with %d result %d\n", rc,
sk->result.err);
break;
default:
pr_info("skcipher encrypt returned with %d result %d\n",
rc, sk->result.err);
pr_info("skcipher encrypt returned with %d result %d\n", rc,
sk->result.err);
break;
}
@@ -90,7 +89,8 @@ static void test_skcipher_callback(struct crypto_async_request *req, int error)
*/
}
static int test_skcipher_encrypt(char * plaintext, char * password,
static int test_skcipher_encrypt(char *plaintext,
char *password,
struct skcipher_def *sk)
{
int ret = -EFAULT;
@@ -114,8 +114,7 @@ static int test_skcipher_encrypt(char * plaintext, char * password,
}
skcipher_request_set_callback(sk->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
test_skcipher_callback,
&sk->result);
test_skcipher_callback, &sk->result);
/* clear the key */
memset((void *) key, '\0', SYMMETRIC_KEY_LENGTH);
@@ -153,8 +152,8 @@ static int test_skcipher_encrypt(char * plaintext, char * password,
sprintf((char *) sk->scratchpad, "%s", plaintext);
sg_init_one(&sk->sg, sk->scratchpad, CIPHER_BLOCK_SIZE);
skcipher_request_set_crypt(sk->req, &sk->sg, &sk->sg,
CIPHER_BLOCK_SIZE, sk->ivdata);
skcipher_request_set_crypt(sk->req, &sk->sg, &sk->sg, CIPHER_BLOCK_SIZE,
sk->ivdata);
init_completion(&sk->result.completion);
/* encrypt data */

View File

@@ -9,7 +9,8 @@ struct devicemodel_data {
static int devicemodel_probe(struct platform_device *dev)
{
struct devicemodel_data *pd = (struct devicemodel_data *)(dev->dev.platform_data);
struct devicemodel_data *pd =
(struct devicemodel_data *) (dev->dev.platform_data);
pr_info("devicemodel probe\n");
pr_info("devicemodel greeting: %s; %d\n", pd->greeting, pd->number);
@@ -46,18 +47,17 @@ static int devicemodel_resume(struct device *dev)
return 0;
}
static const struct dev_pm_ops devicemodel_pm_ops =
{
static const struct dev_pm_ops devicemodel_pm_ops = {
.suspend = devicemodel_suspend,
.resume = devicemodel_resume,
.poweroff = devicemodel_suspend,
.freeze = devicemodel_suspend,
.thaw = devicemodel_resume,
.restore = devicemodel_resume
};
.restore = devicemodel_resume};
static struct platform_driver devicemodel_driver = {
.driver = {
.driver =
{
.name = "devicemodel_example",
.owner = THIS_MODULE,
.pm = &devicemodel_pm_ops,

View File

@@ -1,17 +1,13 @@
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
#define BYTE_TO_BINARY(byte) \
(byte & 0x80 ? '1' : '0'), \
(byte & 0x40 ? '1' : '0'), \
(byte & 0x20 ? '1' : '0'), \
(byte & 0x10 ? '1' : '0'), \
(byte & 0x08 ? '1' : '0'), \
(byte & 0x04 ? '1' : '0'), \
(byte & 0x02 ? '1' : '0'), \
(byte & 0x01 ? '1' : '0')
(byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), \
(byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), \
(byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), \
(byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')
static void atomic_add_subtract(void)
{
@@ -28,8 +24,8 @@ static void atomic_add_subtract(void)
/* add one */
atomic_inc(&debbie);
pr_info("chris: %d, debbie: %d\n",
atomic_read(&chris), atomic_read(&debbie));
pr_info("chris: %d, debbie: %d\n", atomic_read(&chris),
atomic_read(&debbie));
}
static void atomic_bitwise(void)

View File

@@ -1,6 +1,6 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mutex.h>
DEFINE_MUTEX(mymutex);
@@ -20,8 +20,7 @@ static int example_mutex_init(void)
mutex_unlock(&mymutex);
pr_info("mutex is unlocked\n");
}
else
} else
pr_info("Failed to lock\n");
return 0;

View File

@@ -1,6 +1,6 @@
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
DEFINE_RWLOCK(myrwlock);

View File

@@ -1,8 +1,8 @@
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
DEFINE_SPINLOCK(sl_static);
spinlock_t sl_dynamic;

View File

@@ -1,7 +1,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
static void tasklet_fn(unsigned long data)
{

View File

@@ -1,8 +1,8 @@
/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/module.h> /* Needed by all modules */
int init_module(void)
{

View File

@@ -2,9 +2,9 @@
* hello-2.c - Demonstrating the module_init() and module_exit() macros.
* This is preferred over using init_module() and cleanup_module().
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/module.h> /* Needed by all modules */
static int __init hello_2_init(void)
{

View File

@@ -1,9 +1,9 @@
/*
* hello-3.c - Illustrating the __init, __initdata and __exit macros.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/module.h> /* Needed by all modules */
static int hello3_data __initdata = 3;

View File

@@ -1,9 +1,9 @@
/*
* hello-4.c - Demonstrates module documentation.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/module.h> /* Needed by all modules */
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Bob Mottram");

View File

@@ -1,10 +1,10 @@
/*
* hello-5.c - Demonstrates command line argument passing to a module.
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/stat.h>
MODULE_LICENSE("GPL");

View File

@@ -2,12 +2,12 @@
* hello-sysfs.c sysfs example
*/
#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kobject.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/sysfs.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Bob Mottram");
@@ -26,7 +26,8 @@ static ssize_t myvariable_show(struct kobject *kobj,
static ssize_t myvariable_store(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf, size_t count)
char *buf,
size_t count)
{
sscanf(buf, "%du", &myvariable);
return count;
@@ -34,8 +35,7 @@ static ssize_t myvariable_store(struct kobject *kobj,
static struct kobj_attribute myvariable_attribute =
__ATTR(myvariable, 0660, myvariable_show,
(void*)myvariable_store);
__ATTR(myvariable, 0660, myvariable_show, (void *) myvariable_store);
static int __init mymodule_init(void)
{
@@ -43,14 +43,14 @@ static int __init mymodule_init (void)
pr_info("mymodule: initialised\n");
mymodule =
kobject_create_and_add("mymodule", kernel_kobj);
mymodule = kobject_create_and_add("mymodule", kernel_kobj);
if (!mymodule)
return -ENOMEM;
error = sysfs_create_file(mymodule, &myvariable_attribute.attr);
if (error) {
pr_info("failed to create the myvariable file " \
pr_info(
"failed to create the myvariable file "
"in /sys/kernel/mymodule\n");
}

View File

@@ -9,25 +9,21 @@
* Press one button to turn on a LED and another to turn it off
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
static int button_irqs[] = {-1, -1};
/* Define GPIOs for LEDs.
Change the numbers for the GPIO on your board. */
static struct gpio leds[] = {
{ 4, GPIOF_OUT_INIT_LOW, "LED 1" }
};
static struct gpio leds[] = {{4, GPIOF_OUT_INIT_LOW, "LED 1"}};
/* 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"}};
/*
* interrupt function triggered when a button is pressed
@@ -66,8 +62,7 @@ int init_module()
goto fail1;
}
pr_info("Current button1 value: %d\n",
gpio_get_value(buttons[0].gpio));
pr_info("Current button1 value: %d\n", gpio_get_value(buttons[0].gpio));
ret = gpio_to_irq(buttons[0].gpio);
@@ -78,8 +73,7 @@ int init_module()
button_irqs[0] = ret;
pr_info("Successfully requested BUTTON1 IRQ # %d\n",
button_irqs[0]);
pr_info("Successfully requested BUTTON1 IRQ # %d\n", button_irqs[0]);
ret = request_irq(button_irqs[0], button_isr,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
@@ -100,8 +94,7 @@ int init_module()
button_irqs[1] = ret;
pr_info("Successfully requested BUTTON2 IRQ # %d\n",
button_irqs[1]);
pr_info("Successfully requested BUTTON2 IRQ # %d\n", button_irqs[1]);
ret = request_irq(button_irqs[1], button_isr,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,

View File

@@ -1,8 +1,8 @@
#include <linux/ioctl.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/ioctl.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
@@ -32,7 +32,10 @@ struct test_ioctl_data {
rwlock_t lock;
};
static long test_ioctl_ioctl(struct file* filp, unsigned int cmd, unsigned long arg) {
static long test_ioctl_ioctl(struct file *filp,
unsigned int cmd,
unsigned long arg)
{
struct test_ioctl_data *ioctl_data = filp->private_data;
int retval = 0;
unsigned char val;
@@ -102,7 +105,11 @@ done:
return retval;
}
ssize_t test_ioctl_read(struct file* filp, char __user* buf, size_t count, loff_t* f_pos) {
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;
int retval;
@@ -123,7 +130,8 @@ out:
return retval;
}
static int test_ioctl_close(struct inode* inode, struct file* filp) {
static int test_ioctl_close(struct inode *inode, struct file *filp)
{
pr_alert("%s call.\n", __func__);
if (filp->private_data) {
@@ -134,7 +142,8 @@ static int test_ioctl_close(struct inode* inode, struct file* filp) {
return 0;
}
static int test_ioctl_open(struct inode* inode, struct file* filp) {
static int test_ioctl_open(struct inode *inode, struct file *filp)
{
struct test_ioctl_data *ioctl_data;
pr_alert("%s call.\n", __func__);
ioctl_data = kmalloc(sizeof(struct test_ioctl_data), GFP_KERNEL);
@@ -157,7 +166,8 @@ struct file_operations fops = {
.unlocked_ioctl = test_ioctl_ioctl,
};
static int ioctl_init(void) {
static int ioctl_init(void)
{
dev_t dev = MKDEV(test_ioctl_major, 0);
int alloc_ret = 0;
int cdev_ret = 0;
@@ -175,7 +185,8 @@ static int ioctl_init(void) {
goto error;
}
pr_alert("%s driver(major: %d) installed.\n", DRIVER_NAME, test_ioctl_major);
pr_alert("%s driver(major: %d) installed.\n", DRIVER_NAME,
test_ioctl_major);
return 0;
error:
@@ -190,7 +201,8 @@ error:
return -1;
}
static void ioctl_exit(void) {
static void ioctl_exit(void)
{
dev_t dev = MKDEV(test_ioctl_major, 0);
cdev_del(&test_ioctl_cdev);
unregister_chrdev_region(dev, num_of_dev);

View File

@@ -2,13 +2,13 @@
* kbleds.c - Blink keyboard leds until the module is unloaded.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/vt_kern.h> /* for fg_console */
#include <linux/tty.h> /* For fg_console, MAX_NR_CONSOLES */
#include <linux/kd.h> /* For KDSETLED */
#include <linux/vt.h>
#include <linux/console_struct.h> /* For vc_cons */
#include <linux/init.h>
#include <linux/kd.h> /* For KDSETLED */
#include <linux/module.h>
#include <linux/tty.h> /* For fg_console, MAX_NR_CONSOLES */
#include <linux/vt.h>
#include <linux/vt_kern.h> /* for fg_console */
MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs.");
MODULE_AUTHOR("Daniele Paolo Scarpazza");
@@ -62,9 +62,8 @@ static int __init kbleds_init(void)
for (i = 0; i < MAX_NR_CONSOLES; i++) {
if (!vc_cons[i].d)
break;
pr_info("poet_atkm: console[%i/%i] #%i, tty %lx\n", i,
MAX_NR_CONSOLES, vc_cons[i].d->vc_num,
(unsigned long)vc_cons[i].d->port.tty);
pr_info("poet_atkm: console[%i/%i] #%i, tty %lx\n", i, MAX_NR_CONSOLES,
vc_cons[i].d->vc_num, (unsigned long) vc_cons[i].d->port.tty);
}
pr_info("kbleds: finished scanning consoles\n");
@@ -74,7 +73,8 @@ static int __init kbleds_init(void)
/*
* Set up the LED blink timer the first time
*/
timer_setup(&my_timer, (void*)&my_timer_func, (unsigned long)&kbledstatus);
timer_setup(&my_timer, (void *) &my_timer_func,
(unsigned long) &kbledstatus);
my_timer.expires = jiffies + BLINK_DELAY;
add_timer(&my_timer);
@@ -85,8 +85,8 @@ static void __exit kbleds_cleanup(void)
{
pr_info("kbleds: unloading...\n");
del_timer(&my_timer);
(my_driver->ops->ioctl) (vc_cons[fg_console].d->port.tty,
KDSETLED, RESTORE_LEDS);
(my_driver->ops->ioctl)(vc_cons[fg_console].d->port.tty, KDSETLED,
RESTORE_LEDS);
}
module_init(kbleds_init);

View File

@@ -2,11 +2,11 @@
* wait for input */
/* Copyright (C) 1998 by Ori Pomerantz */
#include <stdio.h> /* standard I/O */
#include <fcntl.h> /* for open */
#include <unistd.h> /* for read */
#include <stdlib.h> /* for exit */
#include <errno.h> /* for errno */
#include <fcntl.h> /* for open */
#include <stdio.h> /* standard I/O */
#include <stdlib.h> /* for exit */
#include <unistd.h> /* for read */
#define MAX_BYTES 1024 * 4

View File

@@ -3,9 +3,9 @@
* through X11, telnet, etc. We do this by printing the string to the tty
* associated with the current task.
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h> /* For current */
#include <linux/tty.h> /* For the tty declarations */
#include <linux/version.h> /* For LINUX_VERSION_CODE */
@@ -39,7 +39,6 @@ static void print_string(char *str)
* (ie, if it's a daemon). If so, there's nothing we can do.
*/
if (my_tty != NULL) {
/*
* my_tty->driver is a struct which holds the tty's functions,
* one of which (write) is used to write strings to the tty.

View File

@@ -2,8 +2,8 @@
procfs1.c
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
@@ -12,8 +12,10 @@
struct proc_dir_entry *Our_Proc_File;
ssize_t procfile_read(struct file *filePointer,char *buffer,
size_t buffer_length, loff_t * offset)
ssize_t procfile_read(struct file *filePointer,
char *buffer,
size_t buffer_length,
loff_t *offset)
{
int ret = 0;
if (strlen(buffer) == 0) {
@@ -22,7 +24,6 @@ ssize_t procfile_read(struct file *filePointer,char *buffer,
ret = sizeof("HelloWorld!\n");
}
return ret;
}
static const struct proc_ops proc_file_fops = {

View File

@@ -3,8 +3,8 @@
*
*/
#include <linux/module.h> /* Specifically, a module */
#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/module.h> /* Specifically, a module */
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
#include <linux/uaccess.h> /* for copy_from_user */
@@ -33,8 +33,10 @@ 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)
ssize_t procfile_read(struct file *filePointer,
char *buffer,
size_t buffer_length,
loff_t *offset)
{
int ret = 0;
if (strlen(buffer) == 0) {
@@ -50,8 +52,10 @@ ssize_t procfile_read(struct file *filePointer,char *buffer,
* 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 *buff,
size_t len,
loff_t *off)
{
procfs_buffer_size = len;
if (procfs_buffer_size > PROCFS_MAX_SIZE)

View File

@@ -15,12 +15,13 @@ 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 *buffer,
size_t length,
loff_t *offset)
{
static int finished = 0;
if(finished)
{
if (finished) {
pr_debug("procfs_read: END\n");
finished = 0;
return 0;
@@ -31,8 +32,10 @@ static ssize_t procfs_read(struct file *filp, char *buffer,
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 *buffer,
size_t len,
loff_t *off)
{
if (len > PROCFS_MAX_SIZE)
procfs_buffer_size = PROCFS_MAX_SIZE;
@@ -63,11 +66,12 @@ static struct proc_ops File_Ops_4_Our_Proc_File = {
int init_module()
{
Our_Proc_File = proc_create(PROCFS_ENTRY_FILENAME, 0644, NULL,&File_Ops_4_Our_Proc_File);
if(Our_Proc_File == NULL)
{
Our_Proc_File = proc_create(PROCFS_ENTRY_FILENAME, 0644, NULL,
&File_Ops_4_Our_Proc_File);
if (Our_Proc_File == NULL) {
remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);
pr_debug("Error: Could not initialize /proc/%s\n", PROCFS_ENTRY_FILENAME);
pr_debug("Error: Could not initialize /proc/%s\n",
PROCFS_ENTRY_FILENAME);
return -ENOMEM;
}
proc_set_size(Our_Proc_File, 80);

View File

@@ -29,8 +29,7 @@ static void *my_seq_start(struct seq_file *s, loff_t *pos)
if (*pos == 0) {
/* yes => return a non null value to begin the sequence */
return &counter;
}
else {
} else {
/* no => it's the end of the sequence, return end to stop reading */
*pos = 0;
return NULL;
@@ -75,12 +74,10 @@ static int my_seq_show(struct seq_file *s, void *v)
* This structure gather "function" to manage the sequence
*
*/
static struct seq_operations my_seq_ops = {
.start = my_seq_start,
static struct seq_operations my_seq_ops = {.start = my_seq_start,
.next = my_seq_next,
.stop = my_seq_stop,
.show = my_seq_show
};
.show = my_seq_show};
/**
* This function is called when the /proc file is open.
@@ -95,12 +92,10 @@ static int my_open(struct inode *inode, struct file *file)
* This structure gather "function" that manage the /proc file
*
*/
static struct proc_ops my_file_ops = {
.proc_open = my_open,
static struct proc_ops my_file_ops = {.proc_open = my_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = seq_release
};
.proc_release = seq_release};
/**
@@ -112,8 +107,7 @@ int init_module(void)
struct proc_dir_entry *entry;
entry = proc_create(PROC_NAME, 0, NULL, &my_file_ops);
if(entry == NULL)
{
if (entry == NULL) {
remove_proc_entry(PROC_NAME, NULL);
pr_debug("Error: Could not initialize /proc/%s\n", PROC_NAME);
return -ENOMEM;

View File

@@ -1,5 +1,5 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/workqueue.h>
static struct workqueue_struct *queue = NULL;

View File

@@ -144,20 +144,19 @@ static int module_open(struct inode *inode, struct file *file)
/*
* Emmanuel Papirakis:
*
* This is a little update to work with 2.2.*. Signals now are contained in
* two words (64 bits) and are stored in a structure that contains an array of
* two unsigned longs. We now have to make 2 checks in our if.
* This is a little update to work with 2.2.*. Signals now are
* contained in two words (64 bits) and are stored in a structure that
* contains an array of two unsigned longs. We now have to make 2
* checks in our if.
*
* Ori Pomerantz:
*
* Nobody promised me they'll never use more than 64 bits, or that this book
* won't be used for a version of Linux with a word size of 16 bits. This code
* would work in any case.
* Nobody promised me they'll never use more than 64 bits, or that this
* book won't be used for a version of Linux with a word size of 16
* bits. This code would work in any case.
*/
for (i = 0; i < _NSIG_WORDS && !is_sig; i++)
is_sig =
current->pending.signal.sig[i] & ~current->
blocked.sig[i];
is_sig = current->pending.signal.sig[i] & ~current->blocked.sig[i];
if (is_sig) {
/*
@@ -237,9 +236,9 @@ static struct proc_ops File_Ops_4_Our_Proc_File = {
int init_module()
{
Our_Proc_File = proc_create(PROC_ENTRY_FILENAME, 0644, NULL, &File_Ops_4_Our_Proc_File);
if(Our_Proc_File == NULL)
{
Our_Proc_File =
proc_create(PROC_ENTRY_FILENAME, 0644, NULL, &File_Ops_4_Our_Proc_File);
if (Our_Proc_File == NULL) {
remove_proc_entry(PROC_ENTRY_FILENAME, NULL);
pr_debug("Error: Could not initialize /proc/%s\n", PROC_ENTRY_FILENAME);
return -ENOMEM;

View File

@@ -10,12 +10,12 @@
* https://bbs.archlinux.org/viewtopic.php?id=139406
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/syscalls.h>
#include <linux/delay.h>
#include <asm/paravirt.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h> /* which will have params */
#include <linux/syscalls.h>
#include <linux/unistd.h> /* The list of system calls */
/*