@@ -110,20 +110,17 @@ static int __init testfunc(void)
return 0;
}
-static ssize_t fifo_write(struct file *file, const char __user *buf,
+static ssize_t fifo_write(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
- int ret;
unsigned int copied;
if (mutex_lock_interruptible(&write_access))
return -ERESTARTSYS;
- ret = kfifo_from_user(&test, buf, count, &copied);
+ copied = kfifo_in(&test, buf, count);
mutex_unlock(&write_access);
- if (ret)
- return ret;
return copied;
}
@@ -148,7 +145,7 @@ static ssize_t fifo_read(struct file *file, char __user *buf,
static const struct proc_ops fifo_proc_ops = {
.proc_read = fifo_read,
- .proc_write = fifo_write,
+ .proc_write_buf = fifo_write,
.proc_lseek = noop_llseek,
};
@@ -103,20 +103,18 @@ static int __init testfunc(void)
return 0;
}
-static ssize_t fifo_write(struct file *file, const char __user *buf,
+static ssize_t fifo_write(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
- int ret;
unsigned int copied;
if (mutex_lock_interruptible(&write_access))
return -ERESTARTSYS;
- ret = kfifo_from_user(&test, buf, count, &copied);
+ copied = kfifo_in(&test, (const int *)buf, count / sizeof(int)) *
+ sizeof(int);
mutex_unlock(&write_access);
- if (ret)
- return ret;
return copied;
}
@@ -141,7 +139,7 @@ static ssize_t fifo_read(struct file *file, char __user *buf,
static const struct proc_ops fifo_proc_ops = {
.proc_read = fifo_read,
- .proc_write = fifo_write,
+ .proc_write_buf = fifo_write,
.proc_lseek = noop_llseek,
};
@@ -117,20 +117,17 @@ static int __init testfunc(void)
return 0;
}
-static ssize_t fifo_write(struct file *file, const char __user *buf,
+static ssize_t fifo_write(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
- int ret;
unsigned int copied;
if (mutex_lock_interruptible(&write_access))
return -ERESTARTSYS;
- ret = kfifo_from_user(&test, buf, count, &copied);
+ copied = kfifo_in(&test, buf, count);
mutex_unlock(&write_access);
- if (ret)
- return ret;
return copied;
}
@@ -155,8 +152,11 @@ static ssize_t fifo_read(struct file *file, char __user *buf,
static const struct proc_ops fifo_proc_ops = {
.proc_read = fifo_read,
- .proc_write = fifo_write,
+ .proc_write_buf = fifo_write,
.proc_lseek = noop_llseek,
+ /* kfifo_from_user() cut a record to what its length byte holds */
+ .proc_flags = PROC_ENTRY_SHORT_WRITES,
+ .proc_write_size = U8_MAX,
};
static int __init example_init(void)
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and put that copy into the fifo with kfifo_in() instead of kfifo_from_user(). Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now. kfifo_from_user() cut a record to 255 bytes, what the one byte that holds its length can say, so the record sample keeps doing that with PROC_ENTRY_SHORT_WRITES. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org> --- samples/kfifo/bytestream-example.c | 9 +++------ samples/kfifo/inttype-example.c | 10 ++++------ samples/kfifo/record-example.c | 12 ++++++------ 3 files changed, 13 insertions(+), 18 deletions(-)