[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-103-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:14:02 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 102/437] lib: convert to read/write iterators
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
lib/dynamic_debug.c | 5 +++--
lib/kunit/debugfs.c | 13 ++++++-------
lib/test_firmware.c | 10 ++++------
lib/xz/xz_dec_test.c | 9 ++++-----
4 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index c78f335fa981..534ad9218557 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1022,6 +1022,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
*offp += len;
return len;
}
+FOPS_WRITE_ITER_HELPER(ddebug_proc_write);
/*
* Set the iterator to point to the first _ddebug object
@@ -1182,10 +1183,10 @@ static int ddebug_proc_open(struct inode *inode, struct file *file)
static const struct file_operations ddebug_proc_fops = {
.owner = THIS_MODULE,
.open = ddebug_proc_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = seq_release_private,
- .write = ddebug_proc_write
+ .write_iter = ddebug_proc_write_iter
};
static const struct proc_ops proc_fops = {
diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c
index d548750a325a..ea7be601cf9e 100644
--- a/lib/kunit/debugfs.c
+++ b/lib/kunit/debugfs.c
@@ -139,28 +139,27 @@ static int debugfs_run_open(struct inode *inode, struct file *file)
*
* Note: what is written to this file will not be saved.
*/
-static ssize_t debugfs_run(struct file *file,
- const char __user *buf, size_t count, loff_t *ppos)
+static ssize_t debugfs_run(struct kiocb *iocb, struct iov_iter *from)
{
- struct inode *f_inode = file->f_inode;
+ struct inode *f_inode = iocb->ki_filp->f_inode;
struct kunit_suite *suite = (struct kunit_suite *) f_inode->i_private;
__kunit_test_suites_init(&suite, 1);
- return count;
+ return iov_iter_count(from);
}
static const struct file_operations debugfs_results_fops = {
.open = debugfs_results_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = debugfs_release,
};
static const struct file_operations debugfs_run_fops = {
.open = debugfs_run_open,
- .read = seq_read,
- .write = debugfs_run,
+ .read_iter = seq_read_iter,
+ .write_iter = debugfs_run,
.llseek = seq_lseek,
.release = debugfs_release,
};
diff --git a/lib/test_firmware.c b/lib/test_firmware.c
index 9cfdcd6d21db..face875a52e2 100644
--- a/lib/test_firmware.c
+++ b/lib/test_firmware.c
@@ -147,23 +147,21 @@ static struct test_firmware_upload *upload_lookup_name(const char *name)
return NULL;
}
-static ssize_t test_fw_misc_read(struct file *f, char __user *buf,
- size_t size, loff_t *offset)
+static ssize_t test_fw_misc_read(struct kiocb *iocb, struct iov_iter *to)
{
ssize_t rc = 0;
mutex_lock(&test_fw_mutex);
if (test_firmware)
- rc = simple_read_from_buffer(buf, size, offset,
- test_firmware->data,
- test_firmware->size);
+ rc = simple_copy_to_iter(test_firmware->data, &iocb->ki_pos,
+ test_firmware->size, to);
mutex_unlock(&test_fw_mutex);
return rc;
}
static const struct file_operations test_fw_fops = {
.owner = THIS_MODULE,
- .read = test_fw_misc_read,
+ .read_iter = test_fw_misc_read,
};
static void __test_release_all_firmware(void)
diff --git a/lib/xz/xz_dec_test.c b/lib/xz/xz_dec_test.c
index da28a19d6c98..42dc077e247b 100644
--- a/lib/xz/xz_dec_test.c
+++ b/lib/xz/xz_dec_test.c
@@ -99,9 +99,9 @@ static int xz_dec_test_release(struct inode *i, struct file *f)
* The .xz file must have exactly one Stream and no Stream Padding. The data
* after the first Stream is considered to be garbage.
*/
-static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
- size_t size, loff_t *pos)
+static ssize_t xz_dec_test_write(struct kiocb *iocb, struct iov_iter *from)
{
+ size_t size = iov_iter_count(from);
size_t remaining;
if (ret != XZ_OK) {
@@ -122,10 +122,9 @@ static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
if (buffers.in_pos == buffers.in_size) {
buffers.in_pos = 0;
buffers.in_size = min(remaining, sizeof(buffer_in));
- if (copy_from_user(buffer_in, buf, buffers.in_size))
+ if (!copy_from_iter_full(buffer_in, buffers.in_size, from))
return -EFAULT;
- buf += buffers.in_size;
remaining -= buffers.in_size;
}
@@ -179,7 +178,7 @@ static int __init xz_dec_test_init(void)
.owner = THIS_MODULE,
.open = &xz_dec_test_open,
.release = &xz_dec_test_release,
- .write = &xz_dec_test_write
+ .write_iter = &xz_dec_test_write
};
state = xz_dec_init(XZ_PREALLOC, DICT_MAX);
--
2.43.0
Powered by blists - more mailing lists