[PATCH 414/437] media/dvb-core: convert to read/write iterators

Jens Axboe
2024-04-11T15:43:13Z

drivers/media/dvb-core/dmxdev.c | 9 ++++++---
drivers/media/dvb-core/dvb_ca_en50221.c | 25 +++++++++++--------------
2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index 9ce5f010de3f..f30ec9c3cade 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -261,6 +261,7 @@ static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
mutex_unlock(&dmxdev->mutex);
return ret;
}
+FOPS_WRITE_ITER_HELPER(dvb_dvr_write);

static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
@@ -275,6 +276,7 @@ static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
file->f_flags & O_NONBLOCK,
buf, count, ppos);
}
+FOPS_READ_ITER_HELPER(dvb_dvr_read);

static int dvb_dvr_set_buffer_size(struct dmxdev *dmxdev,
unsigned long size)
@@ -1025,6 +1027,7 @@ dvb_demux_read(struct file *file, char __user *buf, size_t count,
mutex_unlock(&dmxdevfilter->mutex);
return ret;
}
+FOPS_READ_ITER_HELPER(dvb_demux_read);

static int dvb_demux_do_ioctl(struct file *file,
unsigned int cmd, void *parg)
@@ -1258,7 +1261,7 @@ static int dvb_demux_release(struct inode *inode, struct file *file)

static const struct file_operations dvb_demux_fops = {
.owner = THIS_MODULE,
- .read = dvb_demux_read,
+ .read_iter = dvb_demux_read_iter,
.unlocked_ioctl = dvb_demux_ioctl,
.compat_ioctl = dvb_demux_ioctl,
.open = dvb_demux_open,
@@ -1385,8 +1388,8 @@ static int dvb_dvr_mmap(struct file *file, struct vm_area_struct *vma)

static const struct file_operations dvb_dvr_fops = {
.owner = THIS_MODULE,
- .read = dvb_dvr_read,
- .write = dvb_dvr_write,
+ .read_iter = dvb_dvr_read_iter,
+ .write_iter = dvb_dvr_write_iter,
.unlocked_ioctl = dvb_dvr_ioctl,
.open = dvb_dvr_open,
.release = dvb_dvr_release,
diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
index baf64540dc00..ccb9bff21304 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -1436,19 +1436,16 @@ static long dvb_ca_en50221_io_ioctl(struct file *file,
/**
* dvb_ca_en50221_io_write - Implementation of write() syscall.
*
- * @file: File structure.
- * @buf: Source buffer.
- * @count: Size of source buffer.
- * @ppos: Position in file (ignored).
+ * @iocb: metadata for IO
+ * @from: buffer to read from
*
* return: Number of bytes read, or <0 on error.
*/
-static ssize_t dvb_ca_en50221_io_write(struct file *file,
- const char __user *buf, size_t count,
- loff_t *ppos)
+static ssize_t dvb_ca_en50221_io_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct dvb_device *dvbdev = file->private_data;
+ struct dvb_device *dvbdev = iocb->ki_filp->private_data;
struct dvb_ca_private *ca = dvbdev->priv;
+ size_t count = iov_iter_count(from);
struct dvb_ca_slot *sl;
u8 slot, connection_id;
int status;
@@ -1468,11 +1465,10 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
return -EINVAL;

/* extract slot & connection id */
- if (copy_from_user(&slot, buf, 1))
+ if (!copy_from_iter_full(&slot, 1, from))
return -EFAULT;
- if (copy_from_user(&connection_id, buf + 1, 1))
+ if (!copy_from_iter_full(&connection_id, 1, from))
return -EFAULT;
- buf += 2;
count -= 2;

if (slot >= ca->slot_count)
@@ -1496,7 +1492,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,

fragbuf[0] = connection_id;
fragbuf[1] = ((fragpos + fraglen) < count) ? 0x80 : 0x00;
- status = copy_from_user(fragbuf + 2, buf + fragpos, fraglen);
+ status = !copy_from_iter_full(fragbuf + 2, fraglen, from);
if (status) {
status = -EFAULT;
goto exit;
@@ -1699,6 +1695,7 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf,
exit:
return status;
}
+FOPS_READ_ITER_HELPER(dvb_ca_en50221_io_read);

/**
* dvb_ca_en50221_io_open - Implementation of file open syscall.
@@ -1834,8 +1831,8 @@ static __poll_t dvb_ca_en50221_io_poll(struct file *file, poll_table *wait)

static const struct file_operations dvb_ca_fops = {
.owner = THIS_MODULE,
- .read = dvb_ca_en50221_io_read,
- .write = dvb_ca_en50221_io_write,
+ .read_iter = dvb_ca_en50221_io_read_iter,
+ .write_iter = dvb_ca_en50221_io_write,
.unlocked_ioctl = dvb_ca_en50221_io_ioctl,
.open = dvb_ca_en50221_io_open,
.release = dvb_ca_en50221_io_release,
--
2.43.0