lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-134-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:14:33 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 133/437] drivers/bus: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/bus/mhi/host/debugfs.c | 38 +++++++++++++++++-----------------
 drivers/bus/moxtet.c           | 30 +++++++++++++--------------
 2 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/drivers/bus/mhi/host/debugfs.c b/drivers/bus/mhi/host/debugfs.c
index cfec7811dfbb..14d7a1132fca 100644
--- a/drivers/bus/mhi/host/debugfs.c
+++ b/drivers/bus/mhi/host/debugfs.c
@@ -245,17 +245,17 @@ static int mhi_debugfs_device_wake_show(struct seq_file *m, void *d)
 	return 0;
 }
 
-static ssize_t mhi_debugfs_device_wake_write(struct file *file,
-					     const char __user *ubuf,
-					     size_t count, loff_t *ppos)
+static ssize_t mhi_debugfs_device_wake_write(struct kiocb *iocb,
+					     struct iov_iter *from)
 {
-	struct seq_file	*m = file->private_data;
+	struct seq_file	*m = iocb->ki_filp->private_data;
 	struct mhi_controller *mhi_cntrl = m->private;
 	struct mhi_device *mhi_dev = mhi_cntrl->mhi_dev;
+	size_t count = iov_iter_count(from);
 	char buf[16];
 	int ret = -EINVAL;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (!strncmp(buf, "get", 3)) {
@@ -277,15 +277,15 @@ static int mhi_debugfs_timeout_ms_show(struct seq_file *m, void *d)
 	return 0;
 }
 
-static ssize_t mhi_debugfs_timeout_ms_write(struct file *file,
-					    const char __user *ubuf,
-					    size_t count, loff_t *ppos)
+static ssize_t mhi_debugfs_timeout_ms_write(struct kiocb *iocb,
+					    struct iov_iter *from)
 {
-	struct seq_file	*m = file->private_data;
+	struct seq_file	*m = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct mhi_controller *mhi_cntrl = m->private;
 	u32 timeout_ms;
 
-	if (kstrtou32_from_user(ubuf, count, 0, &timeout_ms))
+	if (kstrtou32_from_iter(from, count, 0, &timeout_ms))
 		return -EINVAL;
 
 	mhi_cntrl->timeout_ms = timeout_ms;
@@ -331,45 +331,45 @@ static int mhi_debugfs_timeout_ms_open(struct inode *inode, struct file *fp)
 static const struct file_operations debugfs_states_fops = {
 	.open = mhi_debugfs_states_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_events_fops = {
 	.open = mhi_debugfs_events_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_channels_fops = {
 	.open = mhi_debugfs_channels_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_devices_fops = {
 	.open = mhi_debugfs_devices_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_regdump_fops = {
 	.open = mhi_debugfs_regdump_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_device_wake_fops = {
 	.open = mhi_debugfs_device_wake_open,
-	.write = mhi_debugfs_device_wake_write,
+	.write_iter = mhi_debugfs_device_wake_write,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_timeout_ms_fops = {
 	.open = mhi_debugfs_timeout_ms_open,
-	.write = mhi_debugfs_timeout_ms_write,
+	.write_iter = mhi_debugfs_timeout_ms_write,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static struct dentry *mhi_debugfs_root;
diff --git a/drivers/bus/moxtet.c b/drivers/bus/moxtet.c
index 641c1a6adc8a..a6635cfc8490 100644
--- a/drivers/bus/moxtet.c
+++ b/drivers/bus/moxtet.c
@@ -15,6 +15,7 @@
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
 #include <linux/spi/spi.h>
+#include <linux/uio.h>
 
 /*
  * @name:	module name for sysfs
@@ -460,10 +461,9 @@ static int moxtet_debug_open(struct inode *inode, struct file *file)
 	return nonseekable_open(inode, file);
 }
 
-static ssize_t input_read(struct file *file, char __user *buf, size_t len,
-			  loff_t *ppos)
+static ssize_t input_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct moxtet *moxtet = file->private_data;
+	struct moxtet *moxtet = iocb->ki_filp->private_data;
 	u8 bin[TURRIS_MOX_MAX_MODULES];
 	u8 hex[sizeof(bin) * 2 + 1];
 	int ret, n;
@@ -477,20 +477,19 @@ static ssize_t input_read(struct file *file, char __user *buf, size_t len,
 
 	hex[2*n] = '\n';
 
-	return simple_read_from_buffer(buf, len, ppos, hex, 2*n + 1);
+	return simple_copy_to_iter(hex, &iocb->ki_pos, 2*n + 1, to);
 }
 
 static const struct file_operations input_fops = {
 	.owner	= THIS_MODULE,
 	.open	= moxtet_debug_open,
-	.read	= input_read,
+	.read_iter	= input_read,
 	.llseek	= no_llseek,
 };
 
-static ssize_t output_read(struct file *file, char __user *buf, size_t len,
-			   loff_t *ppos)
+static ssize_t output_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct moxtet *moxtet = file->private_data;
+	struct moxtet *moxtet = iocb->ki_filp->private_data;
 	u8 hex[TURRIS_MOX_MAX_MODULES * 2 + 1];
 	u8 *p = hex;
 	int i;
@@ -504,23 +503,22 @@ static ssize_t output_read(struct file *file, char __user *buf, size_t len,
 
 	*p++ = '\n';
 
-	return simple_read_from_buffer(buf, len, ppos, hex, p - hex);
+	return simple_copy_to_iter(hex, &iocb->ki_pos, p - hex, to);
 }
 
-static ssize_t output_write(struct file *file, const char __user *buf,
-			    size_t len, loff_t *ppos)
+static ssize_t output_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct moxtet *moxtet = file->private_data;
+	struct moxtet *moxtet = iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(from);
 	u8 bin[TURRIS_MOX_MAX_MODULES];
 	u8 hex[sizeof(bin) * 2 + 1];
 	ssize_t res;
-	loff_t dummy = 0;
 	int err, i;
 
 	if (len > 2 * moxtet->count + 1 || len < 2 * moxtet->count)
 		return -EINVAL;
 
-	res = simple_write_to_buffer(hex, sizeof(hex), &dummy, buf, len);
+	res = simple_copy_from_iter(hex, &iocb->ki_pos, sizeof(hex), from);
 	if (res < 0)
 		return res;
 
@@ -547,8 +545,8 @@ static ssize_t output_write(struct file *file, const char __user *buf,
 static const struct file_operations output_fops = {
 	.owner	= THIS_MODULE,
 	.open	= moxtet_debug_open,
-	.read	= output_read,
-	.write	= output_write,
+	.read_iter	= output_read,
+	.write_iter	= output_write,
 	.llseek	= no_llseek,
 };
 
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ