[PATCH 026/437] char/nvram: convert to read/write iterators

Jens Axboe
2024-04-11T15:32:14Z

drivers/char/nvram.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index e9f694b36871..911370aa2a1a 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -225,29 +225,29 @@ static loff_t nvram_misc_llseek(struct file *file, loff_t offset, int origin)
nvram_size);
}

-static ssize_t nvram_misc_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t nvram_misc_read(struct kiocb *iocb, struct iov_iter *to)
{
+ size_t count = iov_iter_count(to);
char *tmp;
ssize_t ret;

- if (*ppos >= nvram_size)
+ if (iocb->ki_pos >= nvram_size)
return 0;

- count = min_t(size_t, count, nvram_size - *ppos);
+ count = min_t(size_t, count, nvram_size - iocb->ki_pos);
count = min_t(size_t, count, PAGE_SIZE);

tmp = kmalloc(count, GFP_KERNEL);
if (!tmp)
return -ENOMEM;

- ret = nvram_read(tmp, count, ppos);
+ ret = nvram_read(tmp, count, &iocb->ki_pos);
if (ret <= 0)
goto out;

- if (copy_to_user(buf, tmp, ret)) {
- *ppos -= ret;
+ if (!copy_to_iter_full(tmp, ret, to)) {
+ iocb->ki_pos -= ret;
ret = -EFAULT;
}

@@ -276,6 +276,7 @@ static ssize_t nvram_misc_write(struct file *file, const char __user *buf,
kfree(tmp);
return ret;
}
+FOPS_WRITE_ITER_HELPER(nvram_misc_write);

static long nvram_misc_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
@@ -490,8 +491,8 @@ static int nvram_proc_read(struct seq_file *seq, void *offset)
static const struct file_operations nvram_misc_fops = {
.owner = THIS_MODULE,
.llseek = nvram_misc_llseek,
- .read = nvram_misc_read,
- .write = nvram_misc_write,
+ .read_iter = nvram_misc_read,
+ .write_iter = nvram_misc_write_iter,
.unlocked_ioctl = nvram_misc_ioctl,
.open = nvram_misc_open,
.release = nvram_misc_release,
--
2.43.0