[PATCH 012/437] char/adi: convert to read/write iterators

Jens Axboe
2024-04-11T15:31:50Z

drivers/char/adi.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/char/adi.c b/drivers/char/adi.c
index 751d7cc0da1b..941188be2385 100644
--- a/drivers/char/adi.c
+++ b/drivers/char/adi.c
@@ -51,10 +51,10 @@ static int read_mcd_tag(unsigned long addr)
return ver;
}

-static ssize_t adi_read(struct file *file, char __user *buf,
- size_t count, loff_t *offp)
+static ssize_t adi_read(struct kiocb *iocb, struct iov_iter *to)
{
size_t ver_buf_sz, bytes_read = 0;
+ size_t count = iov_iter_count(to);
int ver_buf_idx = 0;
loff_t offset;
u8 *ver_buf;
@@ -65,7 +65,7 @@ static ssize_t adi_read(struct file *file, char __user *buf,
if (!ver_buf)
return -ENOMEM;

- offset = (*offp) * adi_blksize();
+ offset = iocb->ki_pos * adi_blksize();

while (bytes_read < count) {
ret = read_mcd_tag(offset);
@@ -77,8 +77,7 @@ static ssize_t adi_read(struct file *file, char __user *buf,
offset += adi_blksize();

if (ver_buf_idx >= ver_buf_sz) {
- if (copy_to_user(buf + bytes_read, ver_buf,
- ver_buf_sz)) {
+ if (!copy_to_iter_full(ver_buf, ver_buf_sz, to)) {
ret = -EFAULT;
goto out;
}
@@ -91,7 +90,7 @@ static ssize_t adi_read(struct file *file, char __user *buf,
}
}

- (*offp) += bytes_read;
+ iocb->ki_pos += bytes_read;
ret = bytes_read;
out:
kfree(ver_buf);
@@ -128,10 +127,10 @@ static int set_mcd_tag(unsigned long addr, u8 ver)
return ver;
}

-static ssize_t adi_write(struct file *file, const char __user *buf,
- size_t count, loff_t *offp)
+static ssize_t adi_write(struct kiocb *iocb, struct iov_iter *from)
{
size_t ver_buf_sz, bytes_written = 0;
+ size_t count = iov_iter_count(from);
loff_t offset;
u8 *ver_buf;
ssize_t ret;
@@ -145,11 +144,10 @@ static ssize_t adi_write(struct file *file, const char __user *buf,
if (!ver_buf)
return -ENOMEM;

- offset = (*offp) * adi_blksize();
+ offset = iocb->ki_pos * adi_blksize();

do {
- if (copy_from_user(ver_buf, &buf[bytes_written],
- ver_buf_sz)) {
+ if (!copy_from_iter_full(ver_buf, ver_buf_sz, from)) {
ret = -EFAULT;
goto out;
}
@@ -166,7 +164,7 @@ static ssize_t adi_write(struct file *file, const char __user *buf,
ver_buf_sz = min(count - bytes_written, (size_t)MAX_BUF_SZ);
} while (bytes_written < count);

- (*offp) += bytes_written;
+ iocb->ki_pos += bytes_written;
ret = bytes_written;
out:
__asm__ __volatile__("membar #Sync");
@@ -207,8 +205,8 @@ static const struct file_operations adi_fops = {
.owner = THIS_MODULE,
.llseek = adi_llseek,
.open = adi_open,
- .read = adi_read,
- .write = adi_write,
+ .read_iter = adi_read,
+ .write_iter = adi_write,
};

static struct miscdevice adi_miscdev = {
--
2.43.0