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

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/usb/gadget/function/f_fs.c      |  6 ++++--
 drivers/usb/gadget/function/f_hid.c     | 17 ++++++++--------
 drivers/usb/gadget/function/f_printer.c | 26 ++++++++++++-------------
 drivers/usb/gadget/legacy/inode.c       |  6 ++++--
 drivers/usb/gadget/udc/renesas_usb3.c   | 14 ++++++-------
 5 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index bffbc1dc651f..e3514d295e55 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -495,6 +495,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
 	mutex_unlock(&ffs->mutex);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(ffs_ep0_write);
 
 /* Called with ffs->ev.waitq.lock and ffs->mutex held, both released on exit. */
 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
@@ -632,6 +633,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
 	kfree(data);
 	return ret;
 }
+FOPS_READ_ITER_HELPER(ffs_ep0_read);
 
 static int ffs_ep0_open(struct inode *inode, struct file *file)
 {
@@ -720,8 +722,8 @@ static const struct file_operations ffs_ep0_operations = {
 	.llseek =	no_llseek,
 
 	.open =		ffs_ep0_open,
-	.write =	ffs_ep0_write,
-	.read =		ffs_ep0_read,
+	.write_iter =	ffs_ep0_write_iter,
+	.read_iter =	ffs_ep0_read_iter,
 	.release =	ffs_ep0_release,
 	.unlocked_ioctl =	ffs_ep0_ioctl,
 	.poll =		ffs_ep0_poll,
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c8a9dd585c0..13e5bab6e1b2 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -414,6 +414,7 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,
 	else
 		return f_hidg_ssreport_read(file, buffer, count, ptr);
 }
+FOPS_READ_ITER_HELPER(f_hidg_read);
 
 static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -431,10 +432,10 @@ static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
 	wake_up(&hidg->write_queue);
 }
 
-static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
-			    size_t count, loff_t *offp)
+static ssize_t f_hidg_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct f_hidg *hidg  = file->private_data;
+	struct f_hidg *hidg  = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct usb_request *req;
 	unsigned long flags;
 	ssize_t status = -ENOMEM;
@@ -451,7 +452,7 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
 	/* write queue */
 	while (!WRITE_COND) {
 		spin_unlock_irqrestore(&hidg->write_spinlock, flags);
-		if (file->f_flags & O_NONBLOCK)
+		if (iocb->ki_filp->f_flags & O_NONBLOCK)
 			return -EAGAIN;
 
 		if (wait_event_interruptible_exclusive(
@@ -473,8 +474,8 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
 		goto release_write_pending;
 	}
 
-	status = copy_from_user(req->buf, buffer, count);
-	if (status != 0) {
+	status = copy_from_iter_full(req->buf, count, from);
+	if (!status) {
 		ERROR(hidg->func.config->cdev,
 			"copy_from_user error\n");
 		status = -EINVAL;
@@ -906,8 +907,8 @@ static const struct file_operations f_hidg_fops = {
 	.owner		= THIS_MODULE,
 	.open		= f_hidg_open,
 	.release	= f_hidg_release,
-	.write		= f_hidg_write,
-	.read		= f_hidg_read,
+	.write_iter	= f_hidg_write,
+	.read_iter	= f_hidg_read_iter,
 	.poll		= f_hidg_poll,
 	.llseek		= noop_llseek,
 };
diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 076dd4c1be96..de3863f0bfb6 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -426,10 +426,10 @@ setup_rx_reqs(struct printer_dev *dev)
 	}
 }
 
-static ssize_t
-printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
+static ssize_t printer_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct printer_dev		*dev = fd->private_data;
+	struct printer_dev		*dev = iocb->ki_filp->private_data;
+	size_t				len = iov_iter_count(to);
 	unsigned long			flags;
 	size_t				size;
 	size_t				bytes_copied;
@@ -485,7 +485,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 		 * If no data is available check if this is a NON-Blocking
 		 * call or not.
 		 */
-		if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
+		if (iocb->ki_filp->f_flags & (O_NONBLOCK|O_NDELAY)) {
 			mutex_unlock(&dev->lock_printer_io);
 			return -EAGAIN;
 		}
@@ -522,10 +522,9 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 		else
 			size = len;
 
-		size -= copy_to_user(buf, current_rx_buf, size);
+		size -= copy_to_iter(current_rx_buf, size, to);
 		bytes_copied += size;
 		len -= size;
-		buf += size;
 
 		spin_lock_irqsave(&dev->lock, flags);
 
@@ -568,10 +567,10 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 		return -EAGAIN;
 }
 
-static ssize_t
-printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
+static ssize_t printer_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct printer_dev	*dev = fd->private_data;
+	struct printer_dev	*dev = iocb->ki_filp->private_data;
+	size_t			len = iov_iter_count(from);
 	unsigned long		flags;
 	size_t			size;	/* Amount of data in a TX request. */
 	size_t			bytes_copied = 0;
@@ -604,7 +603,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 		 * If write buffers are available check if this is
 		 * a NON-Blocking call or not.
 		 */
-		if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
+		if (iocb->ki_filp->f_flags & (O_NONBLOCK|O_NDELAY)) {
 			mutex_unlock(&dev->lock_printer_io);
 			return -EAGAIN;
 		}
@@ -642,7 +641,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 		/* Don't leave irqs off while doing memory copies */
 		spin_unlock_irqrestore(&dev->lock, flags);
 
-		if (copy_from_user(req->buf, buf, size)) {
+		if (!copy_from_iter_full(req->buf, size, from)) {
 			list_add(&req->list, &dev->tx_reqs);
 			mutex_unlock(&dev->lock_printer_io);
 			return bytes_copied;
@@ -650,7 +649,6 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 
 		bytes_copied += size;
 		len -= size;
-		buf += size;
 
 		spin_lock_irqsave(&dev->lock, flags);
 
@@ -794,8 +792,8 @@ printer_ioctl(struct file *fd, unsigned int code, unsigned long arg)
 static const struct file_operations printer_io_operations = {
 	.owner =	THIS_MODULE,
 	.open =		printer_open,
-	.read =		printer_read,
-	.write =	printer_write,
+	.read_iter =	printer_read,
+	.write_iter =	printer_write,
 	.fsync =	printer_fsync,
 	.poll =		printer_poll,
 	.unlocked_ioctl = printer_ioctl,
diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index 03179b1880fd..2898840a7a41 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1080,6 +1080,7 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 	spin_unlock_irq (&dev->lock);
 	return retval;
 }
+FOPS_READ_ITER_HELPER(ep0_read);
 
 static struct usb_gadgetfs_event *
 next_event (struct dev_data *dev, enum usb_gadgetfs_event_type type)
@@ -1919,6 +1920,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 	dev->buf = NULL;
 	return value;
 }
+FOPS_WRITE_ITER_HELPER(dev_config);
 
 static int
 gadget_dev_open (struct inode *inode, struct file *fd)
@@ -1942,8 +1944,8 @@ static const struct file_operations ep0_operations = {
 	.llseek =	no_llseek,
 
 	.open =		gadget_dev_open,
-	.read =		ep0_read,
-	.write =	dev_config,
+	.read_iter =	ep0_read_iter,
+	.write_iter =	dev_config_iter,
 	.fasync =	ep0_fasync,
 	.poll =		ep0_poll,
 	.unlocked_ioctl = gadget_dev_ioctl,
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
index 3b01734ce1b7..61f5d7ac47ee 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2603,18 +2603,18 @@ static int renesas_usb3_b_device_open(struct inode *inode, struct file *file)
 	return single_open(file, renesas_usb3_b_device_show, inode->i_private);
 }
 
-static ssize_t renesas_usb3_b_device_write(struct file *file,
-					   const char __user *ubuf,
-					   size_t count, loff_t *ppos)
+static ssize_t renesas_usb3_b_device_write(struct kiocb *iocb,
+					   struct iov_iter *from)
 {
-	struct seq_file *s = file->private_data;
+	struct seq_file *s = iocb->ki_filp->private_data;
 	struct renesas_usb3 *usb3 = s->private;
+	size_t count = iov_iter_count(from);
 	char buf[32];
 
 	if (!usb3->driver)
 		return -ENODEV;
 
-	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;
 
 	usb3->start_to_connect = false;
@@ -2637,8 +2637,8 @@ static ssize_t renesas_usb3_b_device_write(struct file *file,
 
 static const struct file_operations renesas_usb3_b_device_fops = {
 	.open = renesas_usb3_b_device_open,
-	.write = renesas_usb3_b_device_write,
-	.read = seq_read,
+	.write_iter = renesas_usb3_b_device_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ