mirror of
https://github.com/nelsbrock/fun-linux-patches.git
synced 2026-08-14 21:56:48 +02:00
initial commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
|
||||
index 3c6670cf905f..ec176debb778 100644
|
||||
--- a/drivers/char/mem.c
|
||||
+++ b/drivers/char/mem.c
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <linux/uio.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/security.h>
|
||||
+#include <linux/minmax.h>
|
||||
+#include <linux/printk.h>
|
||||
|
||||
#define DEVMEM_MINOR 1
|
||||
#define DEVPORT_MINOR 4
|
||||
@@ -428,7 +430,20 @@ static ssize_t write_port(struct file *file, const char __user *buf,
|
||||
static ssize_t read_null(struct file *file, char __user *buf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
- return 0;
|
||||
+ static const char content[] = "null\n";
|
||||
+ size_t content_length = sizeof(content);
|
||||
+
|
||||
+ if (*ppos >= content_length)
|
||||
+ return 0;
|
||||
+
|
||||
+ size_t copy_len = min(content_length - *ppos, count);
|
||||
+ if (copy_to_user(buf, content + *ppos, copy_len)) {
|
||||
+ pr_err("null: User copy failed\n");
|
||||
+ return -EFAULT;
|
||||
+ }
|
||||
+
|
||||
+ *ppos += copy_len;
|
||||
+ return copy_len;
|
||||
}
|
||||
|
||||
static ssize_t write_null(struct file *file, const char __user *buf,
|
||||
@@ -437,33 +452,23 @@ static ssize_t write_null(struct file *file, const char __user *buf,
|
||||
return count;
|
||||
}
|
||||
|
||||
-static ssize_t read_iter_null(struct kiocb *iocb, struct iov_iter *to)
|
||||
-{
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
-static ssize_t write_iter_null(struct kiocb *iocb, struct iov_iter *from)
|
||||
+static ssize_t write_iter_zero(struct kiocb *iocb, struct iov_iter *from)
|
||||
{
|
||||
size_t count = iov_iter_count(from);
|
||||
iov_iter_advance(from, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
-static int pipe_to_null(struct pipe_inode_info *info, struct pipe_buffer *buf,
|
||||
+static int pipe_to_zero(struct pipe_inode_info *info, struct pipe_buffer *buf,
|
||||
struct splice_desc *sd)
|
||||
{
|
||||
return sd->len;
|
||||
}
|
||||
|
||||
-static ssize_t splice_write_null(struct pipe_inode_info *pipe, struct file *out,
|
||||
+static ssize_t splice_write_zero(struct pipe_inode_info *pipe, struct file *out,
|
||||
loff_t *ppos, size_t len, unsigned int flags)
|
||||
{
|
||||
- return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_null);
|
||||
-}
|
||||
-
|
||||
-static int uring_cmd_null(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
|
||||
-{
|
||||
- return 0;
|
||||
+ return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_zero);
|
||||
}
|
||||
|
||||
static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter)
|
||||
@@ -627,8 +632,6 @@ static int open_port(struct inode *inode, struct file *filp)
|
||||
#define zero_lseek null_lseek
|
||||
#define full_lseek null_lseek
|
||||
#define write_zero write_null
|
||||
-#define write_iter_zero write_iter_null
|
||||
-#define splice_write_zero splice_write_null
|
||||
#define open_mem open_port
|
||||
|
||||
static const struct file_operations __maybe_unused mem_fops = {
|
||||
@@ -644,13 +647,8 @@ static const struct file_operations __maybe_unused mem_fops = {
|
||||
};
|
||||
|
||||
static const struct file_operations null_fops = {
|
||||
- .llseek = null_lseek,
|
||||
.read = read_null,
|
||||
.write = write_null,
|
||||
- .read_iter = read_iter_null,
|
||||
- .write_iter = write_iter_null,
|
||||
- .splice_write = splice_write_null,
|
||||
- .uring_cmd = uring_cmd_null,
|
||||
};
|
||||
|
||||
static const struct file_operations __maybe_unused port_fops = {
|
||||
Reference in New Issue
Block a user