corrections on 03 and 08, 09 done

This commit is contained in:
2025-07-11 19:35:43 +02:00
parent fb12152966
commit 2e4d67d510
5 changed files with 115 additions and 18 deletions

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
@ -9,12 +10,12 @@ MODULE_LICENSE("GPL");
MODULE_AUTHOR("Louis Solofrizzo <louis@ne02ptzero.me>");
MODULE_DESCRIPTION("Useless module");
static ssize_t myfd_read (struct file *fp, char __user *user,
size_t size, loff_t *offs);
static ssize_t myfd_read(struct file *fp, char __user *user,
size_t size, loff_t *offs);
static ssize_t myfd_write(struct file *fp, const char __user *user,
size_t size, loff_t *offs);
size_t size, loff_t *offs);
static struct file_operations myfd_fops = {
static const struct file_operations myfd_fops = {
.owner = THIS_MODULE,
.read = &myfd_read,
.write = &myfd_write
@ -27,7 +28,8 @@ static struct miscdevice myfd_device = {
};
char str[PAGE_SIZE];
DEFINE_MUTEX(rw_lock);
DEFINE_MUTEX(rw_lock); //lock read/write operations of the /dev/reverse file
static int __init myfd_init(void)
{
@ -45,25 +47,25 @@ ssize_t myfd_read(struct file *fp, char __user *user, size_t size, loff_t *offs)
ssize_t retval;
size_t len;
char *tmp;
mutex_lock(&rw_lock);
len = strlen(str);
tmp = kmalloc(sizeof(char) * PAGE_SIZE, GFP_KERNEL);
for (size_t i = 0,j = len - 1; i < len; i++, j--) {
for (size_t i = 0, j = len - 1; i < len; i++, j--)
tmp[i] = str[j];
}
tmp[len] = 0;
retval = simple_read_from_buffer(user, size, offs, tmp, len);
mutex_unlock(&rw_lock);
kfree(tmp);
return retval;
}
ssize_t myfd_write(struct file *fp, const char __user *user, size_t size,
loff_t *offs)
loff_t *offs)
{
ssize_t res;
if(size >= (PAGE_SIZE - 1))
if (size >= (PAGE_SIZE - 1))
return -EINVAL;
mutex_lock(&rw_lock);
res = simple_write_to_buffer(str, size, offs, user, size);