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-203-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:15:42 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 202/437] staging: greybus: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/greybus/es2.c            | 29 ++++++++++++++---------------
 drivers/greybus/svc.c            | 27 ++++++++++++---------------
 drivers/staging/greybus/camera.c | 22 ++++++++++------------
 drivers/staging/greybus/raw.c    |  6 ++++--
 4 files changed, 40 insertions(+), 44 deletions(-)

diff --git a/drivers/greybus/es2.c b/drivers/greybus/es2.c
index 1ee78d0d90b4..ef9c68ef8632 100644
--- a/drivers/greybus/es2.c
+++ b/drivers/greybus/es2.c
@@ -1109,10 +1109,10 @@ static int apb_log_poll(void *data)
 	return 0;
 }
 
-static ssize_t apb_log_read(struct file *f, char __user *buf,
-			    size_t count, loff_t *ppos)
+static ssize_t apb_log_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct es2_ap_dev *es2 = file_inode(f)->i_private;
+	struct es2_ap_dev *es2 = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(to);
 	ssize_t ret;
 	size_t copied;
 	char *tmp_buf;
@@ -1125,7 +1125,7 @@ static ssize_t apb_log_read(struct file *f, char __user *buf,
 		return -ENOMEM;
 
 	copied = kfifo_out(&es2->apb_log_fifo, tmp_buf, count);
-	ret = simple_read_from_buffer(buf, count, ppos, tmp_buf, copied);
+	ret = simple_copy_to_iter(tmp_buf, &iocb->ki_pos, copied, to);
 
 	kfree(tmp_buf);
 
@@ -1133,7 +1133,7 @@ static ssize_t apb_log_read(struct file *f, char __user *buf,
 }
 
 static const struct file_operations apb_log_fops = {
-	.read	= apb_log_read,
+	.read_iter	= apb_log_read,
 };
 
 static void usb_log_enable(struct es2_ap_dev *es2)
@@ -1163,25 +1163,24 @@ static void usb_log_disable(struct es2_ap_dev *es2)
 	es2->apb_log_task = NULL;
 }
 
-static ssize_t apb_log_enable_read(struct file *f, char __user *buf,
-				   size_t count, loff_t *ppos)
+static ssize_t apb_log_enable_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct es2_ap_dev *es2 = file_inode(f)->i_private;
+	struct es2_ap_dev *es2 = file_inode(iocb->ki_filp)->i_private;
 	int enable = !IS_ERR_OR_NULL(es2->apb_log_task);
 	char tmp_buf[3];
 
 	sprintf(tmp_buf, "%d\n", enable);
-	return simple_read_from_buffer(buf, count, ppos, tmp_buf, 2);
+	return simple_copy_to_iter(tmp_buf, &iocb->ki_pos, 2, to);
 }
 
-static ssize_t apb_log_enable_write(struct file *f, const char __user *buf,
-				    size_t count, loff_t *ppos)
+static ssize_t apb_log_enable_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	int enable;
 	ssize_t retval;
-	struct es2_ap_dev *es2 = file_inode(f)->i_private;
+	struct es2_ap_dev *es2 = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 
-	retval = kstrtoint_from_user(buf, count, 10, &enable);
+	retval = kstrtoint_from_iter(from, count, 10, &enable);
 	if (retval)
 		return retval;
 
@@ -1194,8 +1193,8 @@ static ssize_t apb_log_enable_write(struct file *f, const char __user *buf,
 }
 
 static const struct file_operations apb_log_enable_fops = {
-	.read	= apb_log_enable_read,
-	.write	= apb_log_enable_write,
+	.read_iter	= apb_log_enable_read,
+	.write_iter	= apb_log_enable_write,
 };
 
 static int apb_get_cport_count(struct usb_device *udev)
diff --git a/drivers/greybus/svc.c b/drivers/greybus/svc.c
index 4256467fcd35..989ee7a3ac17 100644
--- a/drivers/greybus/svc.c
+++ b/drivers/greybus/svc.c
@@ -673,11 +673,10 @@ static int gb_svc_version_request(struct gb_operation *op)
 	return 0;
 }
 
-static ssize_t pwr_debugfs_voltage_read(struct file *file, char __user *buf,
-					size_t len, loff_t *offset)
+static ssize_t pwr_debugfs_voltage_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct svc_debugfs_pwrmon_rail *pwrmon_rails =
-		file_inode(file)->i_private;
+		file_inode(iocb->ki_filp)->i_private;
 	struct gb_svc *svc = pwrmon_rails->svc;
 	int ret, desc;
 	u32 value;
@@ -694,14 +693,13 @@ static ssize_t pwr_debugfs_voltage_read(struct file *file, char __user *buf,
 
 	desc = scnprintf(buff, sizeof(buff), "%u\n", value);
 
-	return simple_read_from_buffer(buf, len, offset, buff, desc);
+	return simple_copy_to_iter(buff, &iocb->ki_pos, desc, to);
 }
 
-static ssize_t pwr_debugfs_current_read(struct file *file, char __user *buf,
-					size_t len, loff_t *offset)
+static ssize_t pwr_debugfs_current_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct svc_debugfs_pwrmon_rail *pwrmon_rails =
-		file_inode(file)->i_private;
+		file_inode(iocb->ki_filp)->i_private;
 	struct gb_svc *svc = pwrmon_rails->svc;
 	int ret, desc;
 	u32 value;
@@ -718,14 +716,13 @@ static ssize_t pwr_debugfs_current_read(struct file *file, char __user *buf,
 
 	desc = scnprintf(buff, sizeof(buff), "%u\n", value);
 
-	return simple_read_from_buffer(buf, len, offset, buff, desc);
+	return simple_copy_to_iter(buff, &iocb->ki_pos, desc, to);
 }
 
-static ssize_t pwr_debugfs_power_read(struct file *file, char __user *buf,
-				      size_t len, loff_t *offset)
+static ssize_t pwr_debugfs_power_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct svc_debugfs_pwrmon_rail *pwrmon_rails =
-		file_inode(file)->i_private;
+		file_inode(iocb->ki_filp)->i_private;
 	struct gb_svc *svc = pwrmon_rails->svc;
 	int ret, desc;
 	u32 value;
@@ -741,19 +738,19 @@ static ssize_t pwr_debugfs_power_read(struct file *file, char __user *buf,
 
 	desc = scnprintf(buff, sizeof(buff), "%u\n", value);
 
-	return simple_read_from_buffer(buf, len, offset, buff, desc);
+	return simple_copy_to_iter(buff, &iocb->ki_pos, desc, to);
 }
 
 static const struct file_operations pwrmon_debugfs_voltage_fops = {
-	.read		= pwr_debugfs_voltage_read,
+	.read_iter	= pwr_debugfs_voltage_read,
 };
 
 static const struct file_operations pwrmon_debugfs_current_fops = {
-	.read		= pwr_debugfs_current_read,
+	.read_iter	= pwr_debugfs_current_read,
 };
 
 static const struct file_operations pwrmon_debugfs_power_fops = {
-	.read		= pwr_debugfs_power_read,
+	.read_iter	= pwr_debugfs_power_read,
 };
 
 static void gb_svc_pwrmon_debugfs_init(struct gb_svc *svc)
diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c
index a8173aa3a995..f18f690a31ee 100644
--- a/drivers/staging/greybus/camera.c
+++ b/drivers/staging/greybus/camera.c
@@ -1086,10 +1086,9 @@ static const struct gb_camera_debugfs_entry gb_camera_debugfs_entries[] = {
 	},
 };
 
-static ssize_t gb_camera_debugfs_read(struct file *file, char __user *buf,
-				      size_t len, loff_t *offset)
+static ssize_t gb_camera_debugfs_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	const struct gb_camera_debugfs_entry *op = file->private_data;
+	const struct gb_camera_debugfs_entry *op = iocb->ki_filp->private_data;
 	struct gb_camera *gcam = file_inode(file)->i_private;
 	struct gb_camera_debugfs_buffer *buffer;
 	ssize_t ret;
@@ -1103,23 +1102,22 @@ static ssize_t gb_camera_debugfs_read(struct file *file, char __user *buf,
 
 	buffer = &gcam->debugfs.buffers[op->buffer];
 
-	return simple_read_from_buffer(buf, len, offset, buffer->data,
-				       buffer->length);
+	return simple_copy_to_iter(buffer->data, &iocb->ki_pos, buffer->length,
+					to);
 }
 
-static ssize_t gb_camera_debugfs_write(struct file *file,
-				       const char __user *buf, size_t len,
-				       loff_t *offset)
+static ssize_t gb_camera_debugfs_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	const struct gb_camera_debugfs_entry *op = file->private_data;
+	const struct gb_camera_debugfs_entry *op = iocb->ki_filp->private_data;
 	struct gb_camera *gcam = file_inode(file)->i_private;
+	size_t len = iov_iter_count(from);
 	ssize_t ret;
 	char *kbuf;
 
 	if (len > 1024)
 		return -EINVAL;
 
-	kbuf = memdup_user_nul(buf, len);
+	kbuf = iterdup_nul(buf, len);
 	if (IS_ERR(kbuf))
 		return PTR_ERR(kbuf);
 
@@ -1149,8 +1147,8 @@ static int gb_camera_debugfs_open(struct inode *inode, struct file *file)
 
 static const struct file_operations gb_camera_debugfs_ops = {
 	.open = gb_camera_debugfs_open,
-	.read = gb_camera_debugfs_read,
-	.write = gb_camera_debugfs_write,
+	.read_iter = gb_camera_debugfs_read,
+	.write_iter = gb_camera_debugfs_write,
 };
 
 static int gb_camera_debugfs_init(struct gb_camera *gcam)
diff --git a/drivers/staging/greybus/raw.c b/drivers/staging/greybus/raw.c
index 836d35e5fa85..44b85032b755 100644
--- a/drivers/staging/greybus/raw.c
+++ b/drivers/staging/greybus/raw.c
@@ -284,6 +284,7 @@ static ssize_t raw_write(struct file *file, const char __user *buf,
 
 	return count;
 }
+FOPS_WRITE_ITER_HELPER(raw_write);
 
 static ssize_t raw_read(struct file *file, char __user *buf, size_t count,
 			loff_t *ppos)
@@ -316,11 +317,12 @@ static ssize_t raw_read(struct file *file, char __user *buf, size_t count,
 	mutex_unlock(&raw->list_lock);
 	return retval;
 }
+FOPS_READ_ITER_HELPER(raw_read);
 
 static const struct file_operations raw_fops = {
 	.owner		= THIS_MODULE,
-	.write		= raw_write,
-	.read		= raw_read,
+	.write_iter	= raw_write_iter,
+	.read_iter	= raw_read_iter,
 	.open		= raw_open,
 	.llseek		= noop_llseek,
 };
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ