[PATCH 157/437] usb: class: convert to read/write iterators

Jens Axboe
2024-04-11T15:36:07Z

drivers/usb/class/cdc-wdm.c | 18 +++++++++---------
drivers/usb/class/usblp.c | 6 ++++--
drivers/usb/class/usbtmc.c | 6 ++++--
3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index c8262e2f2917..a811000b5eb2 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -476,6 +476,7 @@ static ssize_t wdm_write
kfree(buf);
return rv;
}
+FOPS_WRITE_ITER_HELPER(wdm_write);

/*
* Submit the read urb if resp_count is non-zero.
@@ -520,13 +521,12 @@ static int service_outstanding_interrupt(struct wdm_device *desc)
return rv;
}

-static ssize_t wdm_read
-(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t wdm_read(struct kiocb *iocb, struct iov_iter *to)
{
int rv, cntr;
int i = 0;
- struct wdm_device *desc = file->private_data;
-
+ struct wdm_device *desc = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(to);

rv = mutex_lock_interruptible(&desc->rlock); /*concurrent reads */
if (rv < 0)
@@ -546,7 +546,7 @@ static ssize_t wdm_read
goto err;
}
i++;
- if (file->f_flags & O_NONBLOCK) {
+ if (iocb->ki_filp->f_flags & O_NONBLOCK) {
if (!test_bit(WDM_READ, &desc->flags)) {
rv = -EAGAIN;
goto err;
@@ -604,8 +604,8 @@ static ssize_t wdm_read

if (cntr > count)
cntr = count;
- rv = copy_to_user(buffer, desc->ubuf, cntr);
- if (rv > 0) {
+ rv = !copy_to_iter_full(desc->ubuf, cntr, to);
+ if (rv) {
rv = -EFAULT;
goto err;
}
@@ -810,8 +810,8 @@ static long wdm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

static const struct file_operations wdm_fops = {
.owner = THIS_MODULE,
- .read = wdm_read,
- .write = wdm_write,
+ .read_iter = wdm_read,
+ .write_iter = wdm_write_iter,
.fsync = wdm_fsync,
.open = wdm_open,
.flush = wdm_flush,
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 5a2e43331064..2f16b7916963 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -832,6 +832,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
raise_biglock:
return writecount ? writecount : rv;
}
+FOPS_WRITE_ITER_HELPER(usblp_write);

/*
* Notice that we fail to restart in a few cases: on EFAULT, on restart
@@ -885,6 +886,7 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
mutex_unlock(&usblp->mut);
return count;
}
+FOPS_READ_ITER_HELPER(usblp_read);

/*
* Wait for the write path to come idle.
@@ -1080,8 +1082,8 @@ static unsigned int usblp_quirks(__u16 vendor, __u16 product)

static const struct file_operations usblp_fops = {
.owner = THIS_MODULE,
- .read = usblp_read,
- .write = usblp_write,
+ .read_iter = usblp_read_iter,
+ .write_iter = usblp_write_iter,
.poll = usblp_poll,
.unlocked_ioctl = usblp_ioctl,
.compat_ioctl = usblp_ioctl,
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 311007b1d904..281eeb29cf7f 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -1506,6 +1506,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
kfree(buffer);
return retval;
}
+FOPS_READ_ITER_HELPER(usbtmc_read);

static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
size_t count, loff_t *f_pos)
@@ -1644,6 +1645,7 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
mutex_unlock(&data->io_mutex);
return retval;
}
+FOPS_WRITE_ITER_HELPER(usbtmc_write);

static int usbtmc_ioctl_clear(struct usbtmc_device_data *data)
{
@@ -2261,8 +2263,8 @@ static __poll_t usbtmc_poll(struct file *file, poll_table *wait)

static const struct file_operations fops = {
.owner = THIS_MODULE,
- .read = usbtmc_read,
- .write = usbtmc_write,
+ .read_iter = usbtmc_read_iter,
+ .write_iter = usbtmc_write_iter,
.open = usbtmc_open,
.release = usbtmc_release,
.flush = usbtmc_flush,
--
2.43.0