[PATCH 121/437] drivers/input: convert to read/write iterators

From: Jens Axboe
Date: Thu Apr 11 2024 - 12:07:44 EST


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
drivers/input/evdev.c | 6 ++++--
drivers/input/joydev.c | 22 +++++++++++-----------
drivers/input/keyboard/applespi.c | 11 +++++------
drivers/input/misc/uinput.c | 6 ++++--
drivers/input/mousedev.c | 16 +++++++++-------
drivers/input/serio/serio_raw.c | 6 ++++--
drivers/input/serio/userio.c | 22 +++++++++++-----------
drivers/input/touchscreen/edt-ft5x06.c | 19 ++++++++++---------
8 files changed, 58 insertions(+), 50 deletions(-)

diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 51e0c4954600..9f41631df926 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -536,6 +536,7 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
mutex_unlock(&evdev->mutex);
return retval;
}
+FOPS_WRITE_ITER_HELPER(evdev_write);

static int evdev_fetch_next_event(struct evdev_client *client,
struct input_event *event)
@@ -605,6 +606,7 @@ static ssize_t evdev_read(struct file *file, char __user *buffer,

return read;
}
+FOPS_READ_ITER_HELPER(evdev_read);

/* No kernel lock - fine */
static __poll_t evdev_poll(struct file *file, poll_table *wait)
@@ -1291,8 +1293,8 @@ static long evdev_ioctl_compat(struct file *file,

static const struct file_operations evdev_fops = {
.owner = THIS_MODULE,
- .read = evdev_read,
- .write = evdev_write,
+ .read_iter = evdev_read_iter,
+ .write_iter = evdev_write_iter,
.poll = evdev_poll,
.open = evdev_open,
.release = evdev_release,
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 5824bca02e5a..e84acc296aaa 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -23,6 +23,7 @@
#include <linux/init.h>
#include <linux/device.h>
#include <linux/cdev.h>
+#include <linux/uio.h>

MODULE_AUTHOR("Vojtech Pavlik <vojtech@xxxxxx>");
MODULE_DESCRIPTION("Joystick device interfaces");
@@ -338,8 +339,7 @@ static int joydev_fetch_next_event(struct joydev_client *client,
* Old joystick interface
*/
static ssize_t joydev_0x_read(struct joydev_client *client,
- struct input_dev *input,
- char __user *buf)
+ struct input_dev *input, struct iov_iter *to)
{
struct joydev *joydev = client->joydev;
struct JS_DATA_TYPE data;
@@ -366,7 +366,7 @@ static ssize_t joydev_0x_read(struct joydev_client *client,

spin_unlock_irq(&input->event_lock);

- if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE)))
+ if (!copy_to_iter(&data, sizeof(struct JS_DATA_TYPE), to))
return -EFAULT;

return sizeof(struct JS_DATA_TYPE);
@@ -380,12 +380,12 @@ static inline int joydev_data_pending(struct joydev_client *client)
client->head != client->tail;
}

-static ssize_t joydev_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t joydev_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct joydev_client *client = file->private_data;
+ struct joydev_client *client = iocb->ki_filp->private_data;
struct joydev *joydev = client->joydev;
struct input_dev *input = joydev->handle.dev;
+ size_t count = iov_iter_count(to);
struct js_event event;
int retval;

@@ -396,9 +396,9 @@ static ssize_t joydev_read(struct file *file, char __user *buf,
return -EINVAL;

if (count == sizeof(struct JS_DATA_TYPE))
- return joydev_0x_read(client, input, buf);
+ return joydev_0x_read(client, input, to);

- if (!joydev_data_pending(client) && (file->f_flags & O_NONBLOCK))
+ if (!joydev_data_pending(client) && (iocb->ki_filp->f_flags & O_NONBLOCK))
return -EAGAIN;

retval = wait_event_interruptible(joydev->wait,
@@ -412,7 +412,7 @@ static ssize_t joydev_read(struct file *file, char __user *buf,
while (retval + sizeof(struct js_event) <= count &&
joydev_generate_startup_event(client, input, &event)) {

- if (copy_to_user(buf + retval, &event, sizeof(struct js_event)))
+ if (!copy_to_iter_full(&event, sizeof(struct js_event), to))
return -EFAULT;

retval += sizeof(struct js_event);
@@ -421,7 +421,7 @@ static ssize_t joydev_read(struct file *file, char __user *buf,
while (retval + sizeof(struct js_event) <= count &&
joydev_fetch_next_event(client, &event)) {

- if (copy_to_user(buf + retval, &event, sizeof(struct js_event)))
+ if (!copy_to_iter_full(&event, sizeof(struct js_event), to))
return -EFAULT;

retval += sizeof(struct js_event);
@@ -709,7 +709,7 @@ static long joydev_ioctl(struct file *file,

static const struct file_operations joydev_fops = {
.owner = THIS_MODULE,
- .read = joydev_read,
+ .read_iter = joydev_read,
.poll = joydev_poll,
.open = joydev_open,
.release = joydev_release,
diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c
index cf25177b4830..fa1ce0d23f14 100644
--- a/drivers/input/keyboard/applespi.c
+++ b/drivers/input/keyboard/applespi.c
@@ -994,19 +994,18 @@ static int applespi_tp_dim_open(struct inode *inode, struct file *file)
return nonseekable_open(inode, file);
}

-static ssize_t applespi_tp_dim_read(struct file *file, char __user *buf,
- size_t len, loff_t *off)
+static ssize_t applespi_tp_dim_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct applespi_data *applespi = file->private_data;
+ struct applespi_data *applespi = iocb->ki_filp->private_data;

- return simple_read_from_buffer(buf, len, off, applespi->tp_dim_val,
- strlen(applespi->tp_dim_val));
+ return simple_copy_to_iter(applespi->tp_dim_val, &iocb->ki_pos,
+ strlen(applespi->tp_dim_val), to);
}

static const struct file_operations applespi_tp_dim_fops = {
.owner = THIS_MODULE,
.open = applespi_tp_dim_open,
- .read = applespi_tp_dim_read,
+ .read_iter = applespi_tp_dim_read,
.llseek = no_llseek,
};

diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index d98212d55108..960a0c729bc2 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -651,6 +651,7 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer,

return retval;
}
+FOPS_WRITE_ITER_HELPER(uinput_write);

static bool uinput_fetch_next_event(struct uinput_device *udev,
struct input_event *event)
@@ -723,6 +724,7 @@ static ssize_t uinput_read(struct file *file, char __user *buffer,

return retval;
}
+FOPS_READ_ITER_HELPER(uinput_read);

static __poll_t uinput_poll(struct file *file, poll_table *wait)
{
@@ -1111,8 +1113,8 @@ static const struct file_operations uinput_fops = {
.owner = THIS_MODULE,
.open = uinput_open,
.release = uinput_release,
- .read = uinput_read,
- .write = uinput_write,
+ .read_iter = uinput_read_iter,
+ .write_iter = uinput_write_iter,
.poll = uinput_poll,
.unlocked_ioctl = uinput_ioctl,
#ifdef CONFIG_COMPAT
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 505c562a5daa..5d1905f078d1 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -24,6 +24,7 @@
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/kernel.h>
+#include <linux/uio.h>

MODULE_AUTHOR("Vojtech Pavlik <vojtech@xxxxxx>");
MODULE_DESCRIPTION("Mouse (ExplorerPS/2) device interfaces");
@@ -712,17 +713,18 @@ static ssize_t mousedev_write(struct file *file, const char __user *buffer,

return count;
}
+FOPS_WRITE_ITER_HELPER(mousedev_write);

-static ssize_t mousedev_read(struct file *file, char __user *buffer,
- size_t count, loff_t *ppos)
+static ssize_t mousedev_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct mousedev_client *client = file->private_data;
+ struct mousedev_client *client = iocb->ki_filp->private_data;
struct mousedev *mousedev = client->mousedev;
+ size_t count = iov_iter_count(to);
u8 data[sizeof(client->ps2)];
int retval = 0;

if (!client->ready && !client->buffer && mousedev->exist &&
- (file->f_flags & O_NONBLOCK))
+ (iocb->ki_filp->f_flags & O_NONBLOCK))
return -EAGAIN;

retval = wait_event_interruptible(mousedev->wait,
@@ -748,7 +750,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,

spin_unlock_irq(&client->packet_lock);

- if (copy_to_user(buffer, data, count))
+ if (!copy_to_iter_full(data, count, to))
return -EFAULT;

return count;
@@ -772,8 +774,8 @@ static __poll_t mousedev_poll(struct file *file, poll_table *wait)

static const struct file_operations mousedev_fops = {
.owner = THIS_MODULE,
- .read = mousedev_read,
- .write = mousedev_write,
+ .read_iter = mousedev_read,
+ .write_iter = mousedev_write_iter,
.poll = mousedev_poll,
.open = mousedev_open,
.release = mousedev_release,
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
index 1e4770094415..3b4e72fdcd4f 100644
--- a/drivers/input/serio/serio_raw.c
+++ b/drivers/input/serio/serio_raw.c
@@ -194,6 +194,7 @@ static ssize_t serio_raw_read(struct file *file, char __user *buffer,

return read;
}
+FOPS_READ_ITER_HELPER(serio_raw_read);

static ssize_t serio_raw_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
@@ -235,6 +236,7 @@ static ssize_t serio_raw_write(struct file *file, const char __user *buffer,
mutex_unlock(&serio_raw_mutex);
return retval;
}
+FOPS_WRITE_ITER_HELPER(serio_raw_write);

static __poll_t serio_raw_poll(struct file *file, poll_table *wait)
{
@@ -255,8 +257,8 @@ static const struct file_operations serio_raw_fops = {
.owner = THIS_MODULE,
.open = serio_raw_open,
.release = serio_raw_release,
- .read = serio_raw_read,
- .write = serio_raw_write,
+ .read_iter = serio_raw_read_iter,
+ .write_iter = serio_raw_write_iter,
.poll = serio_raw_poll,
.fasync = serio_raw_fasync,
.llseek = noop_llseek,
diff --git a/drivers/input/serio/userio.c b/drivers/input/serio/userio.c
index 9ab5c45c3a9f..3688579d69d2 100644
--- a/drivers/input/serio/userio.c
+++ b/drivers/input/serio/userio.c
@@ -118,10 +118,10 @@ static int userio_char_release(struct inode *inode, struct file *file)
return 0;
}

-static ssize_t userio_char_read(struct file *file, char __user *user_buffer,
- size_t count, loff_t *ppos)
+static ssize_t userio_char_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct userio_device *userio = file->private_data;
+ struct userio_device *userio = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(to);
int error;
size_t nonwrap_len, copylen;
unsigned char buf[USERIO_BUFSIZE];
@@ -153,7 +153,7 @@ static ssize_t userio_char_read(struct file *file, char __user *user_buffer,
break;

/* buffer was/is empty */
- if (file->f_flags & O_NONBLOCK)
+ if (iocb->ki_filp->f_flags & O_NONBLOCK)
return -EAGAIN;

/*
@@ -170,16 +170,16 @@ static ssize_t userio_char_read(struct file *file, char __user *user_buffer,
}

if (copylen)
- if (copy_to_user(user_buffer, buf, copylen))
+ if (!copy_to_iter_full(buf, copylen, to))
return -EFAULT;

return copylen;
}

-static ssize_t userio_char_write(struct file *file, const char __user *buffer,
- size_t count, loff_t *ppos)
+static ssize_t userio_char_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct userio_device *userio = file->private_data;
+ struct userio_device *userio = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct userio_cmd cmd;
int error;

@@ -188,7 +188,7 @@ static ssize_t userio_char_write(struct file *file, const char __user *buffer,
return -EINVAL;
}

- if (copy_from_user(&cmd, buffer, sizeof(cmd)))
+ if (!copy_from_iter_full(&cmd, sizeof(cmd), from))
return -EFAULT;

error = mutex_lock_interruptible(&userio->mutex);
@@ -264,8 +264,8 @@ static const struct file_operations userio_fops = {
.owner = THIS_MODULE,
.open = userio_char_open,
.release = userio_char_release,
- .read = userio_char_read,
- .write = userio_char_write,
+ .read_iter = userio_char_read,
+ .write_iter = userio_char_write,
.poll = userio_char_poll,
.llseek = no_llseek,
};
diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index 2a1db1134476..fe1b0a2c0925 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -31,6 +31,7 @@
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
+#include <linux/uio.h>

#include <asm/unaligned.h>

@@ -735,20 +736,20 @@ static int edt_ft5x06_debugfs_mode_set(void *data, u64 mode)
DEFINE_SIMPLE_ATTRIBUTE(debugfs_mode_fops, edt_ft5x06_debugfs_mode_get,
edt_ft5x06_debugfs_mode_set, "%llu\n");

-static ssize_t edt_ft5x06_debugfs_raw_data_read(struct file *file,
- char __user *buf, size_t count,
- loff_t *off)
+static ssize_t edt_ft5x06_debugfs_raw_data_read(struct kiocb *iocb,
+ struct iov_iter *to)
{
- struct edt_ft5x06_ts_data *tsdata = file->private_data;
+ struct edt_ft5x06_ts_data *tsdata = iocb->ki_filp->private_data;
struct i2c_client *client = tsdata->client;
int retries = EDT_RAW_DATA_RETRIES;
+ size_t count = iov_iter_count(to);
unsigned int val;
int i, error;
size_t read = 0;
int colbytes;
u8 *rdbuf;

- if (*off < 0 || *off >= tsdata->raw_bufsize)
+ if (iocb->ki_pos < 0 || iocb->ki_pos >= tsdata->raw_bufsize)
return 0;

mutex_lock(&tsdata->mutex);
@@ -798,13 +799,13 @@ static ssize_t edt_ft5x06_debugfs_raw_data_read(struct file *file,
rdbuf += colbytes;
}

- read = min_t(size_t, count, tsdata->raw_bufsize - *off);
- if (copy_to_user(buf, tsdata->raw_buffer + *off, read)) {
+ read = min_t(size_t, count, tsdata->raw_bufsize - iocb->ki_pos);
+ if (!copy_to_iter_full(tsdata->raw_buffer + iocb->ki_pos, read, to)) {
error = -EFAULT;
goto out;
}

- *off += read;
+ iocb->ki_pos += read;
out:
mutex_unlock(&tsdata->mutex);
return error ?: read;
@@ -812,7 +813,7 @@ static ssize_t edt_ft5x06_debugfs_raw_data_read(struct file *file,

static const struct file_operations debugfs_raw_data_fops = {
.open = simple_open,
- .read = edt_ft5x06_debugfs_raw_data_read,
+ .read_iter = edt_ft5x06_debugfs_raw_data_read,
};

static void edt_ft5x06_ts_prepare_debugfs(struct edt_ft5x06_ts_data *tsdata,
--
2.43.0