[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-112-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:14:11 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 111/437] drivers/gpio: convert to ->read_iter and ->write_iter
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
drivers/gpio/gpio-mockup.c | 26 +++++++++++------------
drivers/gpio/gpiolib-cdev.c | 41 ++++++++++++++++++-------------------
2 files changed, 32 insertions(+), 35 deletions(-)
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 455eecf6380e..34fc0f921284 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -265,9 +265,7 @@ static void gpio_mockup_free(struct gpio_chip *gc, unsigned int offset)
__gpio_mockup_set(chip, offset, chip->lines[offset].pull);
}
-static ssize_t gpio_mockup_debugfs_read(struct file *file,
- char __user *usr_buf,
- size_t size, loff_t *ppos)
+static ssize_t gpio_mockup_debugfs_read(struct kiocb *iocb, struct iov_iter *to)
{
struct gpio_mockup_dbgfs_private *priv;
struct gpio_mockup_chip *chip;
@@ -276,10 +274,10 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
int val, cnt;
char buf[3];
- if (*ppos != 0)
+ if (iocb->ki_pos != 0)
return 0;
- sfile = file->private_data;
+ sfile = iocb->ki_filp->private_data;
priv = sfile->private;
chip = priv->chip;
gc = &chip->gc;
@@ -287,27 +285,27 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
val = gpio_mockup_get(gc, priv->offset);
cnt = snprintf(buf, sizeof(buf), "%d\n", val);
- return simple_read_from_buffer(usr_buf, size, ppos, buf, cnt);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, cnt, to);
}
-static ssize_t gpio_mockup_debugfs_write(struct file *file,
- const char __user *usr_buf,
- size_t size, loff_t *ppos)
+static ssize_t gpio_mockup_debugfs_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
struct gpio_mockup_dbgfs_private *priv;
+ size_t size = iov_iter_count(from);
int rv, val;
struct seq_file *sfile;
- if (*ppos != 0)
+ if (iocb->ki_pos != 0)
return -EINVAL;
- rv = kstrtoint_from_user(usr_buf, size, 0, &val);
+ rv = kstrtoint_from_iter(from, size, 0, &val);
if (rv)
return rv;
if (val != 0 && val != 1)
return -EINVAL;
- sfile = file->private_data;
+ sfile = iocb->ki_filp->private_data;
priv = sfile->private;
rv = gpio_mockup_apply_pull(priv->chip, priv->offset, val);
if (rv)
@@ -345,8 +343,8 @@ static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file)
static const struct file_operations gpio_mockup_debugfs_ops = {
.owner = THIS_MODULE,
.open = gpio_mockup_debugfs_open,
- .read = gpio_mockup_debugfs_read,
- .write = gpio_mockup_debugfs_write,
+ .read_iter = gpio_mockup_debugfs_read,
+ .write_iter = gpio_mockup_debugfs_write,
.llseek = no_llseek,
.release = single_release,
};
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index d09c7d728365..25e054a42bb1 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1597,10 +1597,10 @@ static __poll_t linereq_poll(struct file *file,
return events;
}
-static ssize_t linereq_read(struct file *file, char __user *buf,
- size_t count, loff_t *f_ps)
+static ssize_t linereq_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct linereq *lr = file->private_data;
+ struct linereq *lr = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(to);
struct gpio_v2_line_event le;
ssize_t bytes_read = 0;
int ret;
@@ -1619,7 +1619,7 @@ static ssize_t linereq_read(struct file *file, char __user *buf,
if (bytes_read)
return bytes_read;
- if (file->f_flags & O_NONBLOCK)
+ if (iocb->ki_filp->f_flags & O_NONBLOCK)
return -EAGAIN;
ret = wait_event_interruptible_locked(lr->wait,
@@ -1640,7 +1640,7 @@ static ssize_t linereq_read(struct file *file, char __user *buf,
break;
}
- if (copy_to_user(buf + bytes_read, &le, sizeof(le)))
+ if (!copy_to_iter_full(&le, sizeof(le), to))
return -EFAULT;
bytes_read += sizeof(le);
} while (count >= bytes_read + sizeof(le));
@@ -1698,7 +1698,7 @@ static void linereq_show_fdinfo(struct seq_file *out, struct file *file)
static const struct file_operations line_fileops = {
.release = linereq_release,
- .read = linereq_read,
+ .read_iter = linereq_read,
.poll = linereq_poll,
.owner = THIS_MODULE,
.llseek = noop_llseek,
@@ -1935,10 +1935,10 @@ struct compat_gpioeevent_data {
u32 id;
};
-static ssize_t lineevent_read(struct file *file, char __user *buf,
- size_t count, loff_t *f_ps)
+static ssize_t lineevent_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct lineevent_state *le = file->private_data;
+ struct lineevent_state *le = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(to);
struct gpioevent_data ge;
ssize_t bytes_read = 0;
ssize_t ge_size;
@@ -1971,7 +1971,7 @@ static ssize_t lineevent_read(struct file *file, char __user *buf,
if (bytes_read)
return bytes_read;
- if (file->f_flags & O_NONBLOCK)
+ if (iocb->ki_filp->f_flags & O_NONBLOCK)
return -EAGAIN;
ret = wait_event_interruptible_locked(le->wait,
@@ -1992,7 +1992,7 @@ static ssize_t lineevent_read(struct file *file, char __user *buf,
break;
}
- if (copy_to_user(buf + bytes_read, &ge, ge_size))
+ if (!copy_to_iter_full(&ge, ge_size, to))
return -EFAULT;
bytes_read += ge_size;
} while (count >= bytes_read + ge_size);
@@ -2064,7 +2064,7 @@ static long lineevent_ioctl_compat(struct file *file, unsigned int cmd,
static const struct file_operations lineevent_fileops = {
.release = lineevent_release,
- .read = lineevent_read,
+ .read_iter = lineevent_read,
.poll = lineevent_poll,
.owner = THIS_MODULE,
.llseek = noop_llseek,
@@ -2649,11 +2649,11 @@ static __poll_t lineinfo_watch_poll(struct file *file,
return events;
}
-static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
- size_t count, loff_t *off)
+static ssize_t lineinfo_watch_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct gpio_chardev_data *cdev = file->private_data;
+ struct gpio_chardev_data *cdev = iocb->ki_filp->private_data;
struct gpio_v2_line_info_changed event;
+ size_t count = iov_iter_count(to);
ssize_t bytes_read = 0;
int ret;
size_t event_size;
@@ -2675,7 +2675,7 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
if (bytes_read)
return bytes_read;
- if (file->f_flags & O_NONBLOCK)
+ if (iocb->ki_filp->f_flags & O_NONBLOCK)
return -EAGAIN;
ret = wait_event_interruptible_locked(cdev->wait,
@@ -2702,18 +2702,17 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
#ifdef CONFIG_GPIO_CDEV_V1
if (event_size == sizeof(struct gpio_v2_line_info_changed)) {
- if (copy_to_user(buf + bytes_read, &event, event_size))
+ if (!copy_to_iter_full(&event, event_size, to))
return -EFAULT;
} else {
struct gpioline_info_changed event_v1;
gpio_v2_line_info_changed_to_v1(&event, &event_v1);
- if (copy_to_user(buf + bytes_read, &event_v1,
- event_size))
+ if (!copy_to_iter_full(&event_v1, event_size, to))
return -EFAULT;
}
#else
- if (copy_to_user(buf + bytes_read, &event, event_size))
+ if (!copy_to_iter_full(&event, event_size, to))
return -EFAULT;
#endif
bytes_read += event_size;
@@ -2814,7 +2813,7 @@ static const struct file_operations gpio_fileops = {
.release = gpio_chrdev_release,
.open = gpio_chrdev_open,
.poll = lineinfo_watch_poll,
- .read = lineinfo_watch_read,
+ .read_iter = lineinfo_watch_read,
.owner = THIS_MODULE,
.llseek = no_llseek,
.unlocked_ioctl = gpio_ioctl,
--
2.43.0
Powered by blists - more mailing lists