indent and checker

This commit is contained in:
rick 2024-01-11 19:55:48 +01:00
parent 1441afda58
commit 3d9046f06d
Signed by: Rick
GPG key ID: 5CBE8779CD27BCBA

View file

@ -4,13 +4,13 @@
#include <asm/page.h> #include <asm/page.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/rwsem.h> #include <linux/rwsem.h>
#ifdef DEBUG #ifdef DEBUG
#include <linux/kernel.h> #include <linux/delay.h>
#endif #endif
#define BUFFER_LENGTH 10 #define BUFFER_LENGTH 10
@ -23,7 +23,8 @@ static char *id_msg;
static char *foo_msg; static char *foo_msg;
static struct rw_semaphore foo_sem; static struct rw_semaphore foo_sem;
static ssize_t id_read(struct file *, char __user *buffer, size_t length, loff_t *offset) static ssize_t id_read(struct file *, char __user *buffer, size_t length,
loff_t *offset)
{ {
int bytes = 0; int bytes = 0;
const char *msg_tmp = id_msg; const char *msg_tmp = id_msg;
@ -82,20 +83,24 @@ static const struct file_operations id_fops = {
.write = id_write, .write = id_write,
}; };
static ssize_t foo_read(struct file *, char __user *buffer, size_t count, loff_t *offset) static ssize_t foo_read(struct file *, char __user *buffer, size_t count,
loff_t *offset)
{ {
int bytes = -EINVAL; int bytes = -EINVAL;
int tmp_len = strlen(foo_msg); int tmp_len = strlen(foo_msg);
if (*offset > tmp_len) bytes = -EFAULT; if (*offset > tmp_len) {
else if (down_read_trylock(&foo_sem)) bytes = -EFAULT;
{ } else if (down_read_trylock(&foo_sem)) {
char *tmp_str = foo_msg + *offset; char *tmp_str = foo_msg + *offset;
tmp_len = strlen(tmp_str);
tmp_len = strlen(tmp_str);
bytes = tmp_len > count ? count : tmp_len; bytes = tmp_len > count ? count : tmp_len;
if (copy_to_user(buffer, tmp_str, bytes)) bytes = -EFAULT;
else *offset += bytes; if (copy_to_user(buffer, tmp_str, bytes))
bytes = -EFAULT;
else
*offset += bytes;
#ifdef DEBUG #ifdef DEBUG
msleep(5000); msleep(5000);
#endif #endif
@ -110,11 +115,12 @@ static ssize_t foo_write(struct file *, const char __user *buffer,
{ {
int bytes = -EINVAL; int bytes = -EINVAL;
if ((*offset + count) > PAGE_SIZE) bytes = -EFAULT; if ((*offset + count) > PAGE_SIZE) {
else if (down_write_trylock(&foo_sem)) bytes = -EFAULT;
{ } else if (down_write_trylock(&foo_sem)) {
bytes = count; bytes = count;
if (copy_from_user(foo_msg, buffer, bytes)) bytes = -EINVAL; if (copy_from_user(foo_msg, buffer, bytes))
bytes = -EINVAL;
#ifdef DEBUG #ifdef DEBUG
msleep(5000); msleep(5000);
#endif #endif
@ -135,7 +141,7 @@ static int __init my_init(void)
init_rwsem(&foo_sem); init_rwsem(&foo_sem);
id_msg = kmalloc(12, GFP_KERNEL); id_msg = kmalloc(12, GFP_KERNEL);
foo_msg = kmalloc(PAGE_SIZE, GFP_KERNEL); foo_msg = kmalloc(PAGE_SIZE, GFP_KERNEL);
strcpy(id_msg, "pouetpouet\n"); strscpy(id_msg, "pouetpouet\n", 12);
pr_info("Coucou le gens !!!!\n"); pr_info("Coucou le gens !!!!\n");
folder = debugfs_create_dir("eudyptula", NULL); folder = debugfs_create_dir("eudyptula", NULL);