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

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/staging/axis-fifo/axis-fifo.c | 22 ++++++++++------------
 drivers/staging/pi433/pi433_if.c      | 13 +++++++------
 drivers/staging/vme_user/vme_user.c   |  6 ++++--
 3 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index c51818c56dd2..ba8e08be0daf 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -345,10 +345,10 @@ static void reset_ip_core(struct axis_fifo *fifo)
  * Returns the number of bytes read from the device or negative error code
  *	on failure.
  */
-static ssize_t axis_fifo_read(struct file *f, char __user *buf,
-			      size_t len, loff_t *off)
+static ssize_t axis_fifo_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct axis_fifo *fifo = (struct axis_fifo *)f->private_data;
+	struct axis_fifo *fifo = iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(to);
 	size_t bytes_available;
 	unsigned int words_available;
 	unsigned int copied;
@@ -431,8 +431,7 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
 					      XLLF_RDFD_OFFSET);
 		}
 
-		if (copy_to_user(buf + copied * sizeof(u32), tmp_buf,
-				 copy * sizeof(u32))) {
+		if (!copy_to_iter_full(tmp_buf, copy * sizeof(u32), to)) {
 			reset_ip_core(fifo);
 			ret = -EFAULT;
 			goto end_unlock;
@@ -465,10 +464,10 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
  * Returns the number of bytes written to the device or negative error code
  *	on failure.
  */
-static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
-			       size_t len, loff_t *off)
+static ssize_t axis_fifo_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct axis_fifo *fifo = (struct axis_fifo *)f->private_data;
+	struct axis_fifo *fifo = iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(from);
 	unsigned int words_to_write;
 	unsigned int copied;
 	unsigned int copy;
@@ -540,8 +539,7 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
 	while (words_to_write > 0) {
 		copy = min(words_to_write, WRITE_BUF_SIZE);
 
-		if (copy_from_user(tmp_buf, buf + copied * sizeof(u32),
-				   copy * sizeof(u32))) {
+		if (!copy_from_iter_full(tmp_buf, copy * sizeof(u32), from)) {
 			reset_ip_core(fifo);
 			ret = -EFAULT;
 			goto end_unlock;
@@ -712,8 +710,8 @@ static const struct file_operations fops = {
 	.owner = THIS_MODULE,
 	.open = axis_fifo_open,
 	.release = axis_fifo_close,
-	.read = axis_fifo_read,
-	.write = axis_fifo_write
+	.read_iter = axis_fifo_read,
+	.write_iter = axis_fifo_write,
 };
 
 /* read named property from the device tree */
diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index b6c4917d515e..f6563e3a7603 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -765,11 +765,11 @@ static int pi433_tx_thread(void *data)
 
 /*-------------------------------------------------------------------------*/
 
-static ssize_t
-pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
+static ssize_t pi433_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct pi433_instance	*instance;
 	struct pi433_device	*device;
+	size_t			size = iov_iter_count(to);
 	int			bytes_received;
 	ssize_t			retval;
 
@@ -777,7 +777,7 @@ pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
 	if (size > MAX_MSG_SIZE)
 		return -EMSGSIZE;
 
-	instance = filp->private_data;
+	instance = iocb->ki_filp->private_data;
 	device = instance->device;
 
 	/* just one read request at a time */
@@ -802,7 +802,7 @@ pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
 
 	/* if read was successful copy to user space*/
 	if (bytes_received > 0) {
-		retval = copy_to_user(buf, device->rx_buffer, bytes_received);
+		retval = !copy_to_iter_full(device->rx_buffer, bytes_received, to);
 		if (retval)
 			return -EFAULT;
 	}
@@ -883,6 +883,7 @@ pi433_write(struct file *filp, const char __user *buf,
 	mutex_unlock(&device->tx_fifo_lock);
 	return -EAGAIN;
 }
+FOPS_WRITE_ITER_HELPER(pi433_write);
 
 static long pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
@@ -1094,8 +1095,8 @@ static const struct file_operations pi433_fops = {
 	 * gets more complete API coverage.  It'll simplify things
 	 * too, except for the locking.
 	 */
-	.write =	pi433_write,
-	.read =		pi433_read,
+	.write_iter =	pi433_write_iter,
+	.read_iter =	pi433_read,
 	.unlocked_ioctl = pi433_ioctl,
 	.compat_ioctl = compat_ptr_ioctl,
 	.open =		pi433_open,
diff --git a/drivers/staging/vme_user/vme_user.c b/drivers/staging/vme_user/vme_user.c
index 36183f923768..4ca38d0af25a 100644
--- a/drivers/staging/vme_user/vme_user.c
+++ b/drivers/staging/vme_user/vme_user.c
@@ -216,6 +216,7 @@ static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
 
 	return retval;
 }
+FOPS_READ_ITER_HELPER(vme_user_read);
 
 static ssize_t vme_user_write(struct file *file, const char __user *buf,
 			      size_t count, loff_t *ppos)
@@ -259,6 +260,7 @@ static ssize_t vme_user_write(struct file *file, const char __user *buf,
 
 	return retval;
 }
+FOPS_WRITE_ITER_HELPER(vme_user_write);
 
 static loff_t vme_user_llseek(struct file *file, loff_t off, int whence)
 {
@@ -492,8 +494,8 @@ static int vme_user_mmap(struct file *file, struct vm_area_struct *vma)
 }
 
 static const struct file_operations vme_user_fops = {
-	.read = vme_user_read,
-	.write = vme_user_write,
+	.read_iter = vme_user_read_iter,
+	.write_iter = vme_user_write_iter,
 	.llseek = vme_user_llseek,
 	.unlocked_ioctl = vme_user_unlocked_ioctl,
 	.compat_ioctl = compat_ptr_ioctl,
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ