[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-378-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:18:37 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 377/437] iio: convert to read/write iterators
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
drivers/iio/iio_core.h | 7 +++----
drivers/iio/industrialio-buffer.c | 20 +++++++++---------
drivers/iio/industrialio-core.c | 34 +++++++++++++++----------------
drivers/iio/industrialio-event.c | 3 ++-
4 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
index 1a38b1915e7a..8aac545ec4d0 100644
--- a/drivers/iio/iio_core.h
+++ b/drivers/iio/iio_core.h
@@ -11,6 +11,7 @@
#define _IIO_CORE_H_
#include <linux/kernel.h>
#include <linux/device.h>
+#include <linux/fs.h>
struct iio_buffer;
struct iio_chan_spec;
@@ -63,10 +64,8 @@ struct poll_table_struct;
__poll_t iio_buffer_poll_wrapper(struct file *filp,
struct poll_table_struct *wait);
-ssize_t iio_buffer_read_wrapper(struct file *filp, char __user *buf,
- size_t n, loff_t *f_ps);
-ssize_t iio_buffer_write_wrapper(struct file *filp, const char __user *buf,
- size_t n, loff_t *f_ps);
+ssize_t iio_buffer_read_wrapper( struct kiocb *iocb, struct iov_iter *to);
+ssize_t iio_buffer_write_wrapper( struct kiocb *iocb, struct iov_iter *from);
int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev);
void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev);
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index b581a7e80566..38a75f88adf6 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -163,6 +163,7 @@ static ssize_t iio_buffer_read(struct file *filp, char __user *buf,
return ret;
}
+FOPS_READ_ITER_HELPER(iio_buffer_read);
static size_t iio_buffer_space_available(struct iio_buffer *buf)
{
@@ -225,6 +226,7 @@ static ssize_t iio_buffer_write(struct file *filp, const char __user *buf,
return ret < 0 ? ret : written;
}
+FOPS_WRITE_ITER_HELPER(iio_buffer_write);
/**
* iio_buffer_poll() - poll the buffer to find out if it has data
@@ -261,30 +263,28 @@ static __poll_t iio_buffer_poll(struct file *filp,
return 0;
}
-ssize_t iio_buffer_read_wrapper(struct file *filp, char __user *buf,
- size_t n, loff_t *f_ps)
+ssize_t iio_buffer_read_wrapper(struct kiocb *iocb, struct iov_iter *to)
{
- struct iio_dev_buffer_pair *ib = filp->private_data;
+ struct iio_dev_buffer_pair *ib = iocb->ki_filp->private_data;
struct iio_buffer *rb = ib->buffer;
/* check if buffer was opened through new API */
if (test_bit(IIO_BUSY_BIT_POS, &rb->flags))
return -EBUSY;
- return iio_buffer_read(filp, buf, n, f_ps);
+ return vfs_read_iter(iocb, to, iio_buffer_read);
}
-ssize_t iio_buffer_write_wrapper(struct file *filp, const char __user *buf,
- size_t n, loff_t *f_ps)
+ssize_t iio_buffer_write_wrapper(struct kiocb *iocb, struct iov_iter *from)
{
- struct iio_dev_buffer_pair *ib = filp->private_data;
+ struct iio_dev_buffer_pair *ib = iocb->ki_filp->private_data;
struct iio_buffer *rb = ib->buffer;
/* check if buffer was opened through new API */
if (test_bit(IIO_BUSY_BIT_POS, &rb->flags))
return -EBUSY;
- return iio_buffer_write(filp, buf, n, f_ps);
+ return vfs_write_iter(iocb, from, iio_buffer_write);
}
__poll_t iio_buffer_poll_wrapper(struct file *filp,
@@ -1537,8 +1537,8 @@ static int iio_buffer_chrdev_release(struct inode *inode, struct file *filep)
static const struct file_operations iio_buffer_chrdev_fileops = {
.owner = THIS_MODULE,
.llseek = noop_llseek,
- .read = iio_buffer_read,
- .write = iio_buffer_write,
+ .read_iter = iio_buffer_read_iter,
+ .write_iter = iio_buffer_write_iter,
.poll = iio_buffer_poll,
.release = iio_buffer_chrdev_release,
};
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 4302093b92c7..6bf6818e505c 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -369,18 +369,17 @@ static void __exit iio_exit(void)
}
#if defined(CONFIG_DEBUG_FS)
-static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
+static ssize_t iio_debugfs_read_reg(struct kiocb *iocb, struct iov_iter *to)
{
- struct iio_dev *indio_dev = file->private_data;
+ struct iio_dev *indio_dev = iocb->ki_filp->private_data;
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
unsigned int val = 0;
int ret;
- if (*ppos > 0)
- return simple_read_from_buffer(userbuf, count, ppos,
- iio_dev_opaque->read_buf,
- iio_dev_opaque->read_buf_len);
+ if (iocb->ki_pos > 0)
+ return simple_copy_to_iter(iio_dev_opaque->read_buf,
+ &iocb->ki_pos,
+ iio_dev_opaque->read_buf_len, to);
ret = indio_dev->info->debugfs_reg_access(indio_dev,
iio_dev_opaque->cached_reg_addr,
@@ -394,22 +393,21 @@ static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
sizeof(iio_dev_opaque->read_buf),
"0x%X\n", val);
- return simple_read_from_buffer(userbuf, count, ppos,
- iio_dev_opaque->read_buf,
- iio_dev_opaque->read_buf_len);
+ return simple_copy_to_iter(iio_dev_opaque->read_buf, &iocb->ki_pos,
+ iio_dev_opaque->read_buf_len, to);
}
-static ssize_t iio_debugfs_write_reg(struct file *file,
- const char __user *userbuf, size_t count, loff_t *ppos)
+static ssize_t iio_debugfs_write_reg(struct kiocb *iocb, struct iov_iter *from)
{
- struct iio_dev *indio_dev = file->private_data;
+ struct iio_dev *indio_dev = iocb->ki_filp->private_data;
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
+ size_t count = iov_iter_count(from);
unsigned int reg, val;
char buf[80];
int ret;
count = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, userbuf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;
buf[count] = 0;
@@ -439,8 +437,8 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
static const struct file_operations iio_debugfs_reg_fops = {
.open = simple_open,
- .read = iio_debugfs_read_reg,
- .write = iio_debugfs_write_reg,
+ .read_iter = iio_debugfs_read_reg,
+ .write_iter = iio_debugfs_write_reg,
};
static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
@@ -1839,8 +1837,8 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
static const struct file_operations iio_buffer_fileops = {
.owner = THIS_MODULE,
.llseek = noop_llseek,
- .read = iio_buffer_read_outer_addr,
- .write = iio_buffer_write_outer_addr,
+ .read_iter = iio_buffer_read_outer_addr,
+ .write_iter = iio_buffer_write_outer_addr,
.poll = iio_buffer_poll_addr,
.unlocked_ioctl = iio_ioctl,
.compat_ioctl = compat_ptr_ioctl,
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index 910c1f14abd5..b6ce1ac1d1ca 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -167,6 +167,7 @@ static ssize_t iio_event_chrdev_read(struct file *filep,
return copied;
}
+FOPS_READ_ITER_HELPER(iio_event_chrdev_read);
static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
{
@@ -182,7 +183,7 @@ static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
}
static const struct file_operations iio_event_chrdev_fileops = {
- .read = iio_event_chrdev_read,
+ .read_iter = iio_event_chrdev_read_iter,
.poll = iio_event_poll,
.release = iio_event_chrdev_release,
.owner = THIS_MODULE,
--
2.43.0
Powered by blists - more mailing lists