From nobody Fri Dec 19 17:16:14 2025 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 563E3158D95 for ; Thu, 11 Apr 2024 15:35:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712849708; cv=none; b=PwAYT3fJA2iYvcrSH7rxYuWQg/KHvqvTJKEH1p5o/5RolaRsxsiRFeafjuJkXe3xWmAk66sbyZAD/dVwt9lGK8uogN3hT38PxW96LMEAmTb63QOHP5zXhSnrg7OkEpfFOqftfnwJdIqg4/d+sBHAoC5ozUk+FZ/vGu1hcZxztZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712849708; c=relaxed/simple; bh=Y2CuPnfNGCTlH89sPwvg5Qqu+KAOzE/jZXq27+ZlmTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TYLJBA95MTkT2u4i1PxNrQIyr84/kbH8/y9of1mS1j5COSJLI24Ha7vSV3IPGQnJpPsaP6N9lhhDYqguujJ9FIkz6Q3BeBF8Ge37xA5qXa/MdEQsxsctQwXhKs3JcBMMBSI/V54088y8IRftazhKo8RrX83IafltpfHM8FK+LGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=Nr94BhZM; arc=none smtp.client-ip=209.85.166.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="Nr94BhZM" Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-7d6812b37a6so8922739f.0 for ; Thu, 11 Apr 2024 08:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1712849705; x=1713454505; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jctYABsZiacNIUyvtBgQSkUe95IwzkHgR2PUGlrc25M=; b=Nr94BhZMJW3LQxH3W9dJ2M5jwZUXyi1nP1HcJYZm8QR1F5nJ8HK04lbDbHfomtGGBu 1tnOUyqIuHD6ESycs14QVwDIb9awUamfapAtKHvQElQCzG/LLX5jyw59iv94CCc4gnpT CNlNseV9ZBdPDyWau9vOxVSMWfHoGMRiC8IQAC2U86LQL/vS0HEOtTABPmtu69eG24U1 vT8kC3qJ0JVQmXAo6WmX7BZ32s4JEOSjnpYGxtyJeONVaKLjCebJa0/TDVa+JSAQlPk6 67CBJmCxTJNVpMSawFIsKoVPqzFKCNFO9OHNLyj/p/1mQmpIR6fD5TMyi63B8LX0OUIm DkgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712849705; x=1713454505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jctYABsZiacNIUyvtBgQSkUe95IwzkHgR2PUGlrc25M=; b=CzRAHhBkcdhOaLsFnVQTzYw8hNutuYHgLmyz0+A3FbcN0UwYJfabN4jctF4gCAAOfy TAsk7O/nwaoo1PIlM4fRKfKBRLuIRVOrI/ls+kbD+C2KnNDDa/Tzwl0gkKuoOYrnfIRo 0fROpigddSmqL2dPjAfGznm5fbmK8gH4dIqZWTw9e5OZPGleUiwENv/tTQkLPwBWYkEi fQQIgVPaKIa6HulddptBI8JgWCfVAy5U/ekvEHB+Ha54VN63EE9g5OPUQ2mdyQzA2dwz PfR6RYbggvni+IPqJgQhWIkar1EcC+qEETvmV1TEXRbj17PnxsR+ttXW5Xx9gx8P99Is D2Jg== X-Gm-Message-State: AOJu0Yyp8gHD9HvjX4nwebsZtembU5uUwyW/n4g2cFqKO/W8W7SpPltD HlRtaMwEKDy/OIQGNOO6bpUu6GHfJuhgt2l7XL8ChG8ZfGGs1F6LN01yWKwXiqphDqg7RyXiHgU S X-Google-Smtp-Source: AGHT+IF9gFig6M+UH9WnMfXESZo6hf1MnyyC+bzgiTIP7ZEz+OCipcMpgkovUtXNnZ/hCbTaC+ccNA== X-Received: by 2002:a6b:5b10:0:b0:7d0:bd2b:43ba with SMTP id v16-20020a6b5b10000000b007d0bd2b43bamr219626ioh.0.1712849705156; Thu, 11 Apr 2024 08:35:05 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id jc25-20020a056638891900b0047f14b7f6c0sm457056jab.5.2024.04.11.08.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 08:35:03 -0700 (PDT) From: Jens Axboe To: linux-kernel@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 121/437] drivers/input: convert to read/write iterators Date: Thu, 11 Apr 2024 09:14:21 -0600 Message-ID: <20240411153126.16201-122-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411153126.16201-1-axboe@kernel.dk> References: <20240411153126.16201-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Jens Axboe --- 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 cha= r __user *buffer, mutex_unlock(&evdev->mutex); return retval; } +FOPS_WRITE_ITER_HELPER(evdev_write); =20 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 __use= r *buffer, =20 return read; } +FOPS_READ_ITER_HELPER(evdev_read); =20 /* 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, =20 static const struct file_operations evdev_fops =3D { .owner =3D THIS_MODULE, - .read =3D evdev_read, - .write =3D evdev_write, + .read_iter =3D evdev_read_iter, + .write_iter =3D evdev_write_iter, .poll =3D evdev_poll, .open =3D evdev_open, .release =3D 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 #include #include +#include =20 MODULE_AUTHOR("Vojtech Pavlik "); 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 =3D client->joydev; struct JS_DATA_TYPE data; @@ -366,7 +366,7 @@ static ssize_t joydev_0x_read(struct joydev_client *cli= ent, =20 spin_unlock_irq(&input->event_lock); =20 - if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE))) + if (!copy_to_iter(&data, sizeof(struct JS_DATA_TYPE), to)) return -EFAULT; =20 return sizeof(struct JS_DATA_TYPE); @@ -380,12 +380,12 @@ static inline int joydev_data_pending(struct joydev_c= lient *client) client->head !=3D client->tail; } =20 -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 =3D file->private_data; + struct joydev_client *client =3D iocb->ki_filp->private_data; struct joydev *joydev =3D client->joydev; struct input_dev *input =3D joydev->handle.dev; + size_t count =3D iov_iter_count(to); struct js_event event; int retval; =20 @@ -396,9 +396,9 @@ static ssize_t joydev_read(struct file *file, char __us= er *buf, return -EINVAL; =20 if (count =3D=3D sizeof(struct JS_DATA_TYPE)) - return joydev_0x_read(client, input, buf); + return joydev_0x_read(client, input, to); =20 - if (!joydev_data_pending(client) && (file->f_flags & O_NONBLOCK)) + if (!joydev_data_pending(client) && (iocb->ki_filp->f_flags & O_NONBLOCK)) return -EAGAIN; =20 retval =3D wait_event_interruptible(joydev->wait, @@ -412,7 +412,7 @@ static ssize_t joydev_read(struct file *file, char __us= er *buf, while (retval + sizeof(struct js_event) <=3D count && joydev_generate_startup_event(client, input, &event)) { =20 - if (copy_to_user(buf + retval, &event, sizeof(struct js_event))) + if (!copy_to_iter_full(&event, sizeof(struct js_event), to)) return -EFAULT; =20 retval +=3D sizeof(struct js_event); @@ -421,7 +421,7 @@ static ssize_t joydev_read(struct file *file, char __us= er *buf, while (retval + sizeof(struct js_event) <=3D count && joydev_fetch_next_event(client, &event)) { =20 - if (copy_to_user(buf + retval, &event, sizeof(struct js_event))) + if (!copy_to_iter_full(&event, sizeof(struct js_event), to)) return -EFAULT; =20 retval +=3D sizeof(struct js_event); @@ -709,7 +709,7 @@ static long joydev_ioctl(struct file *file, =20 static const struct file_operations joydev_fops =3D { .owner =3D THIS_MODULE, - .read =3D joydev_read, + .read_iter =3D joydev_read, .poll =3D joydev_poll, .open =3D joydev_open, .release =3D joydev_release, diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/app= lespi.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); } =20 -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 *t= o) { - struct applespi_data *applespi =3D file->private_data; + struct applespi_data *applespi =3D iocb->ki_filp->private_data; =20 - 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); } =20 static const struct file_operations applespi_tp_dim_fops =3D { .owner =3D THIS_MODULE, .open =3D applespi_tp_dim_open, - .read =3D applespi_tp_dim_read, + .read_iter =3D applespi_tp_dim_read, .llseek =3D no_llseek, }; =20 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 ch= ar __user *buffer, =20 return retval; } +FOPS_WRITE_ITER_HELPER(uinput_write); =20 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 __us= er *buffer, =20 return retval; } +FOPS_READ_ITER_HELPER(uinput_read); =20 static __poll_t uinput_poll(struct file *file, poll_table *wait) { @@ -1111,8 +1113,8 @@ static const struct file_operations uinput_fops =3D { .owner =3D THIS_MODULE, .open =3D uinput_open, .release =3D uinput_release, - .read =3D uinput_read, - .write =3D uinput_write, + .read_iter =3D uinput_read_iter, + .write_iter =3D uinput_write_iter, .poll =3D uinput_poll, .unlocked_ioctl =3D 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 #include #include +#include =20 MODULE_AUTHOR("Vojtech Pavlik "); MODULE_DESCRIPTION("Mouse (ExplorerPS/2) device interfaces"); @@ -712,17 +713,18 @@ static ssize_t mousedev_write(struct file *file, cons= t char __user *buffer, =20 return count; } +FOPS_WRITE_ITER_HELPER(mousedev_write); =20 -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 =3D file->private_data; + struct mousedev_client *client =3D iocb->ki_filp->private_data; struct mousedev *mousedev =3D client->mousedev; + size_t count =3D iov_iter_count(to); u8 data[sizeof(client->ps2)]; int retval =3D 0; =20 if (!client->ready && !client->buffer && mousedev->exist && - (file->f_flags & O_NONBLOCK)) + (iocb->ki_filp->f_flags & O_NONBLOCK)) return -EAGAIN; =20 retval =3D wait_event_interruptible(mousedev->wait, @@ -748,7 +750,7 @@ static ssize_t mousedev_read(struct file *file, char __= user *buffer, =20 spin_unlock_irq(&client->packet_lock); =20 - if (copy_to_user(buffer, data, count)) + if (!copy_to_iter_full(data, count, to)) return -EFAULT; =20 return count; @@ -772,8 +774,8 @@ static __poll_t mousedev_poll(struct file *file, poll_t= able *wait) =20 static const struct file_operations mousedev_fops =3D { .owner =3D THIS_MODULE, - .read =3D mousedev_read, - .write =3D mousedev_write, + .read_iter =3D mousedev_read, + .write_iter =3D mousedev_write_iter, .poll =3D mousedev_poll, .open =3D mousedev_open, .release =3D mousedev_release, diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_ra= w.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, =20 return read; } +FOPS_READ_ITER_HELPER(serio_raw_read); =20 static ssize_t serio_raw_write(struct file *file, const char __user *buffe= r, 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); =20 static __poll_t serio_raw_poll(struct file *file, poll_table *wait) { @@ -255,8 +257,8 @@ static const struct file_operations serio_raw_fops =3D { .owner =3D THIS_MODULE, .open =3D serio_raw_open, .release =3D serio_raw_release, - .read =3D serio_raw_read, - .write =3D serio_raw_write, + .read_iter =3D serio_raw_read_iter, + .write_iter =3D serio_raw_write_iter, .poll =3D serio_raw_poll, .fasync =3D serio_raw_fasync, .llseek =3D 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, s= truct file *file) return 0; } =20 -static ssize_t userio_char_read(struct file *file, char __user *user_buffe= r, - size_t count, loff_t *ppos) +static ssize_t userio_char_read(struct kiocb *iocb, struct iov_iter *to) { - struct userio_device *userio =3D file->private_data; + struct userio_device *userio =3D iocb->ki_filp->private_data; + size_t count =3D 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; =20 /* buffer was/is empty */ - if (file->f_flags & O_NONBLOCK) + if (iocb->ki_filp->f_flags & O_NONBLOCK) return -EAGAIN; =20 /* @@ -170,16 +170,16 @@ static ssize_t userio_char_read(struct file *file, ch= ar __user *user_buffer, } =20 if (copylen) - if (copy_to_user(user_buffer, buf, copylen)) + if (!copy_to_iter_full(buf, copylen, to)) return -EFAULT; =20 return copylen; } =20 -static ssize_t userio_char_write(struct file *file, const char __user *buf= fer, - size_t count, loff_t *ppos) +static ssize_t userio_char_write(struct kiocb *iocb, struct iov_iter *from) { - struct userio_device *userio =3D file->private_data; + struct userio_device *userio =3D iocb->ki_filp->private_data; + size_t count =3D iov_iter_count(from); struct userio_cmd cmd; int error; =20 @@ -188,7 +188,7 @@ static ssize_t userio_char_write(struct file *file, con= st char __user *buffer, return -EINVAL; } =20 - if (copy_from_user(&cmd, buffer, sizeof(cmd))) + if (!copy_from_iter_full(&cmd, sizeof(cmd), from)) return -EFAULT; =20 error =3D mutex_lock_interruptible(&userio->mutex); @@ -264,8 +264,8 @@ static const struct file_operations userio_fops =3D { .owner =3D THIS_MODULE, .open =3D userio_char_open, .release =3D userio_char_release, - .read =3D userio_char_read, - .write =3D userio_char_write, + .read_iter =3D userio_char_read, + .write_iter =3D userio_char_write, .poll =3D userio_char_poll, .llseek =3D no_llseek, }; diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchsc= reen/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 #include #include +#include =20 #include =20 @@ -735,20 +736,20 @@ static int edt_ft5x06_debugfs_mode_set(void *data, u6= 4 mode) DEFINE_SIMPLE_ATTRIBUTE(debugfs_mode_fops, edt_ft5x06_debugfs_mode_get, edt_ft5x06_debugfs_mode_set, "%llu\n"); =20 -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 =3D file->private_data; + struct edt_ft5x06_ts_data *tsdata =3D iocb->ki_filp->private_data; struct i2c_client *client =3D tsdata->client; int retries =3D EDT_RAW_DATA_RETRIES; + size_t count =3D iov_iter_count(to); unsigned int val; int i, error; size_t read =3D 0; int colbytes; u8 *rdbuf; =20 - if (*off < 0 || *off >=3D tsdata->raw_bufsize) + if (iocb->ki_pos < 0 || iocb->ki_pos >=3D tsdata->raw_bufsize) return 0; =20 mutex_lock(&tsdata->mutex); @@ -798,13 +799,13 @@ static ssize_t edt_ft5x06_debugfs_raw_data_read(struc= t file *file, rdbuf +=3D colbytes; } =20 - read =3D min_t(size_t, count, tsdata->raw_bufsize - *off); - if (copy_to_user(buf, tsdata->raw_buffer + *off, read)) { + read =3D 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 =3D -EFAULT; goto out; } =20 - *off +=3D read; + iocb->ki_pos +=3D 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, =20 static const struct file_operations debugfs_raw_data_fops =3D { .open =3D simple_open, - .read =3D edt_ft5x06_debugfs_raw_data_read, + .read_iter =3D edt_ft5x06_debugfs_raw_data_read, }; =20 static void edt_ft5x06_ts_prepare_debugfs(struct edt_ft5x06_ts_data *tsdat= a, --=20 2.43.0