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 <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rwsem.h>
#ifdef DEBUG
#include <linux/kernel.h>
#include <linux/delay.h>
#endif
#define BUFFER_LENGTH 10
@ -23,18 +23,19 @@ static char *id_msg;
static char *foo_msg;
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;
const char *msg_tmp = id_msg;
int bytes = 0;
const char *msg_tmp = id_msg;
/*
* TODO
if (!*(msg_tmp + *offset)) {
*offset = 0;
return 0;
}
*/
/*
* TODO
if (!*(msg_tmp + *offset)) {
*offset = 0;
return 0;
}
*/
msg_tmp += *offset;
@ -82,46 +83,51 @@ static const struct file_operations id_fops = {
.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 tmp_len = strlen(foo_msg);
int bytes = -EINVAL;
int tmp_len = strlen(foo_msg);
if (*offset > tmp_len) bytes = -EFAULT;
else if (down_read_trylock(&foo_sem))
{
char *tmp_str = foo_msg + *offset;
tmp_len = strlen(tmp_str);
if (*offset > tmp_len) {
bytes = -EFAULT;
} else if (down_read_trylock(&foo_sem)) {
char *tmp_str = foo_msg + *offset;
bytes = tmp_len > count ? count : tmp_len;
if (copy_to_user(buffer, tmp_str, bytes)) bytes = -EFAULT;
else *offset += bytes;
tmp_len = strlen(tmp_str);
bytes = tmp_len > count ? count : tmp_len;
if (copy_to_user(buffer, tmp_str, bytes))
bytes = -EFAULT;
else
*offset += bytes;
#ifdef DEBUG
msleep(5000);
msleep(5000);
#endif
up_read(&foo_sem);
}
up_read(&foo_sem);
}
return bytes;
return bytes;
}
static ssize_t foo_write(struct file *, const char __user *buffer,
size_t count, loff_t * offset)
size_t count, loff_t *offset)
{
int bytes = -EINVAL;
int bytes = -EINVAL;
if ((*offset + count) > PAGE_SIZE) bytes = -EFAULT;
else if (down_write_trylock(&foo_sem))
{
bytes = count;
if (copy_from_user(foo_msg, buffer, bytes)) bytes = -EINVAL;
if ((*offset + count) > PAGE_SIZE) {
bytes = -EFAULT;
} else if (down_write_trylock(&foo_sem)) {
bytes = count;
if (copy_from_user(foo_msg, buffer, bytes))
bytes = -EINVAL;
#ifdef DEBUG
msleep(5000);
msleep(5000);
#endif
up_write(&foo_sem);
}
up_write(&foo_sem);
}
return bytes;
return bytes;
}
static const struct file_operations foo_fops = {
@ -132,25 +138,25 @@ static const struct file_operations foo_fops = {
static int __init my_init(void)
{
init_rwsem(&foo_sem);
id_msg = kmalloc(12, GFP_KERNEL);
foo_msg = kmalloc(PAGE_SIZE, GFP_KERNEL);
strcpy(id_msg, "pouetpouet\n");
init_rwsem(&foo_sem);
id_msg = kmalloc(12, GFP_KERNEL);
foo_msg = kmalloc(PAGE_SIZE, GFP_KERNEL);
strscpy(id_msg, "pouetpouet\n", 12);
pr_info("Coucou le gens !!!!\n");
folder = debugfs_create_dir("eudyptula", NULL);
id_file = debugfs_create_file("id", 0666, folder, NULL, &id_fops);
debugfs_create_u64("jiffies", 0444, folder, &jiffies_64);
foo_file = debugfs_create_file("foo", 0664, folder, NULL, &foo_fops);
folder = debugfs_create_dir("eudyptula", NULL);
id_file = debugfs_create_file("id", 0666, folder, NULL, &id_fops);
debugfs_create_u64("jiffies", 0444, folder, &jiffies_64);
foo_file = debugfs_create_file("foo", 0664, folder, NULL, &foo_fops);
return 0;
}
static void __exit my_exit(void)
{
debugfs_remove_recursive(folder);
kfree(id_msg);
kfree(foo_msg);
debugfs_remove_recursive(folder);
kfree(id_msg);
kfree(foo_msg);
pr_info("Tschuss !!!\n");
}