format files to comply with kernel coding standards, rename .config to config

This commit is contained in:
2025-08-13 19:45:11 +02:00
parent 2e4d67d510
commit cf0ab7f1db
10 changed files with 97 additions and 83 deletions

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
@ -13,7 +14,7 @@ ssize_t foo_write(struct file *f, const char __user *buf, size_t len, loff_t *of
int init_foo(void);
char buffer[PAGE_SIZE];
size_t buffer_len = 0;
size_t buffer_len;
DEFINE_MUTEX(rw_lock);
static const struct file_operations fops = {
@ -26,7 +27,7 @@ static const struct file_operations fops = {
ssize_t foo_read(struct file *f, char __user *buf, size_t len, loff_t *off)
{
size_t read;
mutex_lock(&rw_lock);
read = simple_read_from_buffer(buf, len, off, buffer, buffer_len);
mutex_unlock(&rw_lock);
@ -39,8 +40,7 @@ ssize_t foo_write(struct file *f, const char __user *buf, size_t len, loff_t *of
if (len > sizeof(buffer))
return -EINVAL;
mutex_lock(&rw_lock);
if (copy_from_user(buffer, buf, len))
{
if (copy_from_user(buffer, buf, len)) {
mutex_unlock(&rw_lock);
return -EINVAL;
}
@ -55,6 +55,7 @@ int init_foo(void)
mutex_init(&rw_lock);
ret = debugfs_create_file("foo", 0644, module_dir, NULL, &fops);
if (IS_ERR(ret)) return PTR_ERR(ret);
if (IS_ERR(ret))
return PTR_ERR(ret);
return 0;
}

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
@ -21,6 +22,7 @@ static const struct file_operations fops = {
ssize_t id_read(struct file *f, char __user *buf, size_t len, loff_t *off)
{
char msg[] = VALUE;
pr_info("someone read from the file\n");
return simple_read_from_buffer(buf, len, off, msg, sizeof(msg) - 1);
}
@ -29,6 +31,7 @@ ssize_t id_read(struct file *f, char __user *buf, size_t len, loff_t *off)
ssize_t id_write(struct file *f, const char __user *buf, size_t len, loff_t *off)
{
char kbuf[64];
if (len > sizeof(kbuf) - 1)
return -EINVAL;
if (copy_from_user(kbuf, buf, len))
@ -36,7 +39,7 @@ ssize_t id_write(struct file *f, const char __user *buf, size_t len, loff_t *off
kbuf[len] = '\0';
if (strcmp(kbuf, VALUE) == 0){
if (strcmp(kbuf, VALUE) == 0) {
pr_info("someone wrote the right string\n");
return len;
}
@ -47,8 +50,9 @@ ssize_t id_write(struct file *f, const char __user *buf, size_t len, loff_t *off
int init_id(void)
{
struct dentry *ret;
ret = debugfs_create_file("id", 0666, module_dir, NULL, &fops);
if(IS_ERR(ret))
if (IS_ERR(ret))
return PTR_ERR(ret);
return 0;
}

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
@ -15,8 +16,8 @@ int init_foo(void);
struct dentry *module_dir;
static int __init fortytwo_debug_init(void)
{
static int __init fortytwo_debug_init(void)
{
int err = 0;
pr_info("creating fortytwo debug dir\n");
@ -27,18 +28,19 @@ static int __init fortytwo_debug_init(void)
debugfs_create_u64("jiffies", 0444, module_dir, (uint64_t *)(&jiffies));
err = init_id();
if (err) return err;
if (err)
return err;
err = init_foo();
if(err) return err;
if (err)
return err;
return 0;
}
}
static void __exit fortytwo_debug_exit(void)
{
pr_info("removing forytwo debug dir\n");
static void __exit fortytwo_debug_exit(void)
{
pr_info("removing forytwo debug dir\n");
debugfs_remove(module_dir);
}
}
module_init(fortytwo_debug_init);
module_init(fortytwo_debug_init);
module_exit(fortytwo_debug_exit);