Skip to contentSkip to conversation

Kill off old fops ->read() and ->write()

RFC PATCH In review Jens Axboe 4 participants 451 messages Apr 11, 2024 – May 5, 2024 Page 2 of 5

Subsystems (424)
lore
Share & tools
lore
author maintainer
#98 lore raw

PATCH 92/437 selinux: convert to read/write iterators

In reply to Jens Axboe
---
 security/selinux/selinuxfs.c | 168 +++++++++++++++++------------------
 1 file changed, 82 insertions(+), 86 deletions(-)
security/selinux/selinuxfs.c +82 -86
index 074d6c2714eb..9ac5bcf5edc4 100644
@@ -120,15 +120,14 @@ static void selinux_fs_info_free(struct super_block *sb)
 #define POLICYCAP_DIR_NAME "policy_capabilities"
 
 #define TMPBUFLEN	12
-static ssize_t sel_read_enforce(struct file *filp, char __user *buf,
-				size_t count, loff_t *ppos)
+static ssize_t sel_read_enforce(struct kiocb *iocb, struct iov_iter *to)
 {
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
 	length = scnprintf(tmpbuf, TMPBUFLEN, "%d",
 			   enforcing_enabled());
-	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+	return simple_copy_to_iter(tmpbuf, &iocb->ki_pos, length, to);
 }
 
 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
@@ -186,32 +185,32 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf,
 	kfree(page);
 	return length;
 }
+FOPS_WRITE_ITER_HELPER(sel_write_enforce);
 #else
-#define sel_write_enforce NULL
+#define sel_write_enforce_iter NULL
 #endif
 
 static const struct file_operations sel_enforce_ops = {
-	.read		= sel_read_enforce,
-	.write		= sel_write_enforce,
+	.read_iter	= sel_read_enforce,
+	.write_iter	= sel_write_enforce_iter,
 	.llseek		= generic_file_llseek,
 };
 
-static ssize_t sel_read_handle_unknown(struct file *filp, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t sel_read_handle_unknown(struct kiocb *iocb, struct iov_iter *to)
 {
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
-	ino_t ino = file_inode(filp)->i_ino;
+	ino_t ino = file_inode(iocb->ki_filp)->i_ino;
 	int handle_unknown = (ino == SEL_REJECT_UNKNOWN) ?
 		security_get_reject_unknown() :
 		!security_get_allow_unknown();
 
 	length = scnprintf(tmpbuf, TMPBUFLEN, "%d", handle_unknown);
-	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+	return simple_copy_to_iter(tmpbuf, &iocb->ki_pos, length, to);
 }
 
 static const struct file_operations sel_handle_unknown_ops = {
-	.read		= sel_read_handle_unknown,
+	.read_iter	= sel_read_handle_unknown,
 	.llseek		= generic_file_llseek,
 };
 
@@ -227,16 +226,14 @@ static int sel_open_handle_status(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static ssize_t sel_read_handle_status(struct file *filp, char __user *buf,
-				      size_t count, loff_t *ppos)
+static ssize_t sel_read_handle_status(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct page    *status = filp->private_data;
+	struct page    *status = iocb->ki_filp->private_data;
 
 	BUG_ON(!status);
 
-	return simple_read_from_buffer(buf, count, ppos,
-				       page_address(status),
-				       sizeof(struct selinux_kernel_status));
+	return simple_copy_to_iter(page_address(status), &iocb->ki_pos,
+				       sizeof(struct selinux_kernel_status), to);
 }
 
 static int sel_mmap_handle_status(struct file *filp,
@@ -263,7 +260,7 @@ static int sel_mmap_handle_status(struct file *filp,
 
 static const struct file_operations sel_handle_status_ops = {
 	.open		= sel_open_handle_status,
-	.read		= sel_read_handle_status,
+	.read_iter	= sel_read_handle_status,
 	.mmap		= sel_mmap_handle_status,
 	.llseek		= generic_file_llseek,
 };
@@ -302,24 +299,24 @@ static ssize_t sel_write_disable(struct file *file, const char __user *buf,
 	kfree(page);
 	return length;
 }
+FOPS_WRITE_ITER_HELPER(sel_write_disable);
 
 static const struct file_operations sel_disable_ops = {
-	.write		= sel_write_disable,
+	.write_iter	= sel_write_disable_iter,
 	.llseek		= generic_file_llseek,
 };
 
-static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
-				   size_t count, loff_t *ppos)
+static ssize_t sel_read_policyvers(struct kiocb *iocb, struct iov_iter *to)
 {
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
 	length = scnprintf(tmpbuf, TMPBUFLEN, "%u", POLICYDB_VERSION_MAX);
-	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+	return simple_copy_to_iter(tmpbuf, &iocb->ki_pos, length, to);
 }
 
 static const struct file_operations sel_policyvers_ops = {
-	.read		= sel_read_policyvers,
+	.read_iter	= sel_read_policyvers,
 	.llseek		= generic_file_llseek,
 };
 
@@ -339,19 +336,18 @@ static struct dentry *sel_make_dir(struct dentry *dir, const char *name,
 static struct dentry *sel_make_swapover_dir(struct super_block *sb,
 						unsigned long *ino);
 
-static ssize_t sel_read_mls(struct file *filp, char __user *buf,
-				size_t count, loff_t *ppos)
+static ssize_t sel_read_mls(struct kiocb *iocb, struct iov_iter *to)
 {
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
 	length = scnprintf(tmpbuf, TMPBUFLEN, "%d",
 			   security_mls_enabled());
-	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+	return simple_copy_to_iter(tmpbuf, &iocb->ki_pos, length, to);
 }
 
 static const struct file_operations sel_mls_ops = {
-	.read		= sel_read_mls,
+	.read_iter	= sel_read_mls,
 	.llseek		= generic_file_llseek,
 };
 
@@ -425,10 +421,9 @@ static int sel_release_policy(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static ssize_t sel_read_policy(struct file *filp, char __user *buf,
-			       size_t count, loff_t *ppos)
+static ssize_t sel_read_policy(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct policy_load_memory *plm = filp->private_data;
+	struct policy_load_memory *plm = iocb->ki_filp->private_data;
 	int ret;
 
 	ret = avc_has_perm(current_sid(), SECINITSID_SECURITY,
@@ -436,7 +431,7 @@ static ssize_t sel_read_policy(struct file *filp, char __user *buf,
 	if (ret)
 		return ret;
 
-	return simple_read_from_buffer(buf, count, ppos, plm->data, plm->len);
+	return simple_copy_to_iter(plm->data, &iocb->ki_pos, plm->len, to);
 }
 
 static vm_fault_t sel_mmap_policy_fault(struct vm_fault *vmf)
@@ -483,7 +478,7 @@ static int sel_mmap_policy(struct file *filp, struct vm_area_struct *vma)
 
 static const struct file_operations sel_policy_ops = {
 	.open		= sel_open_policy,
-	.read		= sel_read_policy,
+	.read_iter	= sel_read_policy,
 	.mmap		= sel_mmap_policy,
 	.release	= sel_release_policy,
 	.llseek		= generic_file_llseek,
@@ -567,12 +562,13 @@ static int sel_make_policy_nodes(struct selinux_fs_info *fsi,
 	return ret;
 }
 
-static ssize_t sel_write_load(struct file *file, const char __user *buf,
-			      size_t count, loff_t *ppos)
+static ssize_t sel_write_load(struct kiocb *iocb, struct iov_iter *from)
 
 {
+	struct file *file = iocb->ki_filp;
 	struct selinux_fs_info *fsi = file_inode(file)->i_sb->s_fs_info;
 	struct selinux_load_state load_state;
+	size_t count = iov_iter_count(from);
 	ssize_t length;
 	void *data = NULL;
 
@@ -585,7 +581,7 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
 
 	/* No partial writes. */
 	length = -EINVAL;
-	if (*ppos != 0)
+	if (iocb->ki_pos != 0)
 		goto out;
 
 	length = -ENOMEM;
@@ -594,7 +590,7 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
 		goto out;
 
 	length = -EFAULT;
-	if (copy_from_user(data, buf, count) != 0)
+	if (!copy_from_iter_full(data, count, from))
 		goto out;
 
 	length = security_load_policy(data, count, &load_state);
@@ -625,7 +621,7 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
 }
 
 static const struct file_operations sel_load_ops = {
-	.write		= sel_write_load,
+	.write_iter	= sel_write_load,
 	.llseek		= generic_file_llseek,
 };
 
@@ -662,15 +658,14 @@ static ssize_t sel_write_context(struct file *file, char *buf, size_t size)
 	return length;
 }
 
-static ssize_t sel_read_checkreqprot(struct file *filp, char __user *buf,
-				     size_t count, loff_t *ppos)
+static ssize_t sel_read_checkreqprot(struct kiocb *iocb, struct iov_iter *to)
 {
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
 	length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
 			   checkreqprot_get());
-	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+	return simple_copy_to_iter(tmpbuf, &iocb->ki_pos, length, to);
 }
 
 static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf,
@@ -717,9 +712,11 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf,
 	kfree(page);
 	return length;
 }
+FOPS_WRITE_ITER_HELPER(sel_write_checkreqprot);
+
 static const struct file_operations sel_checkreqprot_ops = {
-	.read		= sel_read_checkreqprot,
-	.write		= sel_write_checkreqprot,
+	.read_iter	= sel_read_checkreqprot,
+	.write_iter	= sel_write_checkreqprot_iter,
 	.llseek		= generic_file_llseek,
 };
 
@@ -793,9 +790,10 @@ static ssize_t sel_write_validatetrans(struct file *file,
 	kfree(taskcon);
 	return rc;
 }
+FOPS_WRITE_ITER_HELPER(sel_write_validatetrans);
 
 static const struct file_operations sel_transition_ops = {
-	.write		= sel_write_validatetrans,
+	.write_iter	= sel_write_validatetrans_iter,
 	.llseek		= generic_file_llseek,
 };
 
@@ -837,10 +835,11 @@ static ssize_t selinux_transaction_write(struct file *file, const char __user *b
 	}
 	return rv;
 }
+FOPS_WRITE_ITER_HELPER(selinux_transaction_write);
 
 static const struct file_operations transaction_ops = {
-	.write		= selinux_transaction_write,
-	.read		= simple_transaction_read,
+	.write_iter	= selinux_transaction_write_iter,
+	.read_iter	= simple_transaction_read_iter,
 	.release	= simple_transaction_release,
 	.llseek		= generic_file_llseek,
 };
@@ -1192,9 +1191,9 @@ static struct inode *sel_make_inode(struct super_block *sb, umode_t mode)
 	return ret;
 }
 
-static ssize_t sel_read_bool(struct file *filep, char __user *buf,
-			     size_t count, loff_t *ppos)
+static ssize_t sel_read_bool(struct kiocb *iocb, struct iov_iter *to)
 {
+	struct file *filep = iocb->ki_filp;
 	struct selinux_fs_info *fsi = file_inode(filep)->i_sb->s_fs_info;
 	char *page = NULL;
 	ssize_t length;
@@ -1223,7 +1222,7 @@ static ssize_t sel_read_bool(struct file *filep, char __user *buf,
 	length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,
 			  fsi->bool_pending_values[index]);
 	mutex_unlock(&selinux_state.policy_mutex);
-	ret = simple_read_from_buffer(buf, count, ppos, page, length);
+	ret = simple_copy_to_iter(page, &iocb->ki_pos, length, to);
 out_free:
 	free_page((unsigned long)page);
 	return ret;
@@ -1282,10 +1281,11 @@ static ssize_t sel_write_bool(struct file *filep, const char __user *buf,
 	kfree(page);
 	return length;
 }
+FOPS_WRITE_ITER_HELPER(sel_write_bool);
 
 static const struct file_operations sel_bool_ops = {
-	.read		= sel_read_bool,
-	.write		= sel_write_bool,
+	.read_iter	= sel_read_bool,
+	.write_iter	= sel_write_bool_iter,
 	.llseek		= generic_file_llseek,
 };
 
@@ -1334,9 +1334,10 @@ static ssize_t sel_commit_bools_write(struct file *filep,
 	kfree(page);
 	return length;
 }
+FOPS_WRITE_ITER_HELPER(sel_commit_bools_write);
 
 static const struct file_operations sel_commit_bools_ops = {
-	.write		= sel_commit_bools_write,
+	.write_iter	= sel_commit_bools_write_iter,
 	.llseek		= generic_file_llseek,
 };
 
@@ -1404,15 +1405,15 @@ static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_
 	return ret;
 }
 
-static ssize_t sel_read_avc_cache_threshold(struct file *filp, char __user *buf,
-					    size_t count, loff_t *ppos)
+static ssize_t sel_read_avc_cache_threshold(struct kiocb *iocb,
+					    struct iov_iter *to)
 {
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
 	length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
 			   avc_get_cache_threshold());
-	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+	return simple_copy_to_iter(tmpbuf, &iocb->ki_pos, length, to);
 }
 
 static ssize_t sel_write_avc_cache_threshold(struct file *file,
@@ -1452,9 +1453,9 @@ static ssize_t sel_write_avc_cache_threshold(struct file *file,
 	kfree(page);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(sel_write_avc_cache_threshold);
 
-static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
-				       size_t count, loff_t *ppos)
+static ssize_t sel_read_avc_hash_stats(struct kiocb *iocb, struct iov_iter *to)
 {
 	char *page;
 	ssize_t length;
@@ -1465,14 +1466,14 @@ static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
 
 	length = avc_get_hash_stats(page);
 	if (length >= 0)
-		length = simple_read_from_buffer(buf, count, ppos, page, length);
+		length = simple_copy_to_iter(page, &iocb->ki_pos, length, to);
 	free_page((unsigned long)page);
 
 	return length;
 }
 
-static ssize_t sel_read_sidtab_hash_stats(struct file *filp, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t sel_read_sidtab_hash_stats(struct kiocb *iocb,
+					  struct iov_iter *to)
 {
 	char *page;
 	ssize_t length;
@@ -1483,26 +1484,25 @@ static ssize_t sel_read_sidtab_hash_stats(struct file *filp, char __user *buf,
 
 	length = security_sidtab_hash_stats(page);
 	if (length >= 0)
-		length = simple_read_from_buffer(buf, count, ppos, page,
-						length);
+		length = simple_copy_to_iter(page, &iocb->ki_pos, length, to);
 	free_page((unsigned long)page);
 
 	return length;
 }
 
 static const struct file_operations sel_sidtab_hash_stats_ops = {
-	.read		= sel_read_sidtab_hash_stats,
+	.read_iter	= sel_read_sidtab_hash_stats,
 	.llseek		= generic_file_llseek,
 };
 
 static const struct file_operations sel_avc_cache_threshold_ops = {
-	.read		= sel_read_avc_cache_threshold,
-	.write		= sel_write_avc_cache_threshold,
+	.read_iter	= sel_read_avc_cache_threshold,
+	.write_iter	= sel_write_avc_cache_threshold_iter,
 	.llseek		= generic_file_llseek,
 };
 
 static const struct file_operations sel_avc_hash_stats_ops = {
-	.read		= sel_read_avc_hash_stats,
+	.read_iter	= sel_read_avc_hash_stats,
 	.llseek		= generic_file_llseek,
 };
 
@@ -1571,7 +1571,7 @@ static int sel_open_avc_cache_stats(struct inode *inode, struct file *file)
 
 static const struct file_operations sel_avc_cache_stats_ops = {
 	.open		= sel_open_avc_cache_stats,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= seq_release,
 };
@@ -1644,25 +1644,24 @@ static int sel_make_ss_files(struct dentry *dir)
 	return 0;
 }
 
-static ssize_t sel_read_initcon(struct file *file, char __user *buf,
-				size_t count, loff_t *ppos)
+static ssize_t sel_read_initcon(struct kiocb *iocb, struct iov_iter *to)
 {
 	char *con;
 	u32 sid, len;
 	ssize_t ret;
 
-	sid = file_inode(file)->i_ino&SEL_INO_MASK;
+	sid = file_inode(iocb->ki_filp)->i_ino&SEL_INO_MASK;
 	ret = security_sid_to_context(sid, &con, &len);
 	if (ret)
 		return ret;
 
-	ret = simple_read_from_buffer(buf, count, ppos, con, len);
+	ret = simple_copy_to_iter(con, &iocb->ki_pos, len, to);
 	kfree(con);
 	return ret;
 }
 
 static const struct file_operations sel_initcon_ops = {
-	.read		= sel_read_initcon,
+	.read_iter	= sel_read_initcon,
 	.llseek		= generic_file_llseek,
 };
 
@@ -1715,50 +1714,47 @@ static inline u32 sel_ino_to_perm(unsigned long ino)
 	return (ino & SEL_INO_MASK) % (SEL_VEC_MAX + 1);
 }
 
-static ssize_t sel_read_class(struct file *file, char __user *buf,
-				size_t count, loff_t *ppos)
+static ssize_t sel_read_class(struct kiocb *iocb, struct iov_iter *to)
 {
-	unsigned long ino = file_inode(file)->i_ino;
+	unsigned long ino = file_inode(iocb->ki_filp)->i_ino;
 	char res[TMPBUFLEN];
 	ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
-	return simple_read_from_buffer(buf, count, ppos, res, len);
+	return simple_copy_to_iter(res, &iocb->ki_pos, len, to);
 }
 
 static const struct file_operations sel_class_ops = {
-	.read		= sel_read_class,
+	.read_iter	= sel_read_class,
 	.llseek		= generic_file_llseek,
 };
 
-static ssize_t sel_read_perm(struct file *file, char __user *buf,
-				size_t count, loff_t *ppos)
+static ssize_t sel_read_perm(struct kiocb *iocb, struct iov_iter *to)
 {
-	unsigned long ino = file_inode(file)->i_ino;
+	unsigned long ino = file_inode(iocb->ki_filp)->i_ino;
 	char res[TMPBUFLEN];
 	ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_perm(ino));
-	return simple_read_from_buffer(buf, count, ppos, res, len);
+	return simple_copy_to_iter(res, &iocb->ki_pos, len, to);
 }
 
 static const struct file_operations sel_perm_ops = {
-	.read		= sel_read_perm,
+	.read_iter	= sel_read_perm,
 	.llseek		= generic_file_llseek,
 };
 
-static ssize_t sel_read_policycap(struct file *file, char __user *buf,
-				  size_t count, loff_t *ppos)
+static ssize_t sel_read_policycap(struct kiocb *iocb, struct iov_iter *to)
 {
 	int value;
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
-	unsigned long i_ino = file_inode(file)->i_ino;
+	unsigned long i_ino = file_inode(iocb->ki_filp)->i_ino;
 
 	value = security_policycap_supported(i_ino & SEL_INO_MASK);
 	length = scnprintf(tmpbuf, TMPBUFLEN, "%d", value);
 
-	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+	return simple_copy_to_iter(tmpbuf, &iocb->ki_pos, length, to);
 }
 
 static const struct file_operations sel_policycap_ops = {
-	.read		= sel_read_policycap,
+	.read_iter	= sel_read_policycap,
 	.llseek		= generic_file_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#99 lore raw

PATCH 93/437 integrity: convert to read/write iterators

In reply to Jens Axboe
---
 security/integrity/evm/evm_secfs.c | 60 +++++++++++++-----------------
 security/integrity/ima/ima_fs.c    | 41 ++++++++++----------
 2 files changed, 44 insertions(+), 57 deletions(-)
security/integrity/evm/evm_secfs.c +25 -35
index 9b907c2fee60..2ff3b5d04eae 100644
@@ -29,50 +29,45 @@ static int evm_xattrs_locked;
 /**
  * evm_read_key - read() for <securityfs>/evm
  *
- * @filp: file pointer, not actually used
- * @buf: where to put the result
- * @count: maximum to send along
- * @ppos: where to start
+ * @iocb: metadata for IO
+ * @to: where to put the result
  *
  * Returns number of bytes read or error code, as appropriate
  */
-static ssize_t evm_read_key(struct file *filp, char __user *buf,
-			    size_t count, loff_t *ppos)
+static ssize_t evm_read_key(struct kiocb *iocb, struct iov_iter *to)
 {
 	char temp[80];
 	ssize_t rc;
 
-	if (*ppos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	sprintf(temp, "%d", (evm_initialized & ~EVM_SETUP_COMPLETE));
-	rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
+	rc = simple_copy_to_iter(temp, &iocb->ki_pos, strlen(temp), to);
 
 	return rc;
 }
 
 /**
  * evm_write_key - write() for <securityfs>/evm
- * @file: file pointer, not actually used
- * @buf: where to get the data from
- * @count: bytes sent
- * @ppos: where to start
+ * @iocb: metadata for IO
+ * @from: where to get the data from
  *
  * Used to signal that key is on the kernel key ring.
  * - get the integrity hmac key from the kernel key ring
  * - create list of hmac protected extended attributes
  * Returns number of bytes written or error code, as appropriate
  */
-static ssize_t evm_write_key(struct file *file, const char __user *buf,
-			     size_t count, loff_t *ppos)
+static ssize_t evm_write_key(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	unsigned int i;
 	int ret;
 
 	if (!capable(CAP_SYS_ADMIN) || (evm_initialized & EVM_SETUP_COMPLETE))
 		return -EPERM;
 
-	ret = kstrtouint_from_user(buf, count, 0, &i);
+	ret = kstrtouint_from_iter(from, count, 0, &i);
 
 	if (ret)
 		return ret;
@@ -109,30 +104,27 @@ static ssize_t evm_write_key(struct file *file, const char __user *buf,
 }
 
 static const struct file_operations evm_key_ops = {
-	.read		= evm_read_key,
-	.write		= evm_write_key,
+	.read_iter	= evm_read_key,
+	.write_iter	= evm_write_key,
 };
 
 #ifdef CONFIG_EVM_ADD_XATTRS
 /**
  * evm_read_xattrs - read() for <securityfs>/evm_xattrs
  *
- * @filp: file pointer, not actually used
- * @buf: where to put the result
- * @count: maximum to send along
- * @ppos: where to start
+ * @iocb: metadata for IO
+ * @to: where to put the result
  *
  * Returns number of bytes read or error code, as appropriate
  */
-static ssize_t evm_read_xattrs(struct file *filp, char __user *buf,
-			       size_t count, loff_t *ppos)
+static ssize_t evm_read_xattrs(struct kiocb *iocb, struct iov_iter *to)
 {
 	char *temp;
 	int offset = 0;
 	ssize_t rc, size = 0;
 	struct xattr_list *xattr;
 
-	if (*ppos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	rc = mutex_lock_interruptible(&xattr_list_mutex);
@@ -161,7 +153,7 @@ static ssize_t evm_read_xattrs(struct file *filp, char __user *buf,
 	}
 
 	mutex_unlock(&xattr_list_mutex);
-	rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
+	rc = simple_copy_to_iter(temp, &iocb->ki_pos, strlen(temp), to);
 
 	kfree(temp);
 
@@ -170,26 +162,24 @@ static ssize_t evm_read_xattrs(struct file *filp, char __user *buf,
 
 /**
  * evm_write_xattrs - write() for <securityfs>/evm_xattrs
- * @file: file pointer, not actually used
- * @buf: where to get the data from
- * @count: bytes sent
- * @ppos: where to start
+ * @iocb: metadata for IO
+ * @from: where to get the data from
  *
  * Returns number of bytes written or error code, as appropriate
  */
-static ssize_t evm_write_xattrs(struct file *file, const char __user *buf,
-				size_t count, loff_t *ppos)
+static ssize_t evm_write_xattrs(struct kiocb *iocb, struct iov_iter *from)
 {
 	int len, err;
 	struct xattr_list *xattr, *tmp;
 	struct audit_buffer *ab;
 	struct iattr newattrs;
 	struct inode *inode;
+	size_t count = iov_iter_count(from);
 
 	if (!capable(CAP_SYS_ADMIN) || evm_xattrs_locked)
 		return -EPERM;
 
-	if (*ppos != 0)
+	if (iocb->ki_pos != 0)
 		return -EINVAL;
 
 	if (count > XATTR_NAME_MAX)
@@ -207,7 +197,7 @@ static ssize_t evm_write_xattrs(struct file *file, const char __user *buf,
 	}
 
 	xattr->enabled = true;
-	xattr->name = memdup_user_nul(buf, count);
+	xattr->name = iterdup_nul(from, count);
 	if (IS_ERR(xattr->name)) {
 		err = PTR_ERR(xattr->name);
 		xattr->name = NULL;
@@ -278,8 +268,8 @@ static ssize_t evm_write_xattrs(struct file *file, const char __user *buf,
 }
 
 static const struct file_operations evm_xattr_ops = {
-	.read		= evm_read_xattrs,
-	.write		= evm_write_xattrs,
+	.read_iter	= evm_read_xattrs,
+	.write_iter	= evm_write_xattrs,
 };
 
 static int evm_init_xattrs(void)
security/integrity/ima/ima_fs.c +19 -22

98 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#100 lore raw

PATCH 94/437 lockdown: convert to read/write iterators

In reply to Jens Axboe
---
 security/lockdown/lockdown.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
security/lockdown/lockdown.c +5 -5
index cd84d8ea1dfb..ea208d3251e6 100644
@@ -93,8 +93,7 @@ static int __init lockdown_lsm_init(void)
 	return 0;
 }
 
-static ssize_t lockdown_read(struct file *filp, char __user *buf, size_t count,
-			     loff_t *ppos)
+static ssize_t lockdown_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	char temp[80];
 	int i, offset = 0;
@@ -116,7 +115,7 @@ static ssize_t lockdown_read(struct file *filp, char __user *buf, size_t count,
 	if (offset > 0)
 		temp[offset-1] = '\n';
 
-	return simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
+	return simple_copy_to_iter(temp, &iocb->ki_pos, strlen(temp), to);
 }
 
 static ssize_t lockdown_write(struct file *file, const char __user *buf,
@@ -146,10 +145,11 @@ static ssize_t lockdown_write(struct file *file, const char __user *buf,
 	kfree(state);
 	return err ? err : n;
 }
+FOPS_WRITE_ITER_HELPER(lockdown_write);
 
 static const struct file_operations lockdown_ops = {
-	.read  = lockdown_read,
-	.write = lockdown_write,
+	.read_iter  = lockdown_read,
+	.write_iter = lockdown_write_iter,
 };
 
 static int __init lockdown_secfs_init(void)
Signature · 1 line
2.43.0
author maintainer
#101 lore raw

PATCH 95/437 security: convert to read/write iterators

In reply to Jens Axboe
---
 security/inode.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
security/inode.c +4 -5
index 9e7cde913667..81a7b43a0009 100644
@@ -315,15 +315,14 @@ EXPORT_SYMBOL_GPL(securityfs_remove);
 
 #ifdef CONFIG_SECURITY
 static struct dentry *lsm_dentry;
-static ssize_t lsm_read(struct file *filp, char __user *buf, size_t count,
-			loff_t *ppos)
+static ssize_t lsm_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	return simple_read_from_buffer(buf, count, ppos, lsm_names,
-		strlen(lsm_names));
+	return simple_copy_to_iter(lsm_names, &iocb->ki_pos, strlen(lsm_names),
+					to);
 }
 
 static const struct file_operations lsm_ops = {
-	.read = lsm_read,
+	.read_iter = lsm_read,
 	.llseek = generic_file_llseek,
 };
 #endif
Signature · 1 line
2.43.0
author maintainer
#102 lore raw

PATCH 96/437 mm: convert to read/write iterators

In reply to Jens Axboe
---
 mm/damon/dbgfs.c    | 84 ++++++++++++++++++++++++---------------------
 mm/huge_memory.c    | 10 +++---
 mm/kmemleak.c       |  5 +--
 mm/page_owner.c     |  5 +--
 mm/shrinker_debug.c | 12 +++----
 mm/slub.c           |  2 +-
 mm/vmscan.c         | 14 ++++----
 7 files changed, 69 insertions(+), 63 deletions(-)
mm/damon/dbgfs.c +44 -40
index 2461cfe2e968..1ee9d28ded80 100644
@@ -56,10 +56,9 @@ static char *user_input_str(const char __user *buf, size_t count, loff_t *ppos)
 	return kbuf;
 }
 
-static ssize_t dbgfs_attrs_read(struct file *file,
-		char __user *buf, size_t count, loff_t *ppos)
+static ssize_t dbgfs_attrs_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct damon_ctx *ctx = file->private_data;
+	struct damon_ctx *ctx = iocb->ki_filp->private_data;
 	char kbuf[128];
 	int ret;
 
@@ -70,7 +69,7 @@ static ssize_t dbgfs_attrs_read(struct file *file,
 			ctx->attrs.min_nr_regions, ctx->attrs.max_nr_regions);
 	mutex_unlock(&ctx->kdamond_lock);
 
-	return simple_read_from_buffer(buf, count, ppos, kbuf, ret);
+	return simple_copy_to_iter(kbuf, &iocb->ki_pos, ret, to);
 }
 
 static ssize_t dbgfs_attrs_write(struct file *file,
@@ -109,6 +108,7 @@ static ssize_t dbgfs_attrs_write(struct file *file,
 	kfree(kbuf);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(dbgfs_attrs_write);
 
 /*
  * Return corresponding dbgfs' scheme action value (int) for the given
@@ -169,10 +169,10 @@ static ssize_t sprint_schemes(struct damon_ctx *c, char *buf, ssize_t len)
 	return written;
 }
 
-static ssize_t dbgfs_schemes_read(struct file *file, char __user *buf,
-		size_t count, loff_t *ppos)
+static ssize_t dbgfs_schemes_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct damon_ctx *ctx = file->private_data;
+	struct damon_ctx *ctx = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	char *kbuf;
 	ssize_t len;
 
@@ -185,7 +185,7 @@ static ssize_t dbgfs_schemes_read(struct file *file, char __user *buf,
 	mutex_unlock(&ctx->kdamond_lock);
 	if (len < 0)
 		goto out;
-	len = simple_read_from_buffer(buf, count, ppos, kbuf, len);
+	len = simple_copy_to_iter(kbuf, &iocb->ki_pos, len, to);
 
 out:
 	kfree(kbuf);
@@ -329,6 +329,7 @@ static ssize_t dbgfs_schemes_write(struct file *file, const char __user *buf,
 	kfree(kbuf);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(dbgfs_schemes_write);
 
 static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
 {
@@ -356,10 +357,9 @@ static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
 	return written;
 }
 
-static ssize_t dbgfs_target_ids_read(struct file *file,
-		char __user *buf, size_t count, loff_t *ppos)
+static ssize_t dbgfs_target_ids_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct damon_ctx *ctx = file->private_data;
+	struct damon_ctx *ctx = iocb->ki_filp->private_data;
 	ssize_t len;
 	char ids_buf[320];
 
@@ -369,7 +369,7 @@ static ssize_t dbgfs_target_ids_read(struct file *file,
 	if (len < 0)
 		return len;
 
-	return simple_read_from_buffer(buf, count, ppos, ids_buf, len);
+	return simple_copy_to_iter(ids_buf, &iocb->ki_pos, len, to);
 }
 
 /*
@@ -548,6 +548,7 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
 	kfree(kbuf);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(dbgfs_target_ids_write);
 
 static ssize_t sprint_init_regions(struct damon_ctx *c, char *buf, ssize_t len)
 {
@@ -571,10 +572,10 @@ static ssize_t sprint_init_regions(struct damon_ctx *c, char *buf, ssize_t len)
 	return written;
 }
 
-static ssize_t dbgfs_init_regions_read(struct file *file, char __user *buf,
-		size_t count, loff_t *ppos)
+static ssize_t dbgfs_init_regions_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct damon_ctx *ctx = file->private_data;
+	struct damon_ctx *ctx = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	char *kbuf;
 	ssize_t len;
 
@@ -593,7 +594,7 @@ static ssize_t dbgfs_init_regions_read(struct file *file, char __user *buf,
 	mutex_unlock(&ctx->kdamond_lock);
 	if (len < 0)
 		goto out;
-	len = simple_read_from_buffer(buf, count, ppos, kbuf, len);
+	len = simple_copy_to_iter(kbuf, &iocb->ki_pos, len, to);
 
 out:
 	kfree(kbuf);
@@ -693,11 +694,12 @@ static ssize_t dbgfs_init_regions_write(struct file *file,
 	kfree(kbuf);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(dbgfs_init_regions_write);
 
-static ssize_t dbgfs_kdamond_pid_read(struct file *file,
-		char __user *buf, size_t count, loff_t *ppos)
+static ssize_t dbgfs_kdamond_pid_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct damon_ctx *ctx = file->private_data;
+	struct damon_ctx *ctx = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	char *kbuf;
 	ssize_t len;
 
@@ -713,7 +715,7 @@ static ssize_t dbgfs_kdamond_pid_read(struct file *file,
 	mutex_unlock(&ctx->kdamond_lock);
 	if (!len)
 		goto out;
-	len = simple_read_from_buffer(buf, count, ppos, kbuf, len);
+	len = simple_copy_to_iter(kbuf, &iocb->ki_pos, len, to);
 
 out:
 	kfree(kbuf);
@@ -731,31 +733,31 @@ static int damon_dbgfs_open(struct inode *inode, struct file *file)
 
 static const struct file_operations attrs_fops = {
 	.open = damon_dbgfs_open,
-	.read = dbgfs_attrs_read,
-	.write = dbgfs_attrs_write,
+	.read_iter = dbgfs_attrs_read,
+	.write_iter = dbgfs_attrs_write_iter,
 };
 
 static const struct file_operations schemes_fops = {
 	.open = damon_dbgfs_open,
-	.read = dbgfs_schemes_read,
-	.write = dbgfs_schemes_write,
+	.read_iter = dbgfs_schemes_read,
+	.write_iter = dbgfs_schemes_write_iter,
 };
 
 static const struct file_operations target_ids_fops = {
 	.open = damon_dbgfs_open,
-	.read = dbgfs_target_ids_read,
-	.write = dbgfs_target_ids_write,
+	.read_iter = dbgfs_target_ids_read,
+	.write_iter = dbgfs_target_ids_write_iter,
 };
 
 static const struct file_operations init_regions_fops = {
 	.open = damon_dbgfs_open,
-	.read = dbgfs_init_regions_read,
-	.write = dbgfs_init_regions_write,
+	.read_iter = dbgfs_init_regions_read,
+	.write_iter = dbgfs_init_regions_write_iter,
 };
 
 static const struct file_operations kdamond_pid_fops = {
 	.open = damon_dbgfs_open,
-	.read = dbgfs_kdamond_pid_read,
+	.read_iter = dbgfs_kdamond_pid_read,
 };
 
 static void dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx)
@@ -807,12 +809,12 @@ static void dbgfs_destroy_ctx(struct damon_ctx *ctx)
 	damon_destroy_ctx(ctx);
 }
 
-static ssize_t damon_dbgfs_deprecated_read(struct file *file,
-		char __user *buf, size_t count, loff_t *ppos)
+static ssize_t damon_dbgfs_deprecated_read(struct kiocb *iocb,
+					   struct iov_iter *to)
 {
 	static const char kbuf[512] = DAMON_DBGFS_DEPRECATION_NOTICE;
 
-	return simple_read_from_buffer(buf, count, ppos, kbuf, strlen(kbuf));
+	return simple_copy_to_iter(kbuf, &iocb->ki_pos, strlen(kbuf), to);
 }
 
 /*
@@ -900,6 +902,7 @@ static ssize_t dbgfs_mk_context_write(struct file *file,
 	kfree(ctx_name);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(dbgfs_mk_context_write);
 
 /*
  * Remove a context of @name and its debugfs directory.
@@ -1006,9 +1009,9 @@ static ssize_t dbgfs_rm_context_write(struct file *file,
 	kfree(ctx_name);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(dbgfs_rm_context_write);
 
-static ssize_t dbgfs_monitor_on_read(struct file *file,
-		char __user *buf, size_t count, loff_t *ppos)
+static ssize_t dbgfs_monitor_on_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	char monitor_on_buf[5];
 	bool monitor_on = damon_nr_running_ctxs() != 0;
@@ -1016,7 +1019,7 @@ static ssize_t dbgfs_monitor_on_read(struct file *file,
 
 	len = scnprintf(monitor_on_buf, 5, monitor_on ? "on\n" : "off\n");
 
-	return simple_read_from_buffer(buf, count, ppos, monitor_on_buf, len);
+	return simple_copy_to_iter(monitor_on_buf, &iocb->ki_pos, len, to);
 }
 
 static ssize_t dbgfs_monitor_on_write(struct file *file,
@@ -1059,6 +1062,7 @@ static ssize_t dbgfs_monitor_on_write(struct file *file,
 	kfree(kbuf);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(dbgfs_monitor_on_write);
 
 static int damon_dbgfs_static_file_open(struct inode *inode, struct file *file)
 {
@@ -1067,23 +1071,23 @@ static int damon_dbgfs_static_file_open(struct inode *inode, struct file *file)
 }
 
 static const struct file_operations deprecated_fops = {
-	.read = damon_dbgfs_deprecated_read,
+	.read_iter = damon_dbgfs_deprecated_read,
 };
 
 static const struct file_operations mk_contexts_fops = {
 	.open = damon_dbgfs_static_file_open,
-	.write = dbgfs_mk_context_write,
+	.write_iter = dbgfs_mk_context_write_iter,
 };
 
 static const struct file_operations rm_contexts_fops = {
 	.open = damon_dbgfs_static_file_open,
-	.write = dbgfs_rm_context_write,
+	.write_iter = dbgfs_rm_context_write_iter,
 };
 
 static const struct file_operations monitor_on_fops = {
 	.open = damon_dbgfs_static_file_open,
-	.read = dbgfs_monitor_on_read,
-	.write = dbgfs_monitor_on_write,
+	.read_iter = dbgfs_monitor_on_read,
+	.write_iter = dbgfs_monitor_on_write_iter,
 };
 
 static int __init __damon_dbgfs_init(void)
mm/huge_memory.c +5 -5
index 9859aa4f7553..989847ed0f92 100644
@@ -3582,8 +3582,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,
 
 #define MAX_INPUT_BUF_SZ 255
 
-static ssize_t split_huge_pages_write(struct file *file, const char __user *buf,
-				size_t count, loff_t *ppops)
+static ssize_t split_huge_pages_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	static DEFINE_MUTEX(split_debug_mutex);
 	ssize_t ret;
@@ -3594,6 +3593,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf,
 	char input_buf[MAX_INPUT_BUF_SZ];
 	int pid;
 	unsigned long vaddr_start, vaddr_end;
+	size_t count = iov_iter_count(from);
 	unsigned int new_order = 0;
 
 	ret = mutex_lock_interruptible(&split_debug_mutex);
@@ -3603,7 +3603,8 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf,
 	ret = -EFAULT;
 
 	memset(input_buf, 0, MAX_INPUT_BUF_SZ);
-	if (copy_from_user(input_buf, buf, min_t(size_t, count, MAX_INPUT_BUF_SZ)))
+	if (!copy_from_iter_full(input_buf,
+				 min_t(size_t, count, MAX_INPUT_BUF_SZ), from))
 		goto out;
 
 	input_buf[MAX_INPUT_BUF_SZ - 1] = '\0';
@@ -3651,12 +3652,11 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf,
 out:
 	mutex_unlock(&split_debug_mutex);
 	return ret;
-
 }
 
 static const struct file_operations split_huge_pages_fops = {
 	.owner	 = THIS_MODULE,
-	.write	 = split_huge_pages_write,
+	.write_iter = split_huge_pages_write,
 	.llseek  = no_llseek,
 };
 
mm/kmemleak.c +3 -2
index 6a540c2b27c5..3ff7dc613e70 100644
@@ -2063,12 +2063,13 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,
 	*ppos += size;
 	return size;
 }
+FOPS_WRITE_ITER_HELPER(kmemleak_write);
 
 static const struct file_operations kmemleak_fops = {
 	.owner		= THIS_MODULE,
 	.open		= kmemleak_open,
-	.read		= seq_read,
-	.write		= kmemleak_write,
+	.read_iter	= seq_read_iter,
+	.write_iter	= kmemleak_write_iter,
 	.llseek		= seq_lseek,
 	.release	= seq_release,
 };
mm/page_owner.c +3 -2
index d17d1351ec84..ab5cfbc718b4 100644
@@ -715,6 +715,7 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 
 	return 0;
 }
+FOPS_READ_ITER_HELPER(read_page_owner);
 
 static loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
 {
@@ -822,7 +823,7 @@ static void init_early_allocated_pages(void)
 }
 
 static const struct file_operations proc_page_owner_operations = {
-	.read		= read_page_owner,
+	.read_iter	= read_page_owner_iter,
 	.llseek		= lseek_page_owner,
 };
 
@@ -906,7 +907,7 @@ static int page_owner_stack_open(struct inode *inode, struct file *file)
 
 static const struct file_operations page_owner_stack_operations = {
 	.open		= page_owner_stack_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= seq_release,
 };
mm/shrinker_debug.c +6 -6
index 12ea5486a3e9..b3b4d5a36dc0 100644
@@ -101,11 +101,11 @@ static int shrinker_debugfs_scan_open(struct inode *inode, struct file *file)
 	return nonseekable_open(inode, file);
 }
 
-static ssize_t shrinker_debugfs_scan_write(struct file *file,
-					   const char __user *buf,
-					   size_t size, loff_t *pos)
+static ssize_t shrinker_debugfs_scan_write(struct kiocb *iocb,
+					   struct iov_iter *from)
 {
-	struct shrinker *shrinker = file->private_data;
+	struct shrinker *shrinker = iocb->ki_filp->private_data;
+	size_t size = iov_iter_count(from);
 	unsigned long nr_to_scan = 0, ino, read_len;
 	struct shrink_control sc = {
 		.gfp_mask = GFP_KERNEL,
@@ -115,7 +115,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
 	char kbuf[72];
 
 	read_len = size < (sizeof(kbuf) - 1) ? size : (sizeof(kbuf) - 1);
-	if (copy_from_user(kbuf, buf, read_len))
+	if (!copy_from_iter_full(kbuf, read_len, from))
 		return -EFAULT;
 	kbuf[read_len] = '\0';
 
@@ -156,7 +156,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
 static const struct file_operations shrinker_debugfs_scan_fops = {
 	.owner	 = THIS_MODULE,
 	.open	 = shrinker_debugfs_scan_open,
-	.write	 = shrinker_debugfs_scan_write,
+	.write_iter	 = shrinker_debugfs_scan_write,
 };
 
 int shrinker_debugfs_add(struct shrinker *shrinker)
mm/slub.c +1 -1
index 1bb2a93cf7b6..aff701599b6a 100644
@@ -7033,7 +7033,7 @@ static int slab_debug_trace_release(struct inode *inode, struct file *file)
 
 static const struct file_operations slab_debugfs_fops = {
 	.open    = slab_debug_trace_open,
-	.read    = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek  = seq_lseek,
 	.release = slab_debug_trace_release,
 };
mm/vmscan.c +7 -7
index 3ef654addd44..bf6e9292aea2 100644
@@ -5278,7 +5278,7 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec,
 static int lru_gen_seq_show(struct seq_file *m, void *v)
 {
 	unsigned long seq;
-	bool full = !debugfs_real_fops(m->file)->write;
+	bool full = !debugfs_real_fops(m->file)->write_iter;
 	struct lruvec *lruvec = v;
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 	int nid = lruvec_pgdat(lruvec)->node_id;
@@ -5434,9 +5434,9 @@ static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq,
 }
 
 /* see Documentation/admin-guide/mm/multigen_lru.rst for details */
-static ssize_t lru_gen_seq_write(struct file *file, const char __user *src,
-				 size_t len, loff_t *pos)
+static ssize_t lru_gen_seq_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t len = iov_iter_count(from);
 	void *buf;
 	char *cur, *next;
 	unsigned int flags;
@@ -5454,7 +5454,7 @@ static ssize_t lru_gen_seq_write(struct file *file, const char __user *src,
 	if (!buf)
 		return -ENOMEM;
 
-	if (copy_from_user(buf, src, len)) {
+	if (!copy_from_iter_full(buf, len, from)) {
 		kvfree(buf);
 		return -EFAULT;
 	}
@@ -5513,15 +5513,15 @@ static int lru_gen_seq_open(struct inode *inode, struct file *file)
 
 static const struct file_operations lru_gen_rw_fops = {
 	.open = lru_gen_seq_open,
-	.read = seq_read,
-	.write = lru_gen_seq_write,
+	.read_iter = seq_read_iter,
+	.write_iter = lru_gen_seq_write,
 	.llseek = seq_lseek,
 	.release = seq_release,
 };
 
 static const struct file_operations lru_gen_ro_fops = {
 	.open = lru_gen_seq_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = seq_release,
 };
Signature · 1 line
2.43.0
author maintainer
#103 lore raw

PATCH 97/437 aoe: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/block/aoe/aoechr.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/block/aoe/aoechr.c +8 -7
index a42c4bcc85ba..828499156a5f 100644
@@ -192,6 +192,7 @@ aoechr_write(struct file *filp, const char __user *buf, size_t cnt, loff_t *offp
 		ret = cnt;
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(aoechr_write);
 
 static int
 aoechr_open(struct inode *inode, struct file *filp)
@@ -217,16 +218,16 @@ aoechr_rel(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static ssize_t
-aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
+static ssize_t aoechr_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t cnt = iov_iter_count(to);
 	unsigned long n;
 	char *mp;
 	struct ErrMsg *em;
 	ssize_t len;
 	ulong flags;
 
-	n = (unsigned long) filp->private_data;
+	n = (unsigned long) iocb->ki_filp->private_data;
 	if (n != MINOR_ERR)
 		return -EFAULT;
 
@@ -236,7 +237,7 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
 		em = emsgs + emsgs_head_idx;
 		if ((em->flags & EMFL_VALID) != 0)
 			break;
-		if (filp->f_flags & O_NDELAY) {
+		if (iocb->ki_filp->f_flags & O_NDELAY) {
 			spin_unlock_irqrestore(&emsgs_lock, flags);
 			return -EAGAIN;
 		}
@@ -269,14 +270,14 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
 
 	spin_unlock_irqrestore(&emsgs_lock, flags);
 
-	n = copy_to_user(buf, mp, len);
+	n = !copy_to_iter_full(mp, len, to);
 	kfree(mp);
 	return n == 0 ? len : -EFAULT;
 }
 
 static const struct file_operations aoe_fops = {
-	.write = aoechr_write,
-	.read = aoechr_read,
+	.write_iter = aoechr_write_iter,
+	.read_iter = aoechr_read,
 	.open = aoechr_open,
 	.release = aoechr_rel,
 	.owner = THIS_MODULE,
Signature · 1 line
2.43.0
author maintainer
#104 lore raw

PATCH 98/437 drbd: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/block/drbd/drbd_debugfs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/block/drbd/drbd_debugfs.c +5 -5
index 12460b584bcb..b23baa80eb37 100644
@@ -457,7 +457,7 @@ static int in_flight_summary_release(struct inode *inode, struct file *file)
 static const struct file_operations in_flight_summary_fops = {
 	.owner		= THIS_MODULE,
 	.open		= in_flight_summary_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= in_flight_summary_release,
 };
@@ -565,7 +565,7 @@ static int callback_history_release(struct inode *inode, struct file *file)
 static const struct file_operations connection_callback_history_fops = {
 	.owner		= THIS_MODULE,
 	.open		= callback_history_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= callback_history_release,
 };
@@ -612,7 +612,7 @@ static int connection_oldest_requests_release(struct inode *inode, struct file *
 static const struct file_operations connection_oldest_requests_fops = {
 	.owner		= THIS_MODULE,
 	.open		= connection_oldest_requests_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= connection_oldest_requests_release,
 };
@@ -757,7 +757,7 @@ static int device_ ## name ## _release(struct inode *inode, struct file *file)	\
 static const struct file_operations device_ ## name ## _fops = {		\
 	.owner		= THIS_MODULE,						\
 	.open		= device_ ## name ## _open,				\
-	.read		= seq_read,						\
+	.read_iter	= seq_read_iter,					\
 	.llseek		= seq_lseek,						\
 	.release	= device_ ## name ## _release,				\
 };
@@ -859,7 +859,7 @@ static const struct file_operations drbd_version_fops = {
 	.owner = THIS_MODULE,
 	.open = drbd_version_open,
 	.llseek = seq_lseek,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.release = single_release,
 };
 
Signature · 1 line
2.43.0
author maintainer
#105 lore raw

PATCH 99/437 mtip32xx: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/block/mtip32xx/mtip32xx.c | 36 +++++++++++++++----------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +18 -18
index 43a187609ef7..28ea499cbbfd 100644
@@ -2162,13 +2162,13 @@ static const struct attribute_group *mtip_disk_attr_groups[] = {
 	NULL,
 };
 
-static ssize_t mtip_hw_read_registers(struct file *f, char __user *ubuf,
-				  size_t len, loff_t *offset)
+static ssize_t mtip_hw_read_registers(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct driver_data *dd =  (struct driver_data *)f->private_data;
+	struct driver_data *dd =  iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(to);
 	char *buf;
 	u32 group_allocated;
-	int size = *offset;
+	int size = iocb->ki_pos;
 	int n, rv = 0;
 
 	if (!len || size)
@@ -2217,21 +2217,21 @@ static ssize_t mtip_hw_read_registers(struct file *f, char __user *ubuf,
 	}
 	size += sprintf(&buf[size], "]\n");
 
-	*offset = size <= len ? size : len;
-	size = copy_to_user(ubuf, buf, *offset);
-	if (size)
+	iocb->ki_pos = size <= len ? size : len;
+	size = copy_to_iter(buf, iocb->ki_pos, to);
+	if (!size)
 		rv = -EFAULT;
 
 	kfree(buf);
-	return rv ? rv : *offset;
+	return rv ? rv : iocb->ki_pos;
 }
 
-static ssize_t mtip_hw_read_flags(struct file *f, char __user *ubuf,
-				  size_t len, loff_t *offset)
+static ssize_t mtip_hw_read_flags(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct driver_data *dd =  (struct driver_data *)f->private_data;
+	struct driver_data *dd =  iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(to);
 	char *buf;
-	int size = *offset;
+	int size = iocb->ki_pos;
 	int rv = 0;
 
 	if (!len || size)
@@ -2246,26 +2246,26 @@ static ssize_t mtip_hw_read_flags(struct file *f, char __user *ubuf,
 	size += sprintf(&buf[size], "Flag-dd   : [ %08lX ]\n",
 							dd->dd_flag);
 
-	*offset = size <= len ? size : len;
-	size = copy_to_user(ubuf, buf, *offset);
-	if (size)
+	iocb->ki_pos = size <= len ? size : len;
+	size = copy_to_iter(buf, iocb->ki_pos, to);
+	if (!size)
 		rv = -EFAULT;
 
 	kfree(buf);
-	return rv ? rv : *offset;
+	return rv ? rv : iocb->ki_pos;
 }
 
 static const struct file_operations mtip_regs_fops = {
 	.owner  = THIS_MODULE,
 	.open   = simple_open,
-	.read   = mtip_hw_read_registers,
+	.read_iter   = mtip_hw_read_registers,
 	.llseek = no_llseek,
 };
 
 static const struct file_operations mtip_flags_fops = {
 	.owner  = THIS_MODULE,
 	.open   = simple_open,
-	.read   = mtip_hw_read_flags,
+	.read_iter   = mtip_hw_read_flags,
 	.llseek = no_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#106 lore raw

PATCH 100/437 zram: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/block/zram/zram_drv.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/block/zram/zram_drv.c +7 -7
index f0639df6cd18..eac46889b4b2 100644
@@ -850,13 +850,13 @@ static void zram_debugfs_destroy(void)
 	debugfs_remove_recursive(zram_debugfs_root);
 }
 
-static ssize_t read_block_state(struct file *file, char __user *buf,
-				size_t count, loff_t *ppos)
+static ssize_t read_block_state(struct kiocb *iocb, struct iov_iter *to)
 {
 	char *kbuf;
 	ssize_t index, written = 0;
-	struct zram *zram = file->private_data;
+	struct zram *zram = iocb->ki_filp->private_data;
 	unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
+	size_t count = iov_iter_count(to);
 	struct timespec64 ts;
 
 	kbuf = kvmalloc(count, GFP_KERNEL);
@@ -870,7 +870,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
 		return -EINVAL;
 	}
 
-	for (index = *ppos; index < nr_pages; index++) {
+	for (index = iocb->ki_pos; index < nr_pages; index++) {
 		int copied;
 
 		zram_slot_lock(zram, index);
@@ -898,11 +898,11 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
 		count -= copied;
 next:
 		zram_slot_unlock(zram, index);
-		*ppos += 1;
+		iocb->ki_pos++;
 	}
 
 	up_read(&zram->init_lock);
-	if (copy_to_user(buf, kbuf, written))
+	if (!copy_to_iter(kbuf, written, to))
 		written = -EFAULT;
 	kvfree(kbuf);
 
@@ -911,7 +911,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
 
 static const struct file_operations proc_zram_block_state_op = {
 	.open = simple_open,
-	.read = read_block_state,
+	.read_iter = read_block_state,
 	.llseek = default_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#107 lore raw

PATCH 101/437 s390/dasd: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/s390/block/dasd.c      | 34 +++++++++++++++++++++++++++-------
 drivers/s390/block/dasd_eer.c  | 12 ++++++------
 drivers/s390/block/dasd_int.h  |  1 +
 drivers/s390/block/dasd_proc.c |  2 +-
 4 files changed, 35 insertions(+), 14 deletions(-)
drivers/s390/block/dasd.c +27 -7
index 0a97cfedd706..789e8c47e6ee 100644
@@ -897,6 +897,7 @@ void dasd_profile_off(struct dasd_profile *profile)
 	spin_unlock_bh(&profile->lock);
 }
 
+/* this can go away once proc is converted to ->write_iter() */
 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
 {
 	char *buffer;
@@ -916,18 +917,37 @@ char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
 	return buffer;
 }
 
-static ssize_t dasd_stats_write(struct file *file,
-				const char __user *user_buf,
-				size_t user_len, loff_t *pos)
+char *dasd_get_iter_string(struct iov_iter *from)
+{
+	size_t user_len = iov_iter_count(from);
+	char *buffer;
+
+	buffer = vmalloc(user_len + 1);
+	if (buffer == NULL)
+		return ERR_PTR(-ENOMEM);
+	if (!copy_from_iter_full(buffer, user_len, from)) {
+		vfree(buffer);
+		return ERR_PTR(-EFAULT);
+	}
+	/* got the string, now strip linefeed. */
+	if (buffer[user_len - 1] == '\n')
+		buffer[user_len - 1] = 0;
+	else
+		buffer[user_len] = 0;
+	return buffer;
+}
+
+static ssize_t dasd_stats_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	char *buffer, *str;
 	int rc;
-	struct seq_file *m = (struct seq_file *)file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct dasd_profile *prof = m->private;
+	size_t user_len = iov_iter_count(from);
 
 	if (user_len > 65536)
 		user_len = 65536;
-	buffer = dasd_get_user_string(user_buf, user_len);
+	buffer = dasd_get_iter_string(from);
 	if (IS_ERR(buffer))
 		return PTR_ERR(buffer);
 
@@ -1042,10 +1062,10 @@ static int dasd_stats_open(struct inode *inode, struct file *file)
 static const struct file_operations dasd_stats_raw_fops = {
 	.owner		= THIS_MODULE,
 	.open		= dasd_stats_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= single_release,
-	.write		= dasd_stats_write,
+	.write_iter	= dasd_stats_write,
 };
 
 static void dasd_profile_init(struct dasd_profile *profile,
drivers/s390/block/dasd_eer.c +6 -6
index 194e9e2d9cb8..476d6cf80089 100644
@@ -592,15 +592,15 @@ static int dasd_eer_close(struct inode *inp, struct file *filp)
 	return 0;
 }
 
-static ssize_t dasd_eer_read(struct file *filp, char __user *buf,
-			     size_t count, loff_t *ppos)
+static ssize_t dasd_eer_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	int tc,rc;
 	int tailcount,effective_count;
         unsigned long flags;
 	struct eerbuffer *eerb;
 
-	eerb = (struct eerbuffer *) filp->private_data;
+	eerb = (struct eerbuffer *) iocb->ki_filp->private_data;
 	if (mutex_lock_interruptible(&readbuffer_mutex))
 		return -ERESTARTSYS;
 
@@ -625,7 +625,7 @@ static ssize_t dasd_eer_read(struct file *filp, char __user *buf,
 				/* no data available */
 				spin_unlock_irqrestore(&bufferlock, flags);
 				mutex_unlock(&readbuffer_mutex);
-				if (filp->f_flags & O_NONBLOCK)
+				if (iocb->ki_filp->f_flags & O_NONBLOCK)
 					return -EAGAIN;
 				rc = wait_event_interruptible(
 					dasd_eer_read_wait_queue,
@@ -647,7 +647,7 @@ static ssize_t dasd_eer_read(struct file *filp, char __user *buf,
 
 	spin_unlock_irqrestore(&bufferlock, flags);
 
-	if (copy_to_user(buf, readbuffer, effective_count)) {
+	if (!copy_to_iter_full(readbuffer, effective_count, to)) {
 		mutex_unlock(&readbuffer_mutex);
 		return -EFAULT;
 	}
@@ -676,7 +676,7 @@ static __poll_t dasd_eer_poll(struct file *filp, poll_table *ptable)
 static const struct file_operations dasd_eer_fops = {
 	.open		= &dasd_eer_open,
 	.release	= &dasd_eer_close,
-	.read		= &dasd_eer_read,
+	.read_iter	= &dasd_eer_read,
 	.poll		= &dasd_eer_poll,
 	.owner		= THIS_MODULE,
 	.llseek		= noop_llseek,
drivers/s390/block/dasd_int.h +1 -0
index e5f40536b425..be7d6875b054 100644
@@ -897,6 +897,7 @@ void dasd_profile_reset(struct dasd_profile *);
 int dasd_profile_on(struct dasd_profile *);
 void dasd_profile_off(struct dasd_profile *);
 char *dasd_get_user_string(const char __user *, size_t);
+char *dasd_get_iter_string(struct iov_iter *);
 
 /* externals in dasd_devmap.c */
 extern int dasd_max_devindex;
drivers/s390/block/dasd_proc.c +1 -1
index 0faaa437d9be..b97d1227b9b0 100644
@@ -317,7 +317,7 @@ static ssize_t dasd_stats_proc_write(struct file *file,
 
 static const struct proc_ops dasd_stats_proc_ops = {
 	.proc_open	= dasd_stats_proc_open,
-	.proc_read	= seq_read,
+	.proc_read_iter	= seq_read_iter,
 	.proc_lseek	= seq_lseek,
 	.proc_release	= single_release,
 	.proc_write	= dasd_stats_proc_write,
Signature · 1 line
2.43.0
author maintainer
#108 lore raw

PATCH 102/437 lib: convert to read/write iterators

In reply to Jens Axboe
---
 lib/dynamic_debug.c  |  5 +++--
 lib/kunit/debugfs.c  | 13 ++++++-------
 lib/test_firmware.c  | 10 ++++------
 lib/xz/xz_dec_test.c |  9 ++++-----
 4 files changed, 17 insertions(+), 20 deletions(-)
lib/dynamic_debug.c +3 -2
index c78f335fa981..534ad9218557 100644
@@ -1022,6 +1022,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
 	*offp += len;
 	return len;
 }
+FOPS_WRITE_ITER_HELPER(ddebug_proc_write);
 
 /*
  * Set the iterator to point to the first _ddebug object
@@ -1182,10 +1183,10 @@ static int ddebug_proc_open(struct inode *inode, struct file *file)
 static const struct file_operations ddebug_proc_fops = {
 	.owner = THIS_MODULE,
 	.open = ddebug_proc_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = seq_release_private,
-	.write = ddebug_proc_write
+	.write_iter = ddebug_proc_write_iter
 };
 
 static const struct proc_ops proc_fops = {
lib/kunit/debugfs.c +6 -7
index d548750a325a..ea7be601cf9e 100644
@@ -139,28 +139,27 @@ static int debugfs_run_open(struct inode *inode, struct file *file)
  *
  * Note: what is written to this file will not be saved.
  */
-static ssize_t debugfs_run(struct file *file,
-		const char __user *buf, size_t count, loff_t *ppos)
+static ssize_t debugfs_run(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct inode *f_inode = file->f_inode;
+	struct inode *f_inode = iocb->ki_filp->f_inode;
 	struct kunit_suite *suite = (struct kunit_suite *) f_inode->i_private;
 
 	__kunit_test_suites_init(&suite, 1);
 
-	return count;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations debugfs_results_fops = {
 	.open = debugfs_results_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = debugfs_release,
 };
 
 static const struct file_operations debugfs_run_fops = {
 	.open = debugfs_run_open,
-	.read = seq_read,
-	.write = debugfs_run,
+	.read_iter = seq_read_iter,
+	.write_iter = debugfs_run,
 	.llseek = seq_lseek,
 	.release = debugfs_release,
 };
lib/test_firmware.c +4 -6
index 9cfdcd6d21db..face875a52e2 100644
@@ -147,23 +147,21 @@ static struct test_firmware_upload *upload_lookup_name(const char *name)
 	return NULL;
 }
 
-static ssize_t test_fw_misc_read(struct file *f, char __user *buf,
-				 size_t size, loff_t *offset)
+static ssize_t test_fw_misc_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	ssize_t rc = 0;
 
 	mutex_lock(&test_fw_mutex);
 	if (test_firmware)
-		rc = simple_read_from_buffer(buf, size, offset,
-					     test_firmware->data,
-					     test_firmware->size);
+		rc = simple_copy_to_iter(test_firmware->data, &iocb->ki_pos,
+					     test_firmware->size, to);
 	mutex_unlock(&test_fw_mutex);
 	return rc;
 }
 
 static const struct file_operations test_fw_fops = {
 	.owner          = THIS_MODULE,
-	.read           = test_fw_misc_read,
+	.read_iter      = test_fw_misc_read,
 };
 
 static void __test_release_all_firmware(void)
lib/xz/xz_dec_test.c +4 -5
index da28a19d6c98..42dc077e247b 100644
@@ -99,9 +99,9 @@ static int xz_dec_test_release(struct inode *i, struct file *f)
  * The .xz file must have exactly one Stream and no Stream Padding. The data
  * after the first Stream is considered to be garbage.
  */
-static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
-				 size_t size, loff_t *pos)
+static ssize_t xz_dec_test_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t size = iov_iter_count(from);
 	size_t remaining;
 
 	if (ret != XZ_OK) {
@@ -122,10 +122,9 @@ static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
 		if (buffers.in_pos == buffers.in_size) {
 			buffers.in_pos = 0;
 			buffers.in_size = min(remaining, sizeof(buffer_in));
-			if (copy_from_user(buffer_in, buf, buffers.in_size))
+			if (!copy_from_iter_full(buffer_in, buffers.in_size, from))
 				return -EFAULT;
 
-			buf += buffers.in_size;
 			remaining -= buffers.in_size;
 		}
 
@@ -179,7 +178,7 @@ static int __init xz_dec_test_init(void)
 		.owner = THIS_MODULE,
 		.open = &xz_dec_test_open,
 		.release = &xz_dec_test_release,
-		.write = &xz_dec_test_write
+		.write_iter = &xz_dec_test_write
 	};
 
 	state = xz_dec_init(XZ_PREALLOC, DICT_MAX);
Signature · 1 line
2.43.0
author maintainer
#109 lore raw

PATCH 103/437 ipc: convert to read/write iterators

In reply to Jens Axboe
---
 ipc/mqueue.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
ipc/mqueue.c +4 -6
index 5eea4dc0509e..812b03cf4273 100644
@@ -632,10 +632,9 @@ static int mqueue_unlink(struct inode *dir, struct dentry *dentry)
 *	that are interesting from user point of view and aren't accessible
 *	through std routines)
 */
-static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
-				size_t count, loff_t *off)
+static ssize_t mqueue_read_file(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct inode *inode = file_inode(filp);
+	struct inode *inode = file_inode(iocb->ki_filp);
 	struct mqueue_inode_info *info = MQUEUE_I(inode);
 	char buffer[FILENT_SIZE];
 	ssize_t ret;
@@ -652,8 +651,7 @@ static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
 	spin_unlock(&info->lock);
 	buffer[sizeof(buffer)-1] = '\0';
 
-	ret = simple_read_from_buffer(u_data, count, off, buffer,
-				strlen(buffer));
+	ret = simple_copy_to_iter(buffer, &iocb->ki_pos, strlen(buffer), to);
 	if (ret <= 0)
 		return ret;
 
@@ -1663,7 +1661,7 @@ static const struct inode_operations mqueue_dir_inode_operations = {
 static const struct file_operations mqueue_file_operations = {
 	.flush = mqueue_flush_file,
 	.poll = mqueue_poll_file,
-	.read = mqueue_read_file,
+	.read_iter = mqueue_read_file,
 	.llseek = default_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#110 lore raw

PATCH 104/437 drivers/accel: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/accel/habanalabs/common/debugfs.c    | 307 +++++++++----------
 drivers/accel/habanalabs/common/habanalabs.h |   3 +-
 drivers/accel/ivpu/ivpu_debugfs.c            |  84 +++--
 3 files changed, 183 insertions(+), 211 deletions(-)
drivers/accel/habanalabs/common/debugfs.c +141 -166
index b1c88d1837d9..350dcfc5300e 100644
@@ -403,16 +403,16 @@ static int userptr_lookup_show(struct seq_file *s, void *data)
 	return 0;
 }
 
-static ssize_t userptr_lookup_write(struct file *file, const char __user *buf,
-		size_t count, loff_t *f_pos)
+static ssize_t userptr_lookup_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *s = file->private_data;
+	struct seq_file *s = iocb->ki_filp->private_data;
 	struct hl_debugfs_entry *entry = s->private;
 	struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
+	size_t count = iov_iter_count(from);
 	ssize_t rc;
 	u64 value;
 
-	rc = kstrtoull_from_user(buf, count, 16, &value);
+	rc = kstrtoull_from_iter(from, count, 16, &value);
 	if (rc)
 		return rc;
 
@@ -477,20 +477,20 @@ static int mmu_show(struct seq_file *s, void *data)
 	return 0;
 }
 
-static ssize_t mmu_asid_va_write(struct file *file, const char __user *buf,
-		size_t count, loff_t *f_pos)
+static ssize_t mmu_asid_va_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *s = file->private_data;
+	struct seq_file *s = iocb->ki_filp->private_data;
 	struct hl_debugfs_entry *entry = s->private;
 	struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
 	struct hl_device *hdev = dev_entry->hdev;
+	size_t count = iov_iter_count(from);
 	char kbuf[MMU_KBUF_SIZE] = {0};
 	char *c;
 	ssize_t rc;
 
 	if (count > sizeof(kbuf) - 1)
 		goto err;
-	if (copy_from_user(kbuf, buf, count))
+	if (!copy_from_iter_full(kbuf, count, from))
 		goto err;
 	kbuf[count] = 0;
 
@@ -538,21 +538,21 @@ static int mmu_ack_error(struct seq_file *s, void *data)
 	return -EINVAL;
 }
 
-static ssize_t mmu_ack_error_value_write(struct file *file,
-		const char __user *buf,
-		size_t count, loff_t *f_pos)
+static ssize_t mmu_ack_error_value_write(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct seq_file *s = file->private_data;
+	struct seq_file *s = iocb->ki_filp->private_data;
 	struct hl_debugfs_entry *entry = s->private;
 	struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
 	struct hl_device *hdev = dev_entry->hdev;
+	size_t count = iov_iter_count(from);
 	char kbuf[MMU_KBUF_SIZE] = {0};
 	ssize_t rc;
 
 	if (count > sizeof(kbuf) - 1)
 		goto err;
 
-	if (copy_from_user(kbuf, buf, count))
+	if (!copy_from_iter(kbuf, count, from))
 		goto err;
 
 	kbuf[count] = 0;
@@ -607,10 +607,9 @@ static int engines_show(struct seq_file *s, void *data)
 	return 0;
 }
 
-static ssize_t hl_memory_scrub(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_memory_scrub(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 	u64 val = hdev->memory_scrub_val;
 	int rc;
@@ -637,7 +636,7 @@ static ssize_t hl_memory_scrub(struct file *f, const char __user *buf,
 
 	if (rc)
 		return rc;
-	return count;
+	return iov_iter_count(from);
 }
 
 static bool hl_is_device_va(struct hl_device *hdev, u64 addr)
@@ -839,10 +838,9 @@ static int hl_access_mem(struct hl_device *hdev, u64 addr, u64 *val,
 	return rc;
 }
 
-static ssize_t hl_data_read32(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_data_read32(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 	u64 value64, addr = entry->addr;
 	char tmp_buf[32];
@@ -854,7 +852,7 @@ static ssize_t hl_data_read32(struct file *f, char __user *buf,
 		return 0;
 	}
 
-	if (*ppos)
+	if (iocb->ki_pos)
 		return 0;
 
 	rc = hl_access_mem(hdev, addr, &value64, DEBUGFS_READ32);
@@ -864,14 +862,13 @@ static ssize_t hl_data_read32(struct file *f, char __user *buf,
 	val = value64; /* downcast back to 32 */
 
 	sprintf(tmp_buf, "0x%08x\n", val);
-	return simple_read_from_buffer(buf, count, ppos, tmp_buf,
-			strlen(tmp_buf));
+	return simple_copy_to_iter(tmp_buf, &iocb->ki_pos, strlen(tmp_buf), to);
 }
 
-static ssize_t hl_data_write32(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_data_write32(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u64 value64, addr = entry->addr;
 	u32 value;
@@ -882,7 +879,7 @@ static ssize_t hl_data_write32(struct file *f, const char __user *buf,
 		return 0;
 	}
 
-	rc = kstrtouint_from_user(buf, count, 16, &value);
+	rc = kstrtouint_from_iter(from, count, 16, &value);
 	if (rc)
 		return rc;
 
@@ -894,10 +891,9 @@ static ssize_t hl_data_write32(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_data_read64(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_data_read64(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 	u64 addr = entry->addr;
 	char tmp_buf[32];
@@ -909,7 +905,7 @@ static ssize_t hl_data_read64(struct file *f, char __user *buf,
 		return 0;
 	}
 
-	if (*ppos)
+	if (iocb->ki_pos)
 		return 0;
 
 	rc = hl_access_mem(hdev, addr, &val, DEBUGFS_READ64);
@@ -917,14 +913,13 @@ static ssize_t hl_data_read64(struct file *f, char __user *buf,
 		return rc;
 
 	sprintf(tmp_buf, "0x%016llx\n", val);
-	return simple_read_from_buffer(buf, count, ppos, tmp_buf,
-			strlen(tmp_buf));
+	return simple_copy_to_iter(tmp_buf, &iocb->ki_pos, strlen(tmp_buf), to);
 }
 
-static ssize_t hl_data_write64(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_data_write64(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u64 addr = entry->addr;
 	u64 value;
@@ -935,7 +930,7 @@ static ssize_t hl_data_write64(struct file *f, const char __user *buf,
 		return 0;
 	}
 
-	rc = kstrtoull_from_user(buf, count, 16, &value);
+	rc = kstrtoull_from_iter(from, count, 16, &value);
 	if (rc)
 		return rc;
 
@@ -946,10 +941,10 @@ static ssize_t hl_data_write64(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_dma_size_write(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_dma_size_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u64 addr = entry->addr;
 	ssize_t rc;
@@ -959,7 +954,7 @@ static ssize_t hl_dma_size_write(struct file *f, const char __user *buf,
 		dev_warn_ratelimited(hdev->dev, "Can't DMA during reset\n");
 		return 0;
 	}
-	rc = kstrtouint_from_user(buf, count, 16, &size);
+	rc = kstrtouint_from_iter(from, count, 16, &size);
 	if (rc)
 		return rc;
 
@@ -1003,10 +998,11 @@ static ssize_t hl_dma_size_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_monitor_dump_trigger(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_monitor_dump_trigger(struct kiocb *iocb,
+				       struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u32 size, trig;
 	ssize_t rc;
@@ -1015,7 +1011,7 @@ static ssize_t hl_monitor_dump_trigger(struct file *f, const char __user *buf,
 		dev_warn_ratelimited(hdev->dev, "Can't dump monitors during reset\n");
 		return 0;
 	}
-	rc = kstrtouint_from_user(buf, count, 10, &trig);
+	rc = kstrtouint_from_iter(from, count, 10, &trig);
 	if (rc)
 		return rc;
 
@@ -1047,15 +1043,14 @@ static ssize_t hl_monitor_dump_trigger(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_get_power_state(struct file *f, char __user *buf,
-		size_t count, loff_t *ppos)
+static ssize_t hl_get_power_state(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 	char tmp_buf[200];
 	int i;
 
-	if (*ppos)
+	if (iocb->ki_pos)
 		return 0;
 
 	if (hdev->pdev->current_state == PCI_D0)
@@ -1067,19 +1062,18 @@ static ssize_t hl_get_power_state(struct file *f, char __user *buf,
 
 	sprintf(tmp_buf,
 		"current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i);
-	return simple_read_from_buffer(buf, count, ppos, tmp_buf,
-			strlen(tmp_buf));
+	return simple_copy_to_iter(tmp_buf, &iocb->ki_pos, strlen(tmp_buf), to);
 }
 
-static ssize_t hl_set_power_state(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_set_power_state(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u32 value;
 	ssize_t rc;
 
-	rc = kstrtouint_from_user(buf, count, 10, &value);
+	rc = kstrtouint_from_iter(from, count, 10, &value);
 	if (rc)
 		return rc;
 
@@ -1101,16 +1095,15 @@ static ssize_t hl_set_power_state(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_i2c_data_read(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_i2c_data_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 	char tmp_buf[32];
 	u64 val;
 	ssize_t rc;
 
-	if (*ppos)
+	if (iocb->ki_pos)
 		return 0;
 
 	rc = hl_debugfs_i2c_read(hdev, entry->i2c_bus, entry->i2c_addr,
@@ -1123,21 +1116,18 @@ static ssize_t hl_i2c_data_read(struct file *f, char __user *buf,
 	}
 
 	sprintf(tmp_buf, "%#02llx\n", val);
-	rc = simple_read_from_buffer(buf, count, ppos, tmp_buf,
-			strlen(tmp_buf));
-
-	return rc;
+	return simple_copy_to_iter(tmp_buf, &iocb->ki_pos, strlen(tmp_buf), to);
 }
 
-static ssize_t hl_i2c_data_write(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_i2c_data_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u64 value;
 	ssize_t rc;
 
-	rc = kstrtou64_from_user(buf, count, 16, &value);
+	rc = kstrtou64_from_iter(from, count, 16, &value);
 	if (rc)
 		return rc;
 
@@ -1153,15 +1143,15 @@ static ssize_t hl_i2c_data_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_led0_write(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_led0_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u32 value;
 	ssize_t rc;
 
-	rc = kstrtouint_from_user(buf, count, 10, &value);
+	rc = kstrtouint_from_iter(from, count, 10, &value);
 	if (rc)
 		return rc;
 
@@ -1172,15 +1162,15 @@ static ssize_t hl_led0_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_led1_write(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_led1_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u32 value;
 	ssize_t rc;
 
-	rc = kstrtouint_from_user(buf, count, 10, &value);
+	rc = kstrtouint_from_iter(from, count, 10, &value);
 	if (rc)
 		return rc;
 
@@ -1191,15 +1181,15 @@ static ssize_t hl_led1_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_led2_write(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_led2_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u32 value;
 	ssize_t rc;
 
-	rc = kstrtouint_from_user(buf, count, 10, &value);
+	rc = kstrtouint_from_iter(from, count, 10, &value);
 	if (rc)
 		return rc;
 
@@ -1210,26 +1200,25 @@ static ssize_t hl_led2_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_device_read(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_device_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	static const char *help =
 		"Valid values: disable, enable, suspend, resume, cpu_timeout\n";
-	return simple_read_from_buffer(buf, count, ppos, help, strlen(help));
+	return simple_copy_to_iter(help, &iocb->ki_pos, strlen(help), to);
 }
 
-static ssize_t hl_device_write(struct file *f, const char __user *buf,
-				     size_t count, loff_t *ppos)
+static ssize_t hl_device_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
+	size_t count = iov_iter_count(from);
 	char data[30] = {0};
 
 	/* don't allow partial writes */
-	if (*ppos != 0)
+	if (iocb->ki_pos)
 		return 0;
 
-	simple_write_to_buffer(data, 29, ppos, buf, count);
+	simple_copy_from_iter(data, &iocb->ki_pos, 29, from);
 
 	if (strncmp("disable", data, strlen("disable")) == 0) {
 		hdev->disabled = true;
@@ -1250,43 +1239,36 @@ static ssize_t hl_device_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_clk_gate_read(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_clk_gate_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	return 0;
 }
 
-static ssize_t hl_clk_gate_write(struct file *f, const char __user *buf,
-				     size_t count, loff_t *ppos)
+static ssize_t hl_clk_gate_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	return count;
+	return iov_iter_count(from);
 }
 
-static ssize_t hl_stop_on_err_read(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_stop_on_err_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 	char tmp_buf[200];
-	ssize_t rc;
 
 	if (!hdev->asic_prop.configurable_stop_on_err)
 		return -EOPNOTSUPP;
 
-	if (*ppos)
+	if (iocb->ki_pos)
 		return 0;
 
 	sprintf(tmp_buf, "%d\n", hdev->stop_on_err);
-	rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
-			strlen(tmp_buf) + 1);
-
-	return rc;
+	return simple_copy_to_iter(tmp_buf, &iocb->ki_pos, strlen(tmp_buf) + 1, to);
 }
 
-static ssize_t hl_stop_on_err_write(struct file *f, const char __user *buf,
-				     size_t count, loff_t *ppos)
+static ssize_t hl_stop_on_err_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u32 value;
 	ssize_t rc;
@@ -1300,7 +1282,7 @@ static ssize_t hl_stop_on_err_write(struct file *f, const char __user *buf,
 		return 0;
 	}
 
-	rc = kstrtouint_from_user(buf, count, 10, &value);
+	rc = kstrtouint_from_iter(from, count, 10, &value);
 	if (rc)
 		return rc;
 
@@ -1311,10 +1293,10 @@ static ssize_t hl_stop_on_err_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_security_violations_read(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_security_violations_read(struct kiocb *iocb,
+					   struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 
 	hdev->asic_funcs->ack_protection_bits_errors(hdev);
@@ -1322,35 +1304,34 @@ static ssize_t hl_security_violations_read(struct file *f, char __user *buf,
 	return 0;
 }
 
-static ssize_t hl_state_dump_read(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_state_dump_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	ssize_t rc;
 
 	down_read(&entry->state_dump_sem);
 	if (!entry->state_dump[entry->state_dump_head])
 		rc = 0;
 	else
-		rc = simple_read_from_buffer(
-			buf, count, ppos,
+		rc = simple_copy_to_iter(
 			entry->state_dump[entry->state_dump_head],
-			strlen(entry->state_dump[entry->state_dump_head]));
+			&iocb->ki_pos,
+			strlen(entry->state_dump[entry->state_dump_head]), to);
 	up_read(&entry->state_dump_sem);
 
 	return rc;
 }
 
-static ssize_t hl_state_dump_write(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_state_dump_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	ssize_t rc;
 	u32 size;
 	int i;
 
-	rc = kstrtouint_from_user(buf, count, 10, &size);
+	rc = kstrtouint_from_iter(from, count, 10, &size);
 	if (rc)
 		return rc;
 
@@ -1376,34 +1357,30 @@ static ssize_t hl_state_dump_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_timeout_locked_read(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_timeout_locked_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 	char tmp_buf[200];
-	ssize_t rc;
 
-	if (*ppos)
+	if (iocb->ki_pos)
 		return 0;
 
 	sprintf(tmp_buf, "%d\n",
 		jiffies_to_msecs(hdev->timeout_jiffies) / 1000);
-	rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
-			strlen(tmp_buf) + 1);
-
-	return rc;
+	return simple_copy_to_iter(tmp_buf, &iocb->ki_pos, strlen(tmp_buf) + 1, to);
 }
 
-static ssize_t hl_timeout_locked_write(struct file *f, const char __user *buf,
-				     size_t count, loff_t *ppos)
+static ssize_t hl_timeout_locked_write(struct kiocb *iocb,
+				       struct iov_iter *from)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
+	size_t count = iov_iter_count(from);
 	struct hl_device *hdev = entry->hdev;
 	u32 value;
 	ssize_t rc;
 
-	rc = kstrtouint_from_user(buf, count, 10, &value);
+	rc = kstrtouint_from_iter(from, count, 10, &value);
 	if (rc)
 		return rc;
 
@@ -1415,10 +1392,9 @@ static ssize_t hl_timeout_locked_write(struct file *f, const char __user *buf,
 	return count;
 }
 
-static ssize_t hl_check_razwi_happened(struct file *f, char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t hl_check_razwi_happened(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
+	struct hl_dbg_device_entry *entry = file_inode(iocb->ki_filp)->i_private;
 	struct hl_device *hdev = entry->hdev;
 
 	hdev->asic_funcs->check_if_razwi_happened(hdev);
@@ -1428,96 +1404,96 @@ static ssize_t hl_check_razwi_happened(struct file *f, char __user *buf,
 
 static const struct file_operations hl_mem_scrub_fops = {
 	.owner = THIS_MODULE,
-	.write = hl_memory_scrub,
+	.write_iter = hl_memory_scrub
 };
 
 static const struct file_operations hl_data32b_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_data_read32,
-	.write = hl_data_write32
+	.read_iter = hl_data_read32,
+	.write_iter = hl_data_write32
 };
 
 static const struct file_operations hl_data64b_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_data_read64,
-	.write = hl_data_write64
+	.read_iter = hl_data_read64,
+	.write_iter = hl_data_write64
 };
 
 static const struct file_operations hl_dma_size_fops = {
 	.owner = THIS_MODULE,
-	.write = hl_dma_size_write
+	.write_iter = hl_dma_size_write
 };
 
 static const struct file_operations hl_monitor_dump_fops = {
 	.owner = THIS_MODULE,
-	.write = hl_monitor_dump_trigger
+	.write_iter = hl_monitor_dump_trigger
 };
 
 static const struct file_operations hl_i2c_data_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_i2c_data_read,
-	.write = hl_i2c_data_write
+	.read_iter = hl_i2c_data_read,
+	.write_iter = hl_i2c_data_write
 };
 
 static const struct file_operations hl_power_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_get_power_state,
-	.write = hl_set_power_state
+	.read_iter = hl_get_power_state,
+	.write_iter = hl_set_power_state
 };
 
 static const struct file_operations hl_led0_fops = {
 	.owner = THIS_MODULE,
-	.write = hl_led0_write
+	.write_iter = hl_led0_write
 };
 
 static const struct file_operations hl_led1_fops = {
 	.owner = THIS_MODULE,
-	.write = hl_led1_write
+	.write_iter = hl_led1_write
 };
 
 static const struct file_operations hl_led2_fops = {
 	.owner = THIS_MODULE,
-	.write = hl_led2_write
+	.write_iter = hl_led2_write
 };
 
 static const struct file_operations hl_device_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_device_read,
-	.write = hl_device_write
+	.read_iter = hl_device_read,
+	.write_iter = hl_device_write
 };
 
 static const struct file_operations hl_clk_gate_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_clk_gate_read,
-	.write = hl_clk_gate_write
+	.read_iter = hl_clk_gate_read,
+	.write_iter = hl_clk_gate_write
 };
 
 static const struct file_operations hl_stop_on_err_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_stop_on_err_read,
-	.write = hl_stop_on_err_write
+	.read_iter = hl_stop_on_err_read,
+	.write_iter = hl_stop_on_err_write
 };
 
 static const struct file_operations hl_security_violations_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_security_violations_read
+	.read_iter = hl_security_violations_read
 };
 
 static const struct file_operations hl_state_dump_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_state_dump_read,
-	.write = hl_state_dump_write
+	.read_iter = hl_state_dump_read,
+	.write_iter = hl_state_dump_write
 };
 
 static const struct file_operations hl_timeout_locked_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_timeout_locked_read,
-	.write = hl_timeout_locked_write
+	.read_iter = hl_timeout_locked_read,
+	.write_iter = hl_timeout_locked_write
 };
 
 static const struct file_operations hl_razwi_check_fops = {
 	.owner = THIS_MODULE,
-	.read = hl_check_razwi_happened
+	.read_iter = hl_check_razwi_happened
 };
 
 static const struct hl_info_list hl_debugfs_list[] = {
@@ -1539,13 +1515,12 @@ static int hl_debugfs_open(struct inode *inode, struct file *file)
 	return single_open(file, node->info_ent->show, node);
 }
 
-static ssize_t hl_debugfs_write(struct file *file, const char __user *buf,
-		size_t count, loff_t *f_pos)
+static ssize_t hl_debugfs_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hl_debugfs_entry *node = file->f_inode->i_private;
+	struct hl_debugfs_entry *node = iocb->ki_filp->f_inode->i_private;
 
 	if (node->info_ent->write)
-		return node->info_ent->write(file, buf, count, f_pos);
+		return node->info_ent->write(iocb, from);
 	else
 		return -EINVAL;
 
@@ -1554,8 +1529,8 @@ static ssize_t hl_debugfs_write(struct file *file, const char __user *buf,
 static const struct file_operations hl_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = hl_debugfs_open,
-	.read = seq_read,
-	.write = hl_debugfs_write,
+	.read_iter = seq_read_iter,
+	.write_iter = hl_debugfs_write,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
drivers/accel/habanalabs/common/habanalabs.h +1 -2
index 48f0f3eea1ef..ccf329c83f30 100644
@@ -2338,8 +2338,7 @@ struct hl_fpriv {
 struct hl_info_list {
 	const char	*name;
 	int		(*show)(struct seq_file *s, void *data);
-	ssize_t		(*write)(struct file *file, const char __user *buf,
-				size_t count, loff_t *f_pos);
+	ssize_t		(*write)(struct kiocb *, struct iov_iter *);
 };
 
 /**
drivers/accel/ivpu/ivpu_debugfs.c +41 -43

206 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#111 lore raw

PATCH 105/437 drivers/acpi: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/acpi/acpi_dbg.c      |  6 ++++--
 drivers/acpi/apei/erst-dbg.c | 23 ++++++++++++-----------
 drivers/acpi/ec_sys.c        |  6 ++++--
 drivers/acpi/pfr_update.c    |  3 ++-
 4 files changed, 22 insertions(+), 16 deletions(-)
drivers/acpi/acpi_dbg.c +4 -2
index d50261d05f3a..2ee3bc767693 100644
@@ -638,6 +638,7 @@ static ssize_t acpi_aml_read(struct file *file, char __user *buf,
 	}
 	return size > 0 ? size : ret;
 }
+FOPS_READ_ITER_HELPER(acpi_aml_read);
 
 static int acpi_aml_write_user(const char __user *buf, int len)
 {
@@ -707,6 +708,7 @@ static ssize_t acpi_aml_write(struct file *file, const char __user *buf,
 	}
 	return size > 0 ? size : ret;
 }
+FOPS_WRITE_ITER_HELPER(acpi_aml_write);
 
 static __poll_t acpi_aml_poll(struct file *file, poll_table *wait)
 {
@@ -722,8 +724,8 @@ static __poll_t acpi_aml_poll(struct file *file, poll_table *wait)
 }
 
 static const struct file_operations acpi_aml_operations = {
-	.read		= acpi_aml_read,
-	.write		= acpi_aml_write,
+	.read_iter	= acpi_aml_read_iter,
+	.write_iter	= acpi_aml_write_iter,
 	.poll		= acpi_aml_poll,
 	.open		= acpi_aml_open,
 	.release	= acpi_aml_release,
drivers/acpi/apei/erst-dbg.c +12 -11
index 8bc71cdc2270..293fac1a2821 100644
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/uaccess.h>
+#include <linux/uio.h>
 #include <acpi/apei.h>
 #include <linux/miscdevice.h>
 
@@ -79,20 +80,20 @@ static long erst_dbg_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 	}
 }
 
-static ssize_t erst_dbg_read(struct file *filp, char __user *ubuf,
-			     size_t usize, loff_t *off)
+static ssize_t erst_dbg_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t usize = iov_iter_count(to);
 	int rc, *pos;
 	ssize_t len = 0;
 	u64 id;
 
-	if (*off)
+	if (iocb->ki_pos)
 		return -EINVAL;
 
 	if (mutex_lock_interruptible(&erst_dbg_mutex) != 0)
 		return -EINTR;
 
-	pos = (int *)&filp->private_data;
+	pos = (int *)&iocb->ki_filp->private_data;
 
 retry_next:
 	rc = erst_get_record_id_next(pos, &id);
@@ -141,7 +142,7 @@ static ssize_t erst_dbg_read(struct file *filp, char __user *ubuf,
 		goto out;
 
 	rc = -EFAULT;
-	if (copy_to_user(ubuf, erst_dbg_buf, len))
+	if (!copy_to_iter_full(erst_dbg_buf, len, to))
 		goto out;
 	rc = 0;
 out:
@@ -149,9 +150,9 @@ static ssize_t erst_dbg_read(struct file *filp, char __user *ubuf,
 	return rc ? rc : len;
 }
 
-static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
-			      size_t usize, loff_t *off)
+static ssize_t erst_dbg_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t usize = iov_iter_count(from);
 	int rc;
 	struct cper_record_header *rcd;
 
@@ -175,8 +176,8 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
 		erst_dbg_buf = p;
 		erst_dbg_buf_len = usize;
 	}
-	rc = copy_from_user(erst_dbg_buf, ubuf, usize);
-	if (rc) {
+	rc = copy_from_iter_full(erst_dbg_buf, usize, from);
+	if (!rc) {
 		rc = -EFAULT;
 		goto out;
 	}
@@ -196,8 +197,8 @@ static const struct file_operations erst_dbg_ops = {
 	.owner		= THIS_MODULE,
 	.open		= erst_dbg_open,
 	.release	= erst_dbg_release,
-	.read		= erst_dbg_read,
-	.write		= erst_dbg_write,
+	.read_iter	= erst_dbg_read,
+	.write_iter	= erst_dbg_write,
 	.unlocked_ioctl	= erst_dbg_ioctl,
 	.llseek		= no_llseek,
 };
drivers/acpi/ec_sys.c +4 -2
index c074a0fae059..47c811cb75f4 100644
@@ -60,6 +60,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
 	}
 	return count;
 }
+FOPS_READ_ITER_HELPER(acpi_ec_read_io);
 
 static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
 				size_t count, loff_t *off)
@@ -98,12 +99,13 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
 	}
 	return count;
 }
+FOPS_WRITE_ITER_HELPER(acpi_ec_write_io);
 
 static const struct file_operations acpi_ec_io_ops = {
 	.owner = THIS_MODULE,
 	.open  = simple_open,
-	.read  = acpi_ec_read_io,
-	.write = acpi_ec_write_io,
+	.read_iter  = acpi_ec_read_io_iter,
+	.write_iter = acpi_ec_write_io_iter,
 	.llseek = default_llseek,
 };
 
drivers/acpi/pfr_update.c +2 -1
index 8b2910995fc1..a7a4d3bb74d3 100644
@@ -481,10 +481,11 @@ static ssize_t pfru_write(struct file *file, const char __user *buf,
 
 	return ret ?: len;
 }
+FOPS_WRITE_ITER_HELPER(pfru_write);
 
 static const struct file_operations acpi_pfru_fops = {
 	.owner		= THIS_MODULE,
-	.write		= pfru_write,
+	.write_iter	= pfru_write_iter,
 	.unlocked_ioctl = pfru_ioctl,
 	.llseek		= noop_llseek,
 };
Signature · 1 line
2.43.0
author maintainer
#112 lore raw

PATCH 106/437 crypto: hisilicon: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/crypto/hisilicon/debugfs.c        | 51 +++++++++++------------
 drivers/crypto/hisilicon/hpre/hpre_main.c | 23 +++++-----
 drivers/crypto/hisilicon/qm.c             | 22 +++++-----
 drivers/crypto/hisilicon/sec2/sec_main.c  | 23 +++++-----
 drivers/crypto/hisilicon/zip/zip_main.c   | 23 +++++-----
 5 files changed, 68 insertions(+), 74 deletions(-)
drivers/crypto/hisilicon/debugfs.c +24 -27
index cd67fa348ca7..6dd67b0fcf36 100644
@@ -137,8 +137,7 @@ static struct hisi_qm *file_to_qm(struct debugfs_file *file)
 	return container_of(debug, struct hisi_qm, debug);
 }
 
-static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
-			   size_t count, loff_t *pos)
+static ssize_t qm_cmd_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	char buf[QM_DBG_READ_LEN];
 	int len;
@@ -146,7 +145,7 @@ static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
 	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n",
 			"Please echo help to cmd to get help information");
 
-	return simple_read_from_buffer(buffer, count, pos, buf, len);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 }
 
 static void dump_show(struct hisi_qm *qm, void *info,
@@ -502,14 +501,14 @@ static int qm_cmd_write_dump(struct hisi_qm *qm, const char *cmd_buf)
 	return ret;
 }
 
-static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer,
-			    size_t count, loff_t *pos)
+static ssize_t qm_cmd_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	char *cmd_buf, *cmd_buf_tmp;
 	int ret;
 
-	if (*pos)
+	if (iocb->ki_pos)
 		return 0;
 
 	ret = hisi_qm_get_dfx_access(qm);
@@ -527,7 +526,7 @@ static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer,
 		goto put_dfx_access;
 	}
 
-	cmd_buf = memdup_user_nul(buffer, count);
+	cmd_buf = iterdup_nul(from, count);
 	if (IS_ERR(cmd_buf)) {
 		ret = PTR_ERR(cmd_buf);
 		goto put_dfx_access;
@@ -557,8 +556,8 @@ static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer,
 static const struct file_operations qm_cmd_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_cmd_read,
-	.write = qm_cmd_write,
+	.read_iter = qm_cmd_read,
+	.write_iter = qm_cmd_write,
 };
 
 /**
@@ -704,10 +703,9 @@ static int current_qm_write(struct hisi_qm *qm, u32 val)
 	return 0;
 }
 
-static ssize_t qm_debug_read(struct file *filp, char __user *buf,
-			     size_t count, loff_t *pos)
+static ssize_t qm_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct debugfs_file *file = filp->private_data;
+	struct debugfs_file *file = iocb->ki_filp->private_data;
 	enum qm_debug_file index = file->index;
 	struct hisi_qm *qm = file_to_qm(file);
 	char tbuf[QM_DBG_TMP_BUF_LEN];
@@ -736,7 +734,7 @@ static ssize_t qm_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = scnprintf(tbuf, QM_DBG_TMP_BUF_LEN, "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	mutex_unlock(&file->lock);
@@ -744,24 +742,24 @@ static ssize_t qm_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t qm_debug_write(struct file *filp, const char __user *buf,
-			      size_t count, loff_t *pos)
+static ssize_t qm_debug_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct debugfs_file *file = filp->private_data;
+	struct debugfs_file *file = iocb->ki_filp->private_data;
 	enum qm_debug_file index = file->index;
 	struct hisi_qm *qm = file_to_qm(file);
+	size_t count = iov_iter_count(from);
 	unsigned long val;
 	char tbuf[QM_DBG_TMP_BUF_LEN];
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= QM_DBG_TMP_BUF_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, QM_DBG_TMP_BUF_LEN - 1, pos, buf,
-				     count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos, QM_DBG_TMP_BUF_LEN - 1,
+					from);
 	if (len < 0)
 		return len;
 
@@ -800,8 +798,8 @@ static ssize_t qm_debug_write(struct file *filp, const char __user *buf,
 static const struct file_operations qm_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_debug_read,
-	.write = qm_debug_write,
+	.read_iter = qm_debug_read,
+	.write_iter = qm_debug_write,
 };
 
 static void dfx_regs_uninit(struct hisi_qm *qm,
@@ -1051,23 +1049,22 @@ static int qm_state_show(struct seq_file *s, void *unused)
 
 DEFINE_SHOW_ATTRIBUTE(qm_state);
 
-static ssize_t qm_status_read(struct file *filp, char __user *buffer,
-			      size_t count, loff_t *pos)
+static ssize_t qm_status_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
 	char buf[QM_DBG_READ_LEN];
 	int val, len;
 
 	val = atomic_read(&qm->status.flags);
 	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
 
-	return simple_read_from_buffer(buffer, count, pos, buf, len);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 }
 
 static const struct file_operations qm_status_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_status_read,
+	.read_iter = qm_status_read,
 };
 
 static void qm_create_debugfs_file(struct hisi_qm *qm, struct dentry *dir,
drivers/crypto/hisilicon/hpre/hpre_main.c +11 -12
index d93aa6630a57..b9257a368aa9 100644
@@ -829,10 +829,9 @@ static void hpre_cluster_inqry_write(struct hpre_debugfs_file *file, u32 val)
 	writel(val, qm->io_base + offset + HPRE_CLUSTER_INQURY);
 }
 
-static ssize_t hpre_ctrl_debug_read(struct file *filp, char __user *buf,
-				    size_t count, loff_t *pos)
+static ssize_t hpre_ctrl_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hpre_debugfs_file *file = filp->private_data;
+	struct hpre_debugfs_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = hpre_file_to_qm(file);
 	char tbuf[HPRE_DBGFS_VAL_MAX_LEN];
 	u32 val;
@@ -857,7 +856,7 @@ static ssize_t hpre_ctrl_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = snprintf(tbuf, HPRE_DBGFS_VAL_MAX_LEN, "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	spin_unlock_irq(&file->lock);
@@ -865,23 +864,23 @@ static ssize_t hpre_ctrl_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t hpre_ctrl_debug_write(struct file *filp, const char __user *buf,
-				     size_t count, loff_t *pos)
+static ssize_t hpre_ctrl_debug_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hpre_debugfs_file *file = filp->private_data;
+	struct hpre_debugfs_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = hpre_file_to_qm(file);
+	size_t count = iov_iter_count(from);
 	char tbuf[HPRE_DBGFS_VAL_MAX_LEN];
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= HPRE_DBGFS_VAL_MAX_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, HPRE_DBGFS_VAL_MAX_LEN - 1,
-				     pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos,
+					HPRE_DBGFS_VAL_MAX_LEN - 1, from);
 	if (len < 0)
 		return len;
 
@@ -919,8 +918,8 @@ static ssize_t hpre_ctrl_debug_write(struct file *filp, const char __user *buf,
 static const struct file_operations hpre_ctrl_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = hpre_ctrl_debug_read,
-	.write = hpre_ctrl_debug_write,
+	.read_iter = hpre_ctrl_debug_read,
+	.write_iter = hpre_ctrl_debug_write,
 };
 
 static int hpre_debugfs_atomic64_get(void *data, u64 *val)
drivers/crypto/hisilicon/qm.c +11 -11
index 92f0a1d9b4a6..604cff89f0c8 100644
@@ -3591,10 +3591,9 @@ static int qm_vf_read_qos(struct hisi_qm *qm)
 	return ret;
 }
 
-static ssize_t qm_algqos_read(struct file *filp, char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t qm_algqos_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
 	char tbuf[QM_DBG_READ_LEN];
 	u32 qos_val, ir;
 	int ret;
@@ -3622,7 +3621,7 @@ static ssize_t qm_algqos_read(struct file *filp, char __user *buf,
 	qos_val = ir / QM_QOS_RATE;
 	ret = scnprintf(tbuf, QM_DBG_READ_LEN, "%u\n", qos_val);
 
-	ret = simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	ret = simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_get_status:
 	clear_bit(QM_RESETTING, &qm->misc_ctl);
@@ -3665,22 +3664,23 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
 	return 0;
 }
 
-static ssize_t qm_algqos_write(struct file *filp, const char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t qm_algqos_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	char tbuf[QM_DBG_READ_LEN];
 	unsigned int fun_index;
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= QM_DBG_READ_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, QM_DBG_READ_LEN - 1, pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos, QM_DBG_READ_LEN - 1,
+					from);
 	if (len < 0)
 		return len;
 
@@ -3722,8 +3722,8 @@ static ssize_t qm_algqos_write(struct file *filp, const char __user *buf,
 static const struct file_operations qm_algqos_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_algqos_read,
-	.write = qm_algqos_write,
+	.read_iter = qm_algqos_read,
+	.write_iter = qm_algqos_write,
 };
 
 /**
drivers/crypto/hisilicon/sec2/sec_main.c +11 -12
index c290d8937b19..bb168d97de30 100644
@@ -718,10 +718,9 @@ static int sec_clear_enable_write(struct hisi_qm *qm, u32 val)
 	return 0;
 }
 
-static ssize_t sec_debug_read(struct file *filp, char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t sec_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct sec_debug_file *file = filp->private_data;
+	struct sec_debug_file *file = iocb->ki_filp->private_data;
 	char tbuf[SEC_DBGFS_VAL_MAX_LEN];
 	struct hisi_qm *qm = file->qm;
 	u32 val;
@@ -745,7 +744,7 @@ static ssize_t sec_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = snprintf(tbuf, SEC_DBGFS_VAL_MAX_LEN, "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	spin_unlock_irq(&file->lock);
@@ -753,23 +752,23 @@ static ssize_t sec_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t sec_debug_write(struct file *filp, const char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t sec_debug_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct sec_debug_file *file = filp->private_data;
+	struct sec_debug_file *file = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	char tbuf[SEC_DBGFS_VAL_MAX_LEN];
 	struct hisi_qm *qm = file->qm;
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= SEC_DBGFS_VAL_MAX_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, SEC_DBGFS_VAL_MAX_LEN - 1,
-				     pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos,
+					SEC_DBGFS_VAL_MAX_LEN - 1, from);
 	if (len < 0)
 		return len;
 
@@ -805,8 +804,8 @@ static ssize_t sec_debug_write(struct file *filp, const char __user *buf,
 static const struct file_operations sec_dbg_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = sec_debug_read,
-	.write = sec_debug_write,
+	.read_iter = sec_debug_read,
+	.write_iter = sec_debug_write,
 };
 
 static int sec_debugfs_atomic64_get(void *data, u64 *val)
drivers/crypto/hisilicon/zip/zip_main.c +11 -12
index c065fd867161..47319ba13873 100644
@@ -689,10 +689,9 @@ static int clear_enable_write(struct hisi_qm *qm, u32 val)
 	return  0;
 }
 
-static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
-					size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct ctrl_debug_file *file = filp->private_data;
+	struct ctrl_debug_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = file_to_qm(file);
 	char tbuf[HZIP_BUF_SIZE];
 	u32 val;
@@ -714,7 +713,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = scnprintf(tbuf, sizeof(tbuf), "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	spin_unlock_irq(&file->lock);
@@ -722,23 +721,23 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
-					 const char __user *buf,
-					 size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_write(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct ctrl_debug_file *file = filp->private_data;
+	struct ctrl_debug_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = file_to_qm(file);
+	size_t count = iov_iter_count(from);
 	char tbuf[HZIP_BUF_SIZE];
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= HZIP_BUF_SIZE)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, HZIP_BUF_SIZE - 1, pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos, HZIP_BUF_SIZE - 1, from);
 	if (len < 0)
 		return len;
 
@@ -774,8 +773,8 @@ static ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
 static const struct file_operations ctrl_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = hisi_zip_ctrl_debug_read,
-	.write = hisi_zip_ctrl_debug_write,
+	.read_iter = hisi_zip_ctrl_debug_read,
+	.write_iter = hisi_zip_ctrl_debug_write,
 };
 
 static int zip_debugfs_atomic64_set(void *data, u64 val)
Signature · 1 line
2.43.0
author maintainer
#113 lore raw

PATCH 107/437 crypto: iaa: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/crypto/intel/iaa/iaa_crypto_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/iaa/iaa_crypto_stats.c +1 -1
index c9f83af4b307..8ae1cf87ddca 100644
@@ -238,7 +238,7 @@ static int wq_stats_open(struct inode *inode, struct file *file)
 
 static const struct file_operations wq_stats_fops = {
 	.open = wq_stats_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#114 lore raw

PATCH 108/437 crypto: qat: convert to read/write iterators

In reply to Jens Axboe
---
 .../intel/qat/qat_common/adf_cnv_dbgfs.c      | 10 ++--
 .../intel/qat/qat_common/adf_fw_counters.c    |  2 +-
 .../qat/qat_common/adf_heartbeat_dbgfs.c      | 60 +++++++++----------
 .../intel/qat/qat_common/adf_pm_dbgfs.c       |  3 +-
 .../intel/qat/qat_common/adf_tl_debugfs.c     | 18 +++---
 5 files changed, 44 insertions(+), 49 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_cnv_dbgfs.c +4 -6
index 627953a72d47..3c6b7d0b2e9d 100644
@@ -255,23 +255,21 @@ static int qat_cnv_errors_file_release(struct inode *inode, struct file *file)
 static const struct file_operations qat_cnv_fops = {
 	.owner = THIS_MODULE,
 	.open = qat_cnv_errors_file_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = qat_cnv_errors_file_release,
 };
 
-static ssize_t no_comp_file_read(struct file *f, char __user *buf, size_t count,
-				 loff_t *pos)
+static ssize_t no_comp_file_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	char *file_msg = "No engine configured for comp\n";
 
-	return simple_read_from_buffer(buf, count, pos, file_msg,
-				       strlen(file_msg));
+	return simple_copy_to_iter(file_msg, &iocb->ki_pos, strlen(file_msg), to);
 }
 
 static const struct file_operations qat_cnv_no_comp_fops = {
 	.owner = THIS_MODULE,
-	.read = no_comp_file_read,
+	.read_iter = no_comp_file_read,
 };
 
 void adf_cnv_dbgfs_add(struct adf_accel_dev *accel_dev)
drivers/crypto/intel/qat/qat_common/adf_fw_counters.c +1 -1
index 98fb7ccfed9f..f654d698efe9 100644
@@ -224,7 +224,7 @@ static int qat_fw_counters_file_release(struct inode *inode, struct file *file)
 static const struct file_operations qat_fw_counters_fops = {
 	.owner = THIS_MODULE,
 	.open = qat_fw_counters_file_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = qat_fw_counters_file_release,
 };
drivers/crypto/intel/qat/qat_common/adf_heartbeat_dbgfs.c +28 -32

150 lines not on this page · raw message

drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs.c +2 -1
index f0a13c190196..95105baa68d0 100644
@@ -18,10 +18,11 @@ static ssize_t pm_status_read(struct file *f, char __user *buf, size_t count,
 
 	return count;
 }
+FOPS_READ_ITER_HELPER(pm_status_read);
 
 static const struct file_operations pm_status_fops = {
 	.owner = THIS_MODULE,
-	.read = pm_status_read,
+	.read_iter = pm_status_read_iter,
 };
 
 void adf_pm_dbgfs_add(struct adf_accel_dev *accel_dev)
drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c +9 -9
index c8241f5a0a26..d3704f41c406 100644
@@ -413,10 +413,10 @@ static int tl_control_show(struct seq_file *s, void *unused)
 	return 0;
 }
 
-static ssize_t tl_control_write(struct file *file, const char __user *userbuf,
-				size_t count, loff_t *ppos)
+static ssize_t tl_control_write_iter(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *seq_f = file->private_data;
+	struct seq_file *seq_f = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct adf_accel_dev *accel_dev;
 	struct adf_telemetry *telemetry;
 	struct adf_tl_hw_data *tl_data;
@@ -434,7 +434,7 @@ static ssize_t tl_control_write(struct file *file, const char __user *userbuf,
 
 	mutex_lock(&telemetry->wr_lock);
 
-	ret = kstrtou32_from_user(userbuf, count, 10, &input);
+	ret = kstrtou32_from_iter(from, count, 10, &input);
 	if (ret)
 		goto unlock_and_exit;
 
@@ -627,10 +627,10 @@ static int tl_rp_data_show(struct seq_file *s, void *unused)
 	return tl_print_rp_data(accel_dev, s, rp_regs_index);
 }
 
-static ssize_t tl_rp_data_write(struct file *file, const char __user *userbuf,
-				size_t count, loff_t *ppos)
+static ssize_t tl_rp_data_write_iter(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *seq_f = file->private_data;
+	struct seq_file *seq_f = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct adf_accel_dev *accel_dev;
 	struct adf_telemetry *telemetry;
 	unsigned int new_rp_num;
@@ -647,13 +647,13 @@ static ssize_t tl_rp_data_write(struct file *file, const char __user *userbuf,
 
 	mutex_lock(&telemetry->wr_lock);
 
-	ret = get_rp_index_from_file(file, &rp_regs_index, max_rp);
+	ret = get_rp_index_from_file(iocb->ki_filp, &rp_regs_index, max_rp);
 	if (ret) {
 		dev_dbg(&GET_DEV(accel_dev), "invalid RP data file name\n");
 		goto unlock_and_exit;
 	}
 
-	ret = kstrtou32_from_user(userbuf, count, 10, &new_rp_num);
+	ret = kstrtou32_from_iter(from, count, 10, &new_rp_num);
 	if (ret)
 		goto unlock_and_exit;
 
Signature · 1 line
2.43.0
author maintainer
#115 lore raw

PATCH 109/437 crypto: cpp: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/crypto/ccp/ccp-debugfs.c | 51 ++++++++++++++------------------
 1 file changed, 22 insertions(+), 29 deletions(-)
drivers/crypto/ccp/ccp-debugfs.c +22 -29
index a1055554b47a..34bf31386994 100644
@@ -39,10 +39,9 @@
 #define	RI_NLSB_SHIFT	19
 #define	RI_NLSB(r)	(((r) * RI_LSB_ENTRIES) >> RI_NLSB_SHIFT)
 
-static ssize_t ccp5_debugfs_info_read(struct file *filp, char __user *ubuf,
-				      size_t count, loff_t *offp)
+static ssize_t ccp5_debugfs_info_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct ccp_device *ccp = filp->private_data;
+	struct ccp_device *ccp = iocb->ki_filp->private_data;
 	unsigned int oboff = 0;
 	unsigned int regval;
 	ssize_t ret;
@@ -85,7 +84,7 @@ static ssize_t ccp5_debugfs_info_read(struct file *filp, char __user *ubuf,
 	oboff += OSCNPRINTF("LSB Entries: %d\n",
 		   (regval & RI_LSB_ENTRIES) >> RI_NLSB_SHIFT);
 
-	ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+	ret = simple_copy_to_iter(obuf, &iocb->ki_pos, oboff, to);
 	kfree(obuf);
 
 	return ret;
@@ -94,10 +93,9 @@ static ssize_t ccp5_debugfs_info_read(struct file *filp, char __user *ubuf,
 /* Return a formatted buffer containing the current
  * statistics across all queues for a CCP.
  */
-static ssize_t ccp5_debugfs_stats_read(struct file *filp, char __user *ubuf,
-				       size_t count, loff_t *offp)
+static ssize_t ccp5_debugfs_stats_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct ccp_device *ccp = filp->private_data;
+	struct ccp_device *ccp = iocb->ki_filp->private_data;
 	unsigned long total_xts_aes_ops = 0;
 	unsigned long total_3des_ops = 0;
 	unsigned long total_aes_ops = 0;
@@ -147,7 +145,7 @@ static ssize_t ccp5_debugfs_stats_read(struct file *filp, char __user *ubuf,
 	oboff += OSCNPRINTF("                     ECC: %ld\n",
 			    total_ecc_ops);
 
-	ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+	ret = simple_copy_to_iter(obuf, &iocb->ki_pos, oboff, to);
 	kfree(obuf);
 
 	return ret;
@@ -171,27 +169,25 @@ static void ccp5_debugfs_reset_queue_stats(struct ccp_cmd_queue *cmd_q)
  * should be used to reset the queue counters across
  * that device.
  */
-static ssize_t ccp5_debugfs_stats_write(struct file *filp,
-					const char __user *ubuf,
-					size_t count, loff_t *offp)
+static ssize_t ccp5_debugfs_stats_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	struct ccp_device *ccp = filp->private_data;
+	struct ccp_device *ccp = iocb->ki_filp->private_data;
 	int i;
 
 	for (i = 0; i < ccp->cmd_q_count; i++)
 		ccp5_debugfs_reset_queue_stats(&ccp->cmd_q[i]);
 	ccp->total_interrupts = 0L;
 
-	return count;
+	return iov_iter_count(from);
 }
 
 /* Return a formatted buffer containing the current information
  * for that queue
  */
-static ssize_t ccp5_debugfs_queue_read(struct file *filp, char __user *ubuf,
-				       size_t count, loff_t *offp)
+static ssize_t ccp5_debugfs_queue_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct ccp_cmd_queue *cmd_q = filp->private_data;
+	struct ccp_cmd_queue *cmd_q = iocb->ki_filp->private_data;
 	unsigned int oboff = 0;
 	unsigned int regval;
 	ssize_t ret;
@@ -233,7 +229,7 @@ static ssize_t ccp5_debugfs_queue_read(struct file *filp, char __user *ubuf,
 		oboff += OSCNPRINTF(" COMPLETION");
 	oboff += OSCNPRINTF("\n");
 
-	ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+	ret = simple_copy_to_iter(obuf, &iocb->ki_pos, oboff, to);
 	kfree(obuf);
 
 	return ret;
@@ -242,36 +238,33 @@ static ssize_t ccp5_debugfs_queue_read(struct file *filp, char __user *ubuf,
 /* A value was written to the stats variable for a
  * queue. Reset the queue counters to this value.
  */
-static ssize_t ccp5_debugfs_queue_write(struct file *filp,
-					const char __user *ubuf,
-					size_t count, loff_t *offp)
+static ssize_t ccp5_debugfs_queue_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	struct ccp_cmd_queue *cmd_q = filp->private_data;
+	struct ccp_cmd_queue *cmd_q = iocb->ki_filp->private_data;
 
 	ccp5_debugfs_reset_queue_stats(cmd_q);
-
-	return count;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations ccp_debugfs_info_ops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = ccp5_debugfs_info_read,
-	.write = NULL,
+	.read_iter = ccp5_debugfs_info_read,
 };
 
 static const struct file_operations ccp_debugfs_queue_ops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = ccp5_debugfs_queue_read,
-	.write = ccp5_debugfs_queue_write,
+	.read_iter = ccp5_debugfs_queue_read,
+	.write_iter = ccp5_debugfs_queue_write,
 };
 
 static const struct file_operations ccp_debugfs_stats_ops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = ccp5_debugfs_stats_read,
-	.write = ccp5_debugfs_stats_write,
+	.read_iter = ccp5_debugfs_stats_read,
+	.write_iter = ccp5_debugfs_stats_write,
 };
 
 static struct dentry *ccp_debugfs_dir;
Signature · 1 line
2.43.0
author maintainer
#116 lore raw

PATCH 110/437 fs/pstore: convert to read/write iterators

In reply to Jens Axboe
---
 fs/pstore/ftrace.c | 16 ++++++++--------
 fs/pstore/inode.c  | 13 ++++++-------
 fs/pstore/pmsg.c   |  3 ++-
 3 files changed, 16 insertions(+), 16 deletions(-)
fs/pstore/ftrace.c +8 -8
index 776cae20af4e..8c7244df7787 100644
@@ -88,13 +88,14 @@ static int pstore_set_ftrace_enabled(bool on)
 	return ret;
 }
 
-static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf,
-					size_t count, loff_t *ppos)
+static ssize_t pstore_ftrace_knob_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	u8 on;
 	ssize_t ret;
 
-	ret = kstrtou8_from_user(buf, count, 2, &on);
+	ret = kstrtou8_from_iter(from, count, 2, &on);
 	if (ret)
 		return ret;
 
@@ -108,18 +109,17 @@ static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf,
 	return ret;
 }
 
-static ssize_t pstore_ftrace_knob_read(struct file *f, char __user *buf,
-				       size_t count, loff_t *ppos)
+static ssize_t pstore_ftrace_knob_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	char val[] = { '0' + pstore_ftrace_enabled, '\n' };
 
-	return simple_read_from_buffer(buf, count, ppos, val, sizeof(val));
+	return simple_copy_to_iter(val, &iocb->ki_pos, sizeof(val), to);
 }
 
 static const struct file_operations pstore_knob_fops = {
 	.open	= simple_open,
-	.read	= pstore_ftrace_knob_read,
-	.write	= pstore_ftrace_knob_write,
+	.read_iter	= pstore_ftrace_knob_read,
+	.write_iter	= pstore_ftrace_knob_write,
 };
 
 static struct dentry *pstore_ftrace_dir;
fs/pstore/inode.c +6 -7
index 56815799ce79..581f014149a9 100644
@@ -127,16 +127,15 @@ static const struct seq_operations pstore_ftrace_seq_ops = {
 	.show	= pstore_ftrace_seq_show,
 };
 
-static ssize_t pstore_file_read(struct file *file, char __user *userbuf,
-						size_t count, loff_t *ppos)
+static ssize_t pstore_file_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct seq_file *sf = file->private_data;
+	struct seq_file *sf = iocb->ki_filp->private_data;
 	struct pstore_private *ps = sf->private;
 
 	if (ps->record->type == PSTORE_TYPE_FTRACE)
-		return seq_read(file, userbuf, count, ppos);
-	return simple_read_from_buffer(userbuf, count, ppos,
-				       ps->record->buf, ps->total_size);
+		return seq_read_iter(iocb, to);
+	return simple_copy_to_iter(ps->record->buf, &iocb->ki_pos,
+					ps->total_size, to);
 }
 
 static int pstore_file_open(struct inode *inode, struct file *file)
@@ -170,7 +169,7 @@ static loff_t pstore_file_llseek(struct file *file, loff_t off, int whence)
 
 static const struct file_operations pstore_file_operations = {
 	.open		= pstore_file_open,
-	.read		= pstore_file_read,
+	.read_iter	= pstore_file_read,
 	.llseek		= pstore_file_llseek,
 	.release	= seq_release,
 };
fs/pstore/pmsg.c +2 -1
index 55f139afa327..83fef50ecce5 100644
@@ -33,11 +33,12 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,
 	mutex_unlock(&pmsg_lock);
 	return ret ? ret : count;
 }
+FOPS_WRITE_ITER_HELPER(write_pmsg);
 
 static const struct file_operations pmsg_fops = {
 	.owner		= THIS_MODULE,
 	.llseek		= noop_llseek,
-	.write		= write_pmsg,
+	.write_iter	= write_pmsg_iter,
 };
 
 static struct class *pmsg_class;
Signature · 1 line
2.43.0
author maintainer
#117 lore raw

PATCH 111/437 drivers/gpio: convert to ->read_iter and ->write_iter

In reply to Jens Axboe
---
 drivers/gpio/gpio-mockup.c  | 26 +++++++++++------------
 drivers/gpio/gpiolib-cdev.c | 41 ++++++++++++++++++-------------------
 2 files changed, 32 insertions(+), 35 deletions(-)
drivers/gpio/gpio-mockup.c +12 -14
index 455eecf6380e..34fc0f921284 100644
@@ -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,
 };
drivers/gpio/gpiolib-cdev.c +20 -21

125 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#118 lore raw

PATCH 112/437 drivers/bluetooth: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/bluetooth/btmrvl_debugfs.c | 57 +++++++++++------------
 drivers/bluetooth/btusb.c          | 20 ++++----
 drivers/bluetooth/hci_vhci.c       | 73 ++++++++++++++----------------
 3 files changed, 70 insertions(+), 80 deletions(-)
drivers/bluetooth/btmrvl_debugfs.c +27 -30
index 32329a2e526f..e78343575146 100644
@@ -18,13 +18,13 @@ struct btmrvl_debugfs_data {
 	struct dentry *status_dir;
 };
 
-static ssize_t btmrvl_hscfgcmd_write(struct file *file,
-			const char __user *ubuf, size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscfgcmd_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct btmrvl_private *priv = file->private_data;
+	struct btmrvl_private *priv = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	long result, ret;
 
-	ret = kstrtol_from_user(ubuf, count, 10, &result);
+	ret = kstrtol_from_iter(from, count, 10, &result);
 	if (ret)
 		return ret;
 
@@ -38,33 +38,32 @@ static ssize_t btmrvl_hscfgcmd_write(struct file *file,
 	return count;
 }
 
-static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
-						size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscfgcmd_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct btmrvl_private *priv = file->private_data;
+	struct btmrvl_private *priv = iocb->ki_filp->private_data;
 	char buf[16];
 	int ret;
 
 	ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
 						priv->btmrvl_dev.hscfgcmd);
 
-	return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);
 }
 
 static const struct file_operations btmrvl_hscfgcmd_fops = {
-	.read	= btmrvl_hscfgcmd_read,
-	.write	= btmrvl_hscfgcmd_write,
+	.read_iter	= btmrvl_hscfgcmd_read,
+	.write_iter	= btmrvl_hscfgcmd_write,
 	.open	= simple_open,
 	.llseek = default_llseek,
 };
 
-static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
-						size_t count, loff_t *ppos)
+static ssize_t btmrvl_pscmd_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct btmrvl_private *priv = file->private_data;
+	struct btmrvl_private *priv = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	long result, ret;
 
-	ret = kstrtol_from_user(ubuf, count, 10, &result);
+	ret = kstrtol_from_iter(from, count, 10, &result);
 	if (ret)
 		return ret;
 
@@ -79,32 +78,31 @@ static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
 
 }
 
-static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
-						size_t count, loff_t *ppos)
+static ssize_t btmrvl_pscmd_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct btmrvl_private *priv = file->private_data;
+	struct btmrvl_private *priv = iocb->ki_filp->private_data;
 	char buf[16];
 	int ret;
 
 	ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
 
-	return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);
 }
 
 static const struct file_operations btmrvl_pscmd_fops = {
-	.read = btmrvl_pscmd_read,
-	.write = btmrvl_pscmd_write,
+	.read_iter = btmrvl_pscmd_read,
+	.write_iter = btmrvl_pscmd_write,
 	.open = simple_open,
 	.llseek = default_llseek,
 };
 
-static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
-						size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscmd_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct btmrvl_private *priv = file->private_data;
+	struct btmrvl_private *priv = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	long result, ret;
 
-	ret = kstrtol_from_user(ubuf, count, 10, &result);
+	ret = kstrtol_from_iter(from, count, 10, &result);
 	if (ret)
 		return ret;
 
@@ -117,21 +115,20 @@ static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
 	return count;
 }
 
-static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
-						size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscmd_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct btmrvl_private *priv = file->private_data;
+	struct btmrvl_private *priv = iocb->ki_filp->private_data;
 	char buf[16];
 	int ret;
 
 	ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
 
-	return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);
 }
 
 static const struct file_operations btmrvl_hscmd_fops = {
-	.read	= btmrvl_hscmd_read,
-	.write	= btmrvl_hscmd_write,
+	.read_iter	= btmrvl_hscmd_read,
+	.write_iter	= btmrvl_hscmd_write,
 	.open	= simple_open,
 	.llseek = default_llseek,
 };
drivers/bluetooth/btusb.c +9 -11
index 06e915b57283..7dbcd00ed4ed 100644
@@ -4161,27 +4161,25 @@ static int btusb_shutdown_qca(struct hci_dev *hdev)
 	return 0;
 }
 
-static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf,
-				    size_t count, loff_t *ppos)
+static ssize_t force_poll_sync_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct btusb_data *data = file->private_data;
+	struct btusb_data *data = iocb->ki_filp->private_data;
 	char buf[3];
 
 	buf[0] = data->poll_sync ? 'Y' : 'N';
 	buf[1] = '\n';
 	buf[2] = '\0';
-	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, 2, to);
 }
 
-static ssize_t force_poll_sync_write(struct file *file,
-				     const char __user *user_buf,
-				     size_t count, loff_t *ppos)
+static ssize_t force_poll_sync_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct btusb_data *data = file->private_data;
+	struct btusb_data *data = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	bool enable;
 	int err;
 
-	err = kstrtobool_from_user(user_buf, count, &enable);
+	err = kstrtobool_from_iter(from, count, &enable);
 	if (err)
 		return err;
 
@@ -4199,8 +4197,8 @@ static ssize_t force_poll_sync_write(struct file *file,
 
 static const struct file_operations force_poll_sync_fops = {
 	.open		= simple_open,
-	.read		= force_poll_sync_read,
-	.write		= force_poll_sync_write,
+	.read_iter	= force_poll_sync_read,
+	.write_iter	= force_poll_sync_write,
 	.llseek		= default_llseek,
 };
 
drivers/bluetooth/hci_vhci.c +34 -39

177 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#119 lore raw

PATCH 113/437 drivers/ras: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/ras/amd/fmpm.c | 2 +-
 drivers/ras/debugfs.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/ras/amd/fmpm.c +1 -1
index 271dfad05d68..8e0a89491170 100644
@@ -944,7 +944,7 @@ static int fmpm_open(struct inode *inode, struct file *file)
 static const struct file_operations fmpm_fops = {
 	.open		= fmpm_open,
 	.release	= seq_release,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 };
 
drivers/ras/debugfs.c +1 -1
index 42afd3de68b2..e71046472cea 100644
@@ -38,7 +38,7 @@ static int trace_release(struct inode *inode, struct file *file)
 
 static const struct file_operations trace_fops = {
 	.open    = trace_open,
-	.read    = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek  = seq_lseek,
 	.release = trace_release,
 };
Signature · 1 line
2.43.0
author maintainer
#120 lore raw

PATCH 114/437 fs/efivars: convert to read/write iterators

In reply to Jens Axboe
---
 fs/efivarfs/file.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
fs/efivarfs/file.c +15 -16
index 7e9961639802..b53246e728a5 100644
@@ -12,13 +12,13 @@
 
 #include "internal.h"
 
-static ssize_t efivarfs_file_write(struct file *file,
-		const char __user *userbuf, size_t count, loff_t *ppos)
+static ssize_t efivarfs_file_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct efivar_entry *var = file->private_data;
+	struct efivar_entry *var = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	void *data;
 	u32 attributes;
-	struct inode *inode = file->f_mapping->host;
+	struct inode *inode = iocb->ki_filp->f_mapping->host;
 	unsigned long datasize = count - sizeof(attributes);
 	ssize_t bytes;
 	bool set = false;
@@ -26,13 +26,13 @@ static ssize_t efivarfs_file_write(struct file *file,
 	if (count < sizeof(attributes))
 		return -EINVAL;
 
-	if (copy_from_user(&attributes, userbuf, sizeof(attributes)))
+	if (!copy_from_iter_full(&attributes, sizeof(attributes), from))
 		return -EFAULT;
 
 	if (attributes & ~(EFI_VARIABLE_MASK))
 		return -EINVAL;
 
-	data = memdup_user(userbuf + sizeof(attributes), datasize);
+	data = iterdup(from, datasize);
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
@@ -46,8 +46,8 @@ static ssize_t efivarfs_file_write(struct file *file,
 
 	if (bytes == -ENOENT) {
 		drop_nlink(inode);
-		d_delete(file->f_path.dentry);
-		dput(file->f_path.dentry);
+		d_delete(iocb->ki_filp->f_path.dentry);
+		dput(iocb->ki_filp->f_path.dentry);
 	} else {
 		inode_lock(inode);
 		i_size_write(inode, datasize + sizeof(attributes));
@@ -63,17 +63,16 @@ static ssize_t efivarfs_file_write(struct file *file,
 	return bytes;
 }
 
-static ssize_t efivarfs_file_read(struct file *file, char __user *userbuf,
-		size_t count, loff_t *ppos)
+static ssize_t efivarfs_file_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct efivar_entry *var = file->private_data;
+	struct efivar_entry *var = iocb->ki_filp->private_data;
 	unsigned long datasize = 0;
 	u32 attributes;
 	void *data;
 	ssize_t size = 0;
 	int err;
 
-	while (!__ratelimit(&file->f_cred->user->ratelimit))
+	while (!__ratelimit(&iocb->ki_filp->f_cred->user->ratelimit))
 		msleep(50);
 
 	err = efivar_entry_size(var, &datasize);
@@ -98,8 +97,8 @@ static ssize_t efivarfs_file_read(struct file *file, char __user *userbuf,
 		goto out_free;
 
 	memcpy(data, &attributes, sizeof(attributes));
-	size = simple_read_from_buffer(userbuf, count, ppos,
-				       data, datasize + sizeof(attributes));
+	size = simple_copy_to_iter(data, &iocb->ki_pos,
+				   datasize + sizeof(attributes), to);
 out_free:
 	kfree(data);
 
@@ -108,7 +107,7 @@ static ssize_t efivarfs_file_read(struct file *file, char __user *userbuf,
 
 const struct file_operations efivarfs_file_operations = {
 	.open	= simple_open,
-	.read	= efivarfs_file_read,
-	.write	= efivarfs_file_write,
+	.read_iter	= efivarfs_file_read,
+	.write_iter	= efivarfs_file_write,
 	.llseek	= no_llseek,
 };
Signature · 1 line
2.43.0
author maintainer
#121 lore raw

PATCH 115/437 drivers/comedi: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/comedi/comedi_fops.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
drivers/comedi/comedi_fops.c +12 -14
index 1b481731df96..0e18fac552d3 100644
@@ -2463,8 +2463,7 @@ static __poll_t comedi_poll(struct file *file, poll_table *wait)
 	return mask;
 }
 
-static ssize_t comedi_write(struct file *file, const char __user *buf,
-			    size_t nbytes, loff_t *offset)
+static ssize_t comedi_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	struct comedi_subdevice *s;
 	struct comedi_async *async;
@@ -2472,7 +2471,9 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
 	ssize_t count = 0;
 	int retval = 0;
 	DECLARE_WAITQUEUE(wait, current);
+	struct file *file = iocb->ki_filp;
 	struct comedi_file *cfp = file->private_data;
+	size_t nbytes = iov_iter_count(from);
 	struct comedi_device *dev = cfp->dev;
 	bool become_nonbusy = false;
 	bool attach_locked;
@@ -2546,11 +2547,11 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
 		wp = async->buf_write_ptr;
 		n1 = min(n, async->prealloc_bufsz - wp);
 		n2 = n - n1;
-		m = copy_from_user(async->prealloc_buf + wp, buf, n1);
+		m = copy_from_iter(async->prealloc_buf + wp, n1, from);
 		if (m)
 			m += n2;
 		else if (n2)
-			m = copy_from_user(async->prealloc_buf, buf + n1, n2);
+			m = copy_from_iter(async->prealloc_buf, n2, from);
 		if (m) {
 			n -= m;
 			retval = -EFAULT;
@@ -2559,8 +2560,6 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
 
 		count += n;
 		nbytes -= n;
-
-		buf += n;
 	}
 	remove_wait_queue(&async->wait_head, &wait);
 	set_current_state(TASK_RUNNING);
@@ -2599,8 +2598,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
 	return count ? count : retval;
 }
 
-static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
-			   loff_t *offset)
+static ssize_t comedi_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct comedi_subdevice *s;
 	struct comedi_async *async;
@@ -2608,7 +2606,9 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
 	ssize_t count = 0;
 	int retval = 0;
 	DECLARE_WAITQUEUE(wait, current);
+	struct file *file = iocb->ki_filp;
 	struct comedi_file *cfp = file->private_data;
+	size_t nbytes = iov_iter_count(to);
 	struct comedi_device *dev = cfp->dev;
 	unsigned int old_detach_count;
 	bool become_nonbusy = false;
@@ -2680,11 +2680,11 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
 		rp = async->buf_read_ptr;
 		n1 = min(n, async->prealloc_bufsz - rp);
 		n2 = n - n1;
-		m = copy_to_user(buf, async->prealloc_buf + rp, n1);
+		m = copy_to_iter(async->prealloc_buf + rp, n1, to);
 		if (m)
 			m += n2;
 		else if (n2)
-			m = copy_to_user(buf + n1, async->prealloc_buf, n2);
+			m = copy_to_iter(async->prealloc_buf, n2, to);
 		if (m) {
 			n -= m;
 			retval = -EFAULT;
@@ -2695,8 +2695,6 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
 
 		count += n;
 		nbytes -= n;
-
-		buf += n;
 	}
 	remove_wait_queue(&async->wait_head, &wait);
 	set_current_state(TASK_RUNNING);
@@ -3179,8 +3177,8 @@ static const struct file_operations comedi_fops = {
 	.compat_ioctl = comedi_compat_ioctl,
 	.open = comedi_open,
 	.release = comedi_close,
-	.read = comedi_read,
-	.write = comedi_write,
+	.read_iter = comedi_read,
+	.write_iter = comedi_write,
 	.mmap = comedi_mmap,
 	.poll = comedi_poll,
 	.fasync = comedi_fasync,
Signature · 1 line
2.43.0
author maintainer
#122 lore raw

PATCH 116/437 drivers/counter: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/counter/counter-chrdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/counter/counter-chrdev.c +2 -1
index afc94d0062b1..f2d513248120 100644
@@ -99,6 +99,7 @@ static ssize_t counter_chrdev_read(struct file *filp, char __user *buf,
 
 	return copied;
 }
+FOPS_READ_ITER_HELPER(counter_chrdev_read);
 
 static __poll_t counter_chrdev_poll(struct file *filp,
 				    struct poll_table_struct *pollt)
@@ -455,7 +456,7 @@ static int counter_chrdev_release(struct inode *inode, struct file *filp)
 static const struct file_operations counter_fops = {
 	.owner = THIS_MODULE,
 	.llseek = no_llseek,
-	.read = counter_chrdev_read,
+	.read_iter = counter_chrdev_read_iter,
 	.poll = counter_chrdev_poll,
 	.unlocked_ioctl = counter_chrdev_ioctl,
 	.open = counter_chrdev_open,
Signature · 1 line
2.43.0
author maintainer
#123 lore raw

PATCH 117/437 drivers/hid: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/hid/hid-debug.c           |  3 +-
 drivers/hid/hid-picolcd_debugfs.c | 65 +++++++++++++++++--------------
 drivers/hid/hid-roccat.c          | 12 +++---
 drivers/hid/hid-sensor-custom.c   |  3 +-
 drivers/hid/hid-wiimote-debug.c   | 15 +++----
 drivers/hid/hidraw.c              | 15 +++----
 drivers/hid/uhid.c                | 15 +++----
 7 files changed, 69 insertions(+), 59 deletions(-)
drivers/hid/hid-debug.c +2 -1
index 7dd83ec74f8a..d5110cd9b440 100644
@@ -1206,6 +1206,7 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
 	mutex_unlock(&list->read_mutex);
 	return ret;
 }
+FOPS_READ_ITER_HELPER(hid_debug_events_read);
 
 static __poll_t hid_debug_events_poll(struct file *file, poll_table *wait)
 {
@@ -1240,7 +1241,7 @@ DEFINE_SHOW_ATTRIBUTE(hid_debug_rdesc);
 static const struct file_operations hid_debug_events_fops = {
 	.owner =        THIS_MODULE,
 	.open           = hid_debug_events_open,
-	.read           = hid_debug_events_read,
+	.read_iter      = hid_debug_events_read_iter,
 	.poll		= hid_debug_events_poll,
 	.release        = hid_debug_events_release,
 	.llseek		= noop_llseek,
drivers/hid/hid-picolcd_debugfs.c +35 -30

154 lines not on this page · raw message

drivers/hid/hid-roccat.c +6 -6
index c7f7562e22e5..072da9cf04a9 100644
@@ -70,14 +70,14 @@ static struct roccat_device *devices[ROCCAT_MAX_DEVICES];
 /* protects modifications of devices array */
 static DEFINE_MUTEX(devices_lock);
 
-static ssize_t roccat_read(struct file *file, char __user *buffer,
-		size_t count, loff_t *ppos)
+static ssize_t roccat_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct roccat_reader *reader = file->private_data;
+	struct roccat_reader *reader = iocb->ki_filp->private_data;
 	struct roccat_device *device = reader->device;
 	struct roccat_report *report;
 	ssize_t retval = 0, len;
 	DECLARE_WAITQUEUE(wait, current);
+	size_t count = iov_iter_count(to);
 
 	mutex_lock(&device->cbuf_lock);
 
@@ -88,7 +88,7 @@ static ssize_t roccat_read(struct file *file, char __user *buffer,
 
 		/* wait for data */
 		while (reader->cbuf_start == device->cbuf_end) {
-			if (file->f_flags & O_NONBLOCK) {
+			if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 				retval = -EAGAIN;
 				break;
 			}
@@ -122,7 +122,7 @@ static ssize_t roccat_read(struct file *file, char __user *buffer,
 	 */
 	len = device->report_size > count ? count : device->report_size;
 
-	if (copy_to_user(buffer, report->value, len)) {
+	if (!copy_to_iter_full(report->value, len, to)) {
 		retval = -EFAULT;
 		goto exit_unlock;
 	}
@@ -407,7 +407,7 @@ static long roccat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 static const struct file_operations roccat_ops = {
 	.owner = THIS_MODULE,
-	.read = roccat_read,
+	.read_iter = roccat_read,
 	.poll = roccat_poll,
 	.open = roccat_open,
 	.release = roccat_release,
drivers/hid/hid-sensor-custom.c +2 -1
index d85398721659..a4e58e82b3f1 100644
@@ -669,6 +669,7 @@ static ssize_t hid_sensor_custom_read(struct file *file, char __user *buf,
 
 	return copied;
 }
+FOPS_READ_ITER_HELPER(hid_sensor_custom_read);
 
 static int hid_sensor_custom_release(struct inode *inode, struct file *file)
 {
@@ -714,7 +715,7 @@ static __poll_t hid_sensor_custom_poll(struct file *file,
 
 static const struct file_operations hid_sensor_custom_fops = {
 	.open =  hid_sensor_custom_open,
-	.read =  hid_sensor_custom_read,
+	.read_iter =  hid_sensor_custom_read_iter,
 	.release = hid_sensor_custom_release,
 	.poll = hid_sensor_custom_poll,
 	.llseek = noop_llseek,
drivers/hid/hid-wiimote-debug.c +8 -7
index 00f9be55f148..5a7a0991a8f7 100644
@@ -71,11 +71,12 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
 
 	return ret;
 }
+FOPS_READ_ITER_HELPER(wiidebug_eeprom_read);
 
 static const struct file_operations wiidebug_eeprom_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = wiidebug_eeprom_read,
+	.read_iter = wiidebug_eeprom_read_iter,
 	.llseek = generic_file_llseek,
 };
 
@@ -121,11 +122,11 @@ static int wiidebug_drm_open(struct inode *i, struct file *f)
 	return single_open(f, wiidebug_drm_show, i->i_private);
 }
 
-static ssize_t wiidebug_drm_write(struct file *f, const char __user *u,
-							size_t s, loff_t *off)
+static ssize_t wiidebug_drm_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *sf = f->private_data;
+	struct seq_file *sf = iocb->ki_filp->private_data;
 	struct wiimote_debug *dbg = sf->private;
+	size_t s = iov_iter_count(from);
 	unsigned long flags;
 	char buf[16];
 	ssize_t len;
@@ -135,7 +136,7 @@ static ssize_t wiidebug_drm_write(struct file *f, const char __user *u,
 		return -EINVAL;
 
 	len = min((size_t) 15, s);
-	if (copy_from_user(buf, u, len))
+	if (!copy_from_iter_full(buf, len, from))
 		return -EFAULT;
 
 	buf[len] = 0;
@@ -163,9 +164,9 @@ static ssize_t wiidebug_drm_write(struct file *f, const char __user *u,
 static const struct file_operations wiidebug_drm_fops = {
 	.owner = THIS_MODULE,
 	.open = wiidebug_drm_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
-	.write = wiidebug_drm_write,
+	.write_iter = wiidebug_drm_write,
 	.release = single_release,
 };
 
drivers/hid/hidraw.c +8 -7
index 2bc762d31ac7..54fab17f45a5 100644
@@ -38,9 +38,10 @@ static const struct class hidraw_class = {
 static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES];
 static DECLARE_RWSEM(minors_rwsem);
 
-static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t hidraw_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hidraw_list *list = file->private_data;
+	struct hidraw_list *list = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	int ret = 0, len;
 	DECLARE_WAITQUEUE(wait, current);
 
@@ -60,7 +61,7 @@ static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count,
 					ret = -EIO;
 					break;
 				}
-				if (file->f_flags & O_NONBLOCK) {
+				if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 					ret = -EAGAIN;
 					break;
 				}
@@ -83,7 +84,7 @@ static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count,
 			count : list->buffer[list->tail].len;
 
 		if (list->buffer[list->tail].value) {
-			if (copy_to_user(buffer, list->buffer[list->tail].value, len)) {
+			if (!copy_to_iter_full(list->buffer[list->tail].value, len, to)) {
 				ret = -EFAULT;
 				goto out;
 			}
@@ -167,7 +168,7 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t
 	up_read(&minors_rwsem);
 	return ret;
 }
-
+FOPS_WRITE_ITER_HELPER(hidraw_write);
 
 /*
  * This function performs a Get_Report transfer over the control endpoint
@@ -505,8 +506,8 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
 
 static const struct file_operations hidraw_ops = {
 	.owner =        THIS_MODULE,
-	.read =         hidraw_read,
-	.write =        hidraw_write,
+	.read_iter =    hidraw_read,
+	.write_iter =   hidraw_write_iter,
 	.poll =         hidraw_poll,
 	.open =         hidraw_open,
 	.release =      hidraw_release,
drivers/hid/uhid.c +8 -7
index a54c7995b9be..fb23cff65c92 100644
@@ -669,10 +669,10 @@ static int uhid_char_release(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t uhid_char_read(struct file *file, char __user *buffer,
-				size_t count, loff_t *ppos)
+static ssize_t uhid_char_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct uhid_device *uhid = file->private_data;
+	struct uhid_device *uhid = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	int ret;
 	unsigned long flags;
 	size_t len;
@@ -682,7 +682,7 @@ static ssize_t uhid_char_read(struct file *file, char __user *buffer,
 		return -EINVAL;
 
 try_again:
-	if (file->f_flags & O_NONBLOCK) {
+	if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 		if (uhid->head == uhid->tail)
 			return -EAGAIN;
 	} else {
@@ -701,7 +701,7 @@ static ssize_t uhid_char_read(struct file *file, char __user *buffer,
 		goto try_again;
 	} else {
 		len = min(count, sizeof(**uhid->outq));
-		if (copy_to_user(buffer, uhid->outq[uhid->tail], len)) {
+		if (!copy_to_iter_full(uhid->outq[uhid->tail], len, to)) {
 			ret = -EFAULT;
 		} else {
 			kfree(uhid->outq[uhid->tail]);
@@ -782,6 +782,7 @@ static ssize_t uhid_char_write(struct file *file, const char __user *buffer,
 	/* return "count" not "len" to not confuse the caller */
 	return ret ? ret : count;
 }
+FOPS_WRITE_ITER_HELPER(uhid_char_write);
 
 static __poll_t uhid_char_poll(struct file *file, poll_table *wait)
 {
@@ -800,8 +801,8 @@ static const struct file_operations uhid_fops = {
 	.owner		= THIS_MODULE,
 	.open		= uhid_char_open,
 	.release	= uhid_char_release,
-	.read		= uhid_char_read,
-	.write		= uhid_char_write,
+	.read_iter	= uhid_char_read,
+	.write_iter	= uhid_char_write_iter,
 	.poll		= uhid_char_poll,
 	.llseek		= no_llseek,
 };
Signature · 1 line
2.43.0
author maintainer
#124 lore raw

PATCH 118/437 drivers/tty: convert to ->read_iter and ->write_iter

In reply to Jens Axboe
---
 drivers/tty/serial/pch_uart.c |  9 ++++-----
 drivers/tty/vt/vc_screen.c    | 32 +++++++++++++++-----------------
 2 files changed, 19 insertions(+), 22 deletions(-)
drivers/tty/serial/pch_uart.c +4 -5
index 89257cddf540..a61410eb67b1 100644
@@ -290,10 +290,9 @@ static const int trigger_level_1[4] = { 1, 1, 1, 1 };
 #define PCH_REGS_BUFSIZE	1024
 
 
-static ssize_t port_show_regs(struct file *file, char __user *user_buf,
-				size_t count, loff_t *ppos)
+static ssize_t port_show_regs(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct eg20t_port *priv = file->private_data;
+	struct eg20t_port *priv = iocb->ki_filp->private_data;
 	char *buf;
 	u32 len = 0;
 	ssize_t ret;
@@ -335,7 +334,7 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
 	if (len > PCH_REGS_BUFSIZE)
 		len = PCH_REGS_BUFSIZE;
 
-	ret =  simple_read_from_buffer(user_buf, count, ppos, buf, len);
+	ret =  simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 	kfree(buf);
 	return ret;
 }
@@ -343,7 +342,7 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
 static const struct file_operations port_regs_ops = {
 	.owner		= THIS_MODULE,
 	.open		= simple_open,
-	.read		= port_show_regs,
+	.read_iter	= port_show_regs,
 	.llseek		= default_llseek,
 };
 
drivers/tty/vt/vc_screen.c +15 -17
index 67e2cb7c96ee..56daaa568866 100644
@@ -361,10 +361,10 @@ static unsigned int vcs_read_buf(const struct vc_data *vc, char *con_buf,
 	return filled;
 }
 
-static ssize_t
-vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t vcs_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct inode *inode = file_inode(file);
+	struct inode *inode = file_inode(iocb->ki_filp);
+	size_t count = iov_iter_count(to);
 	struct vc_data *vc;
 	struct vcs_poll_data *poll;
 	unsigned int read;
@@ -377,7 +377,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 	if (!con_buf)
 		return -ENOMEM;
 
-	pos = *ppos;
+	pos = iocb->ki_pos;
 
 	/* Select the proper current console and verify
 	 * sanity of the situation under the console lock.
@@ -394,7 +394,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 	if (uni_mode && (pos | count) & 3)
 		goto unlock_out;
 
-	poll = file->private_data;
+	poll = iocb->ki_filp->private_data;
 	if (count && poll)
 		poll->event = 0;
 	read = 0;
@@ -453,7 +453,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 		 */
 
 		console_unlock();
-		ret = copy_to_user(buf, con_buf + skip, this_round);
+		ret = !copy_to_iter_full(con_buf + skip, this_round, to);
 		console_lock();
 
 		if (ret) {
@@ -461,12 +461,11 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 			ret = -EFAULT;
 			break;
 		}
-		buf += this_round;
 		pos += this_round;
 		read += this_round;
 		count -= this_round;
 	}
-	*ppos += read;
+	iocb->ki_pos += read;
 	if (read)
 		ret = read;
 unlock_out:
@@ -586,10 +585,10 @@ static u16 *vcs_write_buf(struct vc_data *vc, const char *con_buf,
 	return org;
 }
 
-static ssize_t
-vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
+static ssize_t vcs_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct inode *inode = file_inode(file);
+	struct inode *inode = file_inode(iocb->ki_filp);
+	size_t count = iov_iter_count(from);
 	struct vc_data *vc;
 	char *con_buf;
 	u16 *org0, *org;
@@ -606,7 +605,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
 	if (!con_buf)
 		return -ENOMEM;
 
-	pos = *ppos;
+	pos = iocb->ki_pos;
 
 	/* Select the proper current console and verify
 	 * sanity of the situation under the console lock.
@@ -640,7 +639,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
 		 * in the write data from userspace safely.
 		 */
 		console_unlock();
-		ret = copy_from_user(con_buf, buf, this_round);
+		ret = !copy_from_iter_full(con_buf, this_round, from);
 		console_lock();
 
 		if (ret) {
@@ -692,12 +691,11 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
 
 		count -= this_round;
 		written += this_round;
-		buf += this_round;
 		pos += this_round;
 		if (org)
 			update_region(vc, (unsigned long)(org0), org - org0);
 	}
-	*ppos += written;
+	iocb->ki_pos += written;
 	ret = written;
 	if (written)
 		vcs_scr_updated(vc);
@@ -778,8 +776,8 @@ static int vcs_release(struct inode *inode, struct file *file)
 
 static const struct file_operations vcs_fops = {
 	.llseek		= vcs_lseek,
-	.read		= vcs_read,
-	.write		= vcs_write,
+	.read_iter	= vcs_read,
+	.write_iter	= vcs_write,
 	.poll		= vcs_poll,
 	.fasync		= vcs_fasync,
 	.open		= vcs_open,
Signature · 1 line
2.43.0
author maintainer
#125 lore raw

PATCH 119/437 drivers/auxdisplay: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/auxdisplay/charlcd.c | 3 ++-
 drivers/auxdisplay/panel.c   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/auxdisplay/charlcd.c +2 -1
index 6d309e4971b6..b40af38d69b1 100644
@@ -487,6 +487,7 @@ static ssize_t charlcd_write(struct file *file, const char __user *buf,
 
 	return tmp - buf;
 }
+FOPS_WRITE_ITER_HELPER(charlcd_write);
 
 static int charlcd_open(struct inode *inode, struct file *file)
 {
@@ -521,7 +522,7 @@ static int charlcd_release(struct inode *inode, struct file *file)
 }
 
 static const struct file_operations charlcd_fops = {
-	.write   = charlcd_write,
+	.write_iter = charlcd_write_iter,
 	.open    = charlcd_open,
 	.release = charlcd_release,
 	.llseek  = no_llseek,
drivers/auxdisplay/panel.c +2 -1
index 049ff443e790..0e5d8d09b60f 100644
@@ -1045,6 +1045,7 @@ static ssize_t keypad_read(struct file *file,
 
 	return tmp - buf;
 }
+FOPS_READ_ITER_HELPER(keypad_read);
 
 static int keypad_open(struct inode *inode, struct file *file)
 {
@@ -1072,7 +1073,7 @@ static int keypad_release(struct inode *inode, struct file *file)
 }
 
 static const struct file_operations keypad_fops = {
-	.read    = keypad_read,		/* read */
+	.read_iter = keypad_read_iter,	/* read */
 	.open    = keypad_open,		/* open */
 	.release = keypad_release,	/* close */
 	.llseek  = default_llseek,
Signature · 1 line
2.43.0
author maintainer
#126 lore raw

PATCH 120/437 fs/eventfd: convert to read/write iterators

In reply to Jens Axboe
---
 fs/eventfd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/eventfd.c +6 -6
index 9afdb722fa92..6995253a37f3 100644
@@ -244,16 +244,16 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
 	return sizeof(ucnt);
 }
 
-static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t count,
-			     loff_t *ppos)
+static ssize_t eventfd_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct eventfd_ctx *ctx = file->private_data;
+	struct eventfd_ctx *ctx = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	ssize_t res;
 	__u64 ucnt;
 
 	if (count != sizeof(ucnt))
 		return -EINVAL;
-	if (copy_from_user(&ucnt, buf, sizeof(ucnt)))
+	if (!copy_from_iter_full(&ucnt, sizeof(ucnt), from))
 		return -EFAULT;
 	if (ucnt == ULLONG_MAX)
 		return -EINVAL;
@@ -261,7 +261,7 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
 	res = -EAGAIN;
 	if (ULLONG_MAX - ctx->count > ucnt)
 		res = sizeof(ucnt);
-	else if (!(file->f_flags & O_NONBLOCK)) {
+	else if (!(iocb->ki_filp->f_flags & O_NONBLOCK)) {
 		res = wait_event_interruptible_locked_irq(ctx->wqh,
 				ULLONG_MAX - ctx->count > ucnt);
 		if (!res)
@@ -306,7 +306,7 @@ static const struct file_operations eventfd_fops = {
 	.release	= eventfd_release,
 	.poll		= eventfd_poll,
 	.read_iter	= eventfd_read,
-	.write		= eventfd_write,
+	.write_iter	= eventfd_write,
 	.llseek		= noop_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#127 lore raw

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

In reply to 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(-)
drivers/input/evdev.c +4 -2
index 51e0c4954600..9f41631df926 100644
@@ -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,
drivers/input/joydev.c +11 -11
index 5824bca02e5a..e84acc296aaa 100644
@@ -23,6 +23,7 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/cdev.h>
+#include <linux/uio.h>
 
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
 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,
drivers/input/keyboard/applespi.c +5 -6
index cf25177b4830..fa1ce0d23f14 100644
@@ -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,
 };
 
drivers/input/misc/uinput.c +4 -2
index d98212d55108..960a0c729bc2 100644
@@ -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
drivers/input/mousedev.c +9 -7
index 505c562a5daa..5d1905f078d1 100644
@@ -24,6 +24,7 @@
 #include <linux/device.h>
 #include <linux/cdev.h>
 #include <linux/kernel.h>
+#include <linux/uio.h>
 
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
 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,
drivers/input/serio/serio_raw.c +4 -2
index 1e4770094415..3b4e72fdcd4f 100644
@@ -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,
drivers/input/serio/userio.c +11 -11
index 9ab5c45c3a9f..3688579d69d2 100644
@@ -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,
 };
drivers/input/touchscreen/edt-ft5x06.c +10 -9
index 2a1db1134476..fe1b0a2c0925 100644
@@ -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,
Signature · 1 line
2.43.0
author maintainer
#128 lore raw

PATCH 122/437 drivers/pci: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/pci/pcie/aer_inject.c  |  9 +++++----
 drivers/pci/switch/switchtec.c | 33 ++++++++++++++++-----------------
 drivers/pci/vgaarb.c           | 21 +++++++++++----------
 3 files changed, 32 insertions(+), 31 deletions(-)
drivers/pci/pcie/aer_inject.c +5 -4
index 2dab275d252f..869abe6a82ab 100644
@@ -21,6 +21,7 @@
 #include <linux/pci.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
+#include <linux/uio.h>
 #include <linux/uaccess.h>
 #include <linux/stddef.h>
 #include <linux/device.h>
@@ -483,9 +484,9 @@ static int aer_inject(struct aer_error_inj *einj)
 	return ret;
 }
 
-static ssize_t aer_inject_write(struct file *filp, const char __user *ubuf,
-				size_t usize, loff_t *off)
+static ssize_t aer_inject_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t usize = iov_iter_count(from);
 	struct aer_error_inj einj;
 	int ret;
 
@@ -496,7 +497,7 @@ static ssize_t aer_inject_write(struct file *filp, const char __user *ubuf,
 		return -EINVAL;
 
 	memset(&einj, 0, sizeof(einj));
-	if (copy_from_user(&einj, ubuf, usize))
+	if (!copy_from_iter_full(&einj, usize, from))
 		return -EFAULT;
 
 	ret = aer_inject(&einj);
@@ -504,7 +505,7 @@ static ssize_t aer_inject_write(struct file *filp, const char __user *ubuf,
 }
 
 static const struct file_operations aer_inject_fops = {
-	.write = aer_inject_write,
+	.write_iter = aer_inject_write,
 	.owner = THIS_MODULE,
 	.llseek = noop_llseek,
 };
drivers/pci/switch/switchtec.c +16 -17
index 5a4adf6c04cf..db6f578e854c 100644
@@ -15,6 +15,7 @@
 #include <linux/wait.h>
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/nospec.h>
+#include <linux/uio.h>
 
 MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver");
 MODULE_VERSION("0.1");
@@ -503,11 +504,11 @@ static int lock_mutex_and_test_alive(struct switchtec_dev *stdev)
 	return 0;
 }
 
-static ssize_t switchtec_dev_write(struct file *filp, const char __user *data,
-				   size_t size, loff_t *off)
+static ssize_t switchtec_dev_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct switchtec_user *stuser = filp->private_data;
+	struct switchtec_user *stuser = iocb->ki_filp->private_data;
 	struct switchtec_dev *stdev = stuser->stdev;
+	size_t size = iov_iter_count(from);
 	int rc;
 
 	if (size < sizeof(stuser->cmd) ||
@@ -525,7 +526,7 @@ static ssize_t switchtec_dev_write(struct file *filp, const char __user *data,
 		goto out;
 	}
 
-	rc = copy_from_user(&stuser->cmd, data, sizeof(stuser->cmd));
+	rc = !copy_from_iter_full(&stuser->cmd, sizeof(stuser->cmd), from);
 	if (rc) {
 		rc = -EFAULT;
 		goto out;
@@ -537,8 +538,7 @@ static ssize_t switchtec_dev_write(struct file *filp, const char __user *data,
 		goto out;
 	}
 
-	data += sizeof(stuser->cmd);
-	rc = copy_from_user(&stuser->data, data, size - sizeof(stuser->cmd));
+	rc = !copy_from_iter_full(&stuser->data, size - sizeof(stuser->cmd), from);
 	if (rc) {
 		rc = -EFAULT;
 		goto out;
@@ -555,11 +555,11 @@ static ssize_t switchtec_dev_write(struct file *filp, const char __user *data,
 	return size;
 }
 
-static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
-				  size_t size, loff_t *off)
+static ssize_t switchtec_dev_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct switchtec_user *stuser = filp->private_data;
+	struct switchtec_user *stuser = iocb->ki_filp->private_data;
 	struct switchtec_dev *stdev = stuser->stdev;
+	size_t size = iov_iter_count(to);
 	int rc;
 
 	if (size < sizeof(stuser->cmd) ||
@@ -579,7 +579,7 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
 
 	mutex_unlock(&stdev->mrpc_mutex);
 
-	if (filp->f_flags & O_NONBLOCK) {
+	if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 		if (!stuser->cmd_done)
 			return -EAGAIN;
 	} else {
@@ -603,16 +603,15 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
 		return -EBADE;
 	}
 
-	rc = copy_to_user(data, &stuser->return_code,
-			  sizeof(stuser->return_code));
+	rc = !copy_to_iter_full(&stuser->return_code,
+				sizeof(stuser->return_code), to);
 	if (rc) {
 		mutex_unlock(&stdev->mrpc_mutex);
 		return -EFAULT;
 	}
 
-	data += sizeof(stuser->return_code);
-	rc = copy_to_user(data, &stuser->data,
-			  size - sizeof(stuser->return_code));
+	rc = !copy_to_iter_full(&stuser->data,
+				size - sizeof(stuser->return_code), to);
 	if (rc) {
 		mutex_unlock(&stdev->mrpc_mutex);
 		return -EFAULT;
@@ -1247,8 +1246,8 @@ static const struct file_operations switchtec_fops = {
 	.owner = THIS_MODULE,
 	.open = switchtec_dev_open,
 	.release = switchtec_dev_release,
-	.write = switchtec_dev_write,
-	.read = switchtec_dev_read,
+	.write_iter = switchtec_dev_write,
+	.read_iter = switchtec_dev_read,
 	.poll = switchtec_dev_poll,
 	.unlocked_ioctl = switchtec_dev_ioctl,
 	.compat_ioctl = compat_ptr_ioctl,
drivers/pci/vgaarb.c +11 -10
index 78748e8d2dba..a5051fae9bcb 100644
@@ -31,6 +31,7 @@
 #include <linux/console.h>
 #include <linux/acpi.h>
 #include <linux/uaccess.h>
+#include <linux/uio.h>
 #include <linux/vgaarb.h>
 
 static void vga_arbiter_notify_clients(void);
@@ -1088,10 +1089,10 @@ static int vga_pci_str_to_vars(char *buf, int count, unsigned int *domain,
 	return 1;
 }
 
-static ssize_t vga_arb_read(struct file *file, char __user *buf,
-			    size_t count, loff_t *ppos)
+static ssize_t vga_arb_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct vga_arb_private *priv = file->private_data;
+	struct vga_arb_private *priv = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	struct vga_device *vgadev;
 	struct pci_dev *pdev;
 	unsigned long flags;
@@ -1141,7 +1142,7 @@ static ssize_t vga_arb_read(struct file *file, char __user *buf,
 	/* Copy that to user */
 	if (len > count)
 		len = count;
-	rc = copy_to_user(buf, lbuf, len);
+	rc = !copy_to_iter_full(lbuf, len, to);
 	kfree(lbuf);
 	if (rc)
 		return -EFAULT;
@@ -1152,10 +1153,10 @@ static ssize_t vga_arb_read(struct file *file, char __user *buf,
  * TODO: To avoid parsing inside kernel and to improve the speed we may
  * consider use ioctl here
  */
-static ssize_t vga_arb_write(struct file *file, const char __user *buf,
-			     size_t count, loff_t *ppos)
+static ssize_t vga_arb_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct vga_arb_private *priv = file->private_data;
+	struct vga_arb_private *priv = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct vga_arb_user_card *uc = NULL;
 	struct pci_dev *pdev;
 
@@ -1169,7 +1170,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
 
 	if (count >= sizeof(kbuf))
 		return -EINVAL;
-	if (copy_from_user(kbuf, buf, count))
+	if (!copy_from_iter_full(kbuf, count, from))
 		return -EFAULT;
 	curr_pos = kbuf;
 	kbuf[count] = '\0';
@@ -1523,8 +1524,8 @@ static struct notifier_block pci_notifier = {
 };
 
 static const struct file_operations vga_arb_device_fops = {
-	.read = vga_arb_read,
-	.write = vga_arb_write,
+	.read_iter = vga_arb_read,
+	.write_iter = vga_arb_write,
 	.poll = vga_arb_fpoll,
 	.open = vga_arb_open,
 	.release = vga_arb_release,
Signature · 1 line
2.43.0
author maintainer
#129 lore raw

PATCH 123/437 fs/fuse: convert to read/write iterators

In reply to Jens Axboe
---
 fs/fuse/control.c | 70 ++++++++++++++++++++---------------------------
 1 file changed, 30 insertions(+), 40 deletions(-)
fs/fuse/control.c +30 -40
index 0ca1d1f418c3..e572013d345e 100644
@@ -43,8 +43,7 @@ static ssize_t fuse_conn_abort_write(struct kiocb *iocb, struct iov_iter *from)
 	return iov_iter_count(from);
 }
 
-static ssize_t fuse_conn_waiting_read_iter(struct kiocb *iocb,
-					   struct iov_iter *to)
+static ssize_t fuse_conn_waiting_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	char tmp[32];
 	size_t size;
@@ -63,27 +62,27 @@ static ssize_t fuse_conn_waiting_read_iter(struct kiocb *iocb,
 	return simple_copy_to_iter(tmp, &iocb->ki_pos, size, to);
 }
 
-static ssize_t fuse_conn_limit_read(struct file *file, char __user *buf,
-				    size_t len, loff_t *ppos, unsigned val)
+static ssize_t fuse_conn_limit_read(struct kiocb *iocb, struct iov_iter *to,
+				    unsigned val)
 {
 	char tmp[32];
 	size_t size = sprintf(tmp, "%u\n", val);
 
-	return simple_read_from_buffer(buf, len, ppos, tmp, size);
+	return simple_copy_to_iter(tmp, &iocb->ki_pos, size, to);
 }
 
-static ssize_t fuse_conn_limit_write(struct file *file, const char __user *buf,
-				     size_t count, loff_t *ppos, unsigned *val,
-				     unsigned global_limit)
+static ssize_t fuse_conn_limit_write(struct kiocb *iocb, struct iov_iter *from,
+				     unsigned *val, unsigned global_limit)
 {
 	unsigned long t;
 	unsigned limit = (1 << 16) - 1;
+	size_t count = iov_iter_count(from);
 	int err;
 
-	if (*ppos)
+	if (iocb->ki_pos)
 		return -EINVAL;
 
-	err = kstrtoul_from_user(buf, count, 0, &t);
+	err = kstrtoul_from_iter(from, count, 0, &t);
 	if (err)
 		return err;
 
@@ -98,35 +97,31 @@ static ssize_t fuse_conn_limit_write(struct file *file, const char __user *buf,
 	return count;
 }
 
-static ssize_t fuse_conn_max_background_read(struct file *file,
-					     char __user *buf, size_t len,
-					     loff_t *ppos)
+static ssize_t fuse_conn_max_background_read(struct kiocb *iocb,
+					     struct iov_iter *to)
 {
 	struct fuse_conn *fc;
 	unsigned val;
 
-	fc = fuse_ctl_file_conn_get(file);
+	fc = fuse_ctl_file_conn_get(iocb->ki_filp);
 	if (!fc)
 		return 0;
 
 	val = READ_ONCE(fc->max_background);
 	fuse_conn_put(fc);
 
-	return fuse_conn_limit_read(file, buf, len, ppos, val);
+	return fuse_conn_limit_read(iocb, to, val);
 }
-FOPS_READ_ITER_HELPER(fuse_conn_max_background_read);
 
-static ssize_t fuse_conn_max_background_write(struct file *file,
-					      const char __user *buf,
-					      size_t count, loff_t *ppos)
+static ssize_t fuse_conn_max_background_write(struct kiocb *iocb,
+					      struct iov_iter *from)
 {
 	unsigned val;
 	ssize_t ret;
 
-	ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
-				    max_user_bgreq);
+	ret = fuse_conn_limit_write(iocb, from, &val, max_user_bgreq);
 	if (ret > 0) {
-		struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
+		struct fuse_conn *fc = fuse_ctl_file_conn_get(iocb->ki_filp);
 		if (fc) {
 			spin_lock(&fc->bg_lock);
 			fc->max_background = val;
@@ -140,38 +135,34 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
 
 	return ret;
 }
-FOPS_WRITE_ITER_HELPER(fuse_conn_max_background_write);
 
-static ssize_t fuse_conn_congestion_threshold_read(struct file *file,
-						   char __user *buf, size_t len,
-						   loff_t *ppos)
+static ssize_t fuse_conn_congestion_threshold_read(struct kiocb *iocb,
+						   struct iov_iter *to)
 {
 	struct fuse_conn *fc;
 	unsigned val;
 
-	fc = fuse_ctl_file_conn_get(file);
+	fc = fuse_ctl_file_conn_get(iocb->ki_filp);
 	if (!fc)
 		return 0;
 
 	val = READ_ONCE(fc->congestion_threshold);
 	fuse_conn_put(fc);
 
-	return fuse_conn_limit_read(file, buf, len, ppos, val);
+	return fuse_conn_limit_read(iocb, to, val);
 }
 
-static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
-						    const char __user *buf,
-						    size_t count, loff_t *ppos)
+static ssize_t fuse_conn_congestion_threshold_write(struct kiocb *iocb,
+						    struct iov_iter *from)
 {
 	unsigned val;
 	struct fuse_conn *fc;
 	ssize_t ret;
 
-	ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
-				    max_user_congthresh);
+	ret = fuse_conn_limit_write(iocb, from, &val, max_user_congthresh);
 	if (ret <= 0)
 		goto out;
-	fc = fuse_ctl_file_conn_get(file);
+	fc = fuse_ctl_file_conn_get(iocb->ki_filp);
 	if (!fc)
 		goto out;
 
@@ -180,7 +171,6 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
 out:
 	return ret;
 }
-FOPS_WRITE_ITER_HELPER(fuse_conn_congestion_threshold_write);
 
 static const struct file_operations fuse_ctl_abort_ops = {
 	.open = nonseekable_open,
@@ -190,21 +180,21 @@ static const struct file_operations fuse_ctl_abort_ops = {
 
 static const struct file_operations fuse_ctl_waiting_ops = {
 	.open = nonseekable_open,
-	.read_iter = fuse_conn_waiting_read_iter,
+	.read_iter = fuse_conn_waiting_read,
 	.llseek = no_llseek,
 };
 
 static const struct file_operations fuse_conn_max_background_ops = {
 	.open = nonseekable_open,
-	.read_iter = fuse_conn_max_background_read_iter,
-	.write_iter = fuse_conn_max_background_write_iter,
+	.read_iter = fuse_conn_max_background_read,
+	.write_iter = fuse_conn_max_background_write,
 	.llseek = no_llseek,
 };
 
 static const struct file_operations fuse_conn_congestion_threshold_ops = {
 	.open = nonseekable_open,
-	.read = fuse_conn_congestion_threshold_read,
-	.write_iter = fuse_conn_congestion_threshold_write_iter,
+	.read_iter = fuse_conn_congestion_threshold_read,
+	.write_iter = fuse_conn_congestion_threshold_write,
 	.llseek = no_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#130 lore raw

PATCH 124/437 firmware: arm_scmi: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/firmware/arm_scmi/raw_mode.c | 94 ++++++++++++----------------
 1 file changed, 40 insertions(+), 54 deletions(-)
drivers/firmware/arm_scmi/raw_mode.c +40 -54
index 350573518503..95915540165a 100644
@@ -765,46 +765,41 @@ static int scmi_raw_message_receive(struct scmi_raw_mode_info *raw,
 
 /* SCMI Raw debugfs helpers */
 
-static ssize_t scmi_dbg_raw_mode_common_read(struct file *filp,
-					     char __user *buf,
-					     size_t count, loff_t *ppos,
+static ssize_t scmi_dbg_raw_mode_common_read(struct kiocb *iocb,
+					     struct iov_iter *to,
 					     unsigned int idx)
 {
-	ssize_t cnt;
-	struct scmi_dbg_raw_data *rd = filp->private_data;
+	struct scmi_dbg_raw_data *rd = iocb->ki_filp->private_data;
 
 	if (!rd->rx_size) {
 		int ret;
 
 		ret = scmi_raw_message_receive(rd->raw, rd->rx.buf, rd->rx.len,
 					       &rd->rx_size, idx, rd->chan_id,
-					       filp->f_flags & O_NONBLOCK);
+					       iocb->ki_filp->f_flags & O_NONBLOCK);
 		if (ret) {
 			rd->rx_size = 0;
 			return ret;
 		}
 
 		/* Reset any previous filepos change, including writes */
-		*ppos = 0;
-	} else if (*ppos == rd->rx_size) {
+		iocb->ki_pos = 0;
+	} else if (iocb->ki_pos == rd->rx_size) {
 		/* Return EOF once all the message has been read-out */
 		rd->rx_size = 0;
 		return 0;
 	}
 
-	cnt = simple_read_from_buffer(buf, count, ppos,
-				      rd->rx.buf, rd->rx_size);
-
-	return cnt;
+	return simple_copy_to_iter(rd->rx.buf, &iocb->ki_pos, rd->rx_size, to);
 }
 
-static ssize_t scmi_dbg_raw_mode_common_write(struct file *filp,
-					      const char __user *buf,
-					      size_t count, loff_t *ppos,
+static ssize_t scmi_dbg_raw_mode_common_write(struct kiocb *iocb,
+					      struct iov_iter *from,
 					      bool async)
 {
 	int ret;
-	struct scmi_dbg_raw_data *rd = filp->private_data;
+	struct scmi_dbg_raw_data *rd = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 
 	if (count > rd->tx.len - rd->tx_size)
 		return -ENOSPC;
@@ -820,8 +815,8 @@ static ssize_t scmi_dbg_raw_mode_common_write(struct file *filp,
 	if (rd->tx_size < rd->tx_req_size) {
 		ssize_t cnt;
 
-		cnt = simple_write_to_buffer(rd->tx.buf, rd->tx.len, ppos,
-					     buf, count);
+		cnt = simple_copy_from_iter(rd->tx.buf, &iocb->ki_pos,
+					     rd->tx.len, from);
 		if (cnt < 0)
 			return cnt;
 
@@ -835,7 +830,7 @@ static ssize_t scmi_dbg_raw_mode_common_write(struct file *filp,
 
 	/* Reset ppos for next message ... */
 	rd->tx_size = 0;
-	*ppos = 0;
+	iocb->ki_pos = 0;
 
 	return ret ?: count;
 }
@@ -863,19 +858,16 @@ static __poll_t scmi_test_dbg_raw_common_poll(struct file *filp,
 	return mask;
 }
 
-static ssize_t scmi_dbg_raw_mode_message_read(struct file *filp,
-					      char __user *buf,
-					      size_t count, loff_t *ppos)
+static ssize_t scmi_dbg_raw_mode_message_read(struct kiocb *iocb,
+					      struct iov_iter *to)
 {
-	return scmi_dbg_raw_mode_common_read(filp, buf, count, ppos,
-					     SCMI_RAW_REPLY_QUEUE);
+	return scmi_dbg_raw_mode_common_read(iocb, to, SCMI_RAW_REPLY_QUEUE);
 }
 
-static ssize_t scmi_dbg_raw_mode_message_write(struct file *filp,
-					       const char __user *buf,
-					       size_t count, loff_t *ppos)
+static ssize_t scmi_dbg_raw_mode_message_write(struct kiocb *iocb,
+					       struct iov_iter *from)
 {
-	return scmi_dbg_raw_mode_common_write(filp, buf, count, ppos, false);
+	return scmi_dbg_raw_mode_common_write(iocb, from, false);
 }
 
 static __poll_t scmi_dbg_raw_mode_message_poll(struct file *filp,
@@ -935,55 +927,51 @@ static int scmi_dbg_raw_mode_release(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static ssize_t scmi_dbg_raw_mode_reset_write(struct file *filp,
-					     const char __user *buf,
-					     size_t count, loff_t *ppos)
+static ssize_t scmi_dbg_raw_mode_reset_write(struct kiocb *iocb,
+					     struct iov_iter *from)
 {
-	struct scmi_dbg_raw_data *rd = filp->private_data;
+	struct scmi_dbg_raw_data *rd = iocb->ki_filp->private_data;
 
 	scmi_xfer_raw_reset(rd->raw);
 
-	return count;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations scmi_dbg_raw_mode_reset_fops = {
 	.open = scmi_dbg_raw_mode_open,
 	.release = scmi_dbg_raw_mode_release,
-	.write = scmi_dbg_raw_mode_reset_write,
+	.write_iter = scmi_dbg_raw_mode_reset_write,
 	.owner = THIS_MODULE,
 };
 
 static const struct file_operations scmi_dbg_raw_mode_message_fops = {
 	.open = scmi_dbg_raw_mode_open,
 	.release = scmi_dbg_raw_mode_release,
-	.read = scmi_dbg_raw_mode_message_read,
-	.write = scmi_dbg_raw_mode_message_write,
+	.read_iter = scmi_dbg_raw_mode_message_read,
+	.write_iter = scmi_dbg_raw_mode_message_write,
 	.poll = scmi_dbg_raw_mode_message_poll,
 	.owner = THIS_MODULE,
 };
 
-static ssize_t scmi_dbg_raw_mode_message_async_write(struct file *filp,
-						     const char __user *buf,
-						     size_t count, loff_t *ppos)
+static ssize_t scmi_dbg_raw_mode_message_async_write(struct kiocb *iocb,
+						     struct iov_iter *from)
 {
-	return scmi_dbg_raw_mode_common_write(filp, buf, count, ppos, true);
+	return scmi_dbg_raw_mode_common_write(iocb, from, true);
 }
 
 static const struct file_operations scmi_dbg_raw_mode_message_async_fops = {
 	.open = scmi_dbg_raw_mode_open,
 	.release = scmi_dbg_raw_mode_release,
-	.read = scmi_dbg_raw_mode_message_read,
-	.write = scmi_dbg_raw_mode_message_async_write,
+	.read_iter = scmi_dbg_raw_mode_message_read,
+	.write_iter = scmi_dbg_raw_mode_message_async_write,
 	.poll = scmi_dbg_raw_mode_message_poll,
 	.owner = THIS_MODULE,
 };
 
-static ssize_t scmi_test_dbg_raw_mode_notif_read(struct file *filp,
-						 char __user *buf,
-						 size_t count, loff_t *ppos)
+static ssize_t scmi_test_dbg_raw_mode_notif_read(struct kiocb *iocb,
+						 struct iov_iter *to)
 {
-	return scmi_dbg_raw_mode_common_read(filp, buf, count, ppos,
-					     SCMI_RAW_NOTIF_QUEUE);
+	return scmi_dbg_raw_mode_common_read(iocb, to, SCMI_RAW_NOTIF_QUEUE);
 }
 
 static __poll_t
@@ -996,17 +984,15 @@ scmi_test_dbg_raw_mode_notif_poll(struct file *filp,
 static const struct file_operations scmi_dbg_raw_mode_notification_fops = {
 	.open = scmi_dbg_raw_mode_open,
 	.release = scmi_dbg_raw_mode_release,
-	.read = scmi_test_dbg_raw_mode_notif_read,
+	.read_iter = scmi_test_dbg_raw_mode_notif_read,
 	.poll = scmi_test_dbg_raw_mode_notif_poll,
 	.owner = THIS_MODULE,
 };
 
-static ssize_t scmi_test_dbg_raw_mode_errors_read(struct file *filp,
-						  char __user *buf,
-						  size_t count, loff_t *ppos)
+static ssize_t scmi_test_dbg_raw_mode_errors_read(struct kiocb *iocb,
+						  struct iov_iter *to)
 {
-	return scmi_dbg_raw_mode_common_read(filp, buf, count, ppos,
-					     SCMI_RAW_ERRS_QUEUE);
+	return scmi_dbg_raw_mode_common_read(iocb, to, SCMI_RAW_ERRS_QUEUE);
 }
 
 static __poll_t
@@ -1019,7 +1005,7 @@ scmi_test_dbg_raw_mode_errors_poll(struct file *filp,
 static const struct file_operations scmi_dbg_raw_mode_errors_fops = {
 	.open = scmi_dbg_raw_mode_open,
 	.release = scmi_dbg_raw_mode_release,
-	.read = scmi_test_dbg_raw_mode_errors_read,
+	.read_iter = scmi_test_dbg_raw_mode_errors_read,
 	.poll = scmi_test_dbg_raw_mode_errors_poll,
 	.owner = THIS_MODULE,
 };
Signature · 1 line
2.43.0
author maintainer
#131 lore raw

PATCH 125/437 firmware: cirrus: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/firmware/cirrus/cs_dsp.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/firmware/cirrus/cs_dsp.c +10 -16
index 9f3d665cfdcf..80a2cba021d1 100644
@@ -398,11 +398,9 @@ static void cs_dsp_debugfs_clear(struct cs_dsp *dsp)
 	dsp->bin_file_name = NULL;
 }
 
-static ssize_t cs_dsp_debugfs_wmfw_read(struct file *file,
-					char __user *user_buf,
-					size_t count, loff_t *ppos)
+static ssize_t cs_dsp_debugfs_wmfw_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct cs_dsp *dsp = file->private_data;
+	struct cs_dsp *dsp = iocb->ki_filp->private_data;
 	ssize_t ret;
 
 	mutex_lock(&dsp->pwr_lock);
@@ -410,19 +408,16 @@ static ssize_t cs_dsp_debugfs_wmfw_read(struct file *file,
 	if (!dsp->wmfw_file_name || !dsp->booted)
 		ret = 0;
 	else
-		ret = simple_read_from_buffer(user_buf, count, ppos,
-					      dsp->wmfw_file_name,
-					      strlen(dsp->wmfw_file_name));
+		ret = simple_copy_to_iter(dsp->wmfw_file_name, &iocb->ki_pos,
+					      strlen(dsp->wmfw_file_name), to);
 
 	mutex_unlock(&dsp->pwr_lock);
 	return ret;
 }
 
-static ssize_t cs_dsp_debugfs_bin_read(struct file *file,
-				       char __user *user_buf,
-				       size_t count, loff_t *ppos)
+static ssize_t cs_dsp_debugfs_bin_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct cs_dsp *dsp = file->private_data;
+	struct cs_dsp *dsp = iocb->ki_filp->private_data;
 	ssize_t ret;
 
 	mutex_lock(&dsp->pwr_lock);
@@ -430,9 +425,8 @@ static ssize_t cs_dsp_debugfs_bin_read(struct file *file,
 	if (!dsp->bin_file_name || !dsp->booted)
 		ret = 0;
 	else
-		ret = simple_read_from_buffer(user_buf, count, ppos,
-					      dsp->bin_file_name,
-					      strlen(dsp->bin_file_name));
+		ret = simple_copy_to_iter(dsp->bin_file_name, &iocb->ki_pos,
+					      strlen(dsp->bin_file_name), to);
 
 	mutex_unlock(&dsp->pwr_lock);
 	return ret;
@@ -446,14 +440,14 @@ static const struct {
 		.name = "wmfw_file_name",
 		.fops = {
 			.open = simple_open,
-			.read = cs_dsp_debugfs_wmfw_read,
+			.read_iter = cs_dsp_debugfs_wmfw_read,
 		},
 	},
 	{
 		.name = "bin_file_name",
 		.fops = {
 			.open = simple_open,
-			.read = cs_dsp_debugfs_bin_read,
+			.read_iter = cs_dsp_debugfs_bin_read,
 		},
 	},
 };
Signature · 1 line
2.43.0
author maintainer
#132 lore raw

PATCH 126/437 firmware: efi: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/firmware/efi/capsule-loader.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/firmware/efi/capsule-loader.c +7 -9
index 97bafb5f7038..9b1d143a64f6 100644
@@ -149,10 +149,8 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info)
 /**
  * efi_capsule_write - store the capsule binary and pass it to
  *		       efi_capsule_update() API
- * @file: file pointer
- * @buff: buffer pointer
- * @count: number of bytes in @buff
- * @offp: not used
+ * @iocb: metadata for IO
+ * @from: buffer pointer
  *
  *	Expectation:
  *	- A user space tool should start at the beginning of capsule binary and
@@ -165,11 +163,11 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info)
  *	- An EFI capsule header must be located at the beginning of capsule
  *	  binary file and passed in as first block data of write operation.
  **/
-static ssize_t efi_capsule_write(struct file *file, const char __user *buff,
-				 size_t count, loff_t *offp)
+static ssize_t efi_capsule_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	int ret;
-	struct capsule_info *cap_info = file->private_data;
+	struct capsule_info *cap_info = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct page *page;
 	void *kbuff = NULL;
 	size_t write_byte;
@@ -202,7 +200,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff,
 
 	/* Copy capsule binary data from user space to kernel space buffer */
 	write_byte = min_t(size_t, count, cap_info->page_bytes_remain);
-	if (copy_from_user(kbuff, buff, write_byte)) {
+	if (!copy_from_iter_full(kbuff, write_byte, from)) {
 		ret = -EFAULT;
 		goto fail_unmap;
 	}
@@ -307,7 +305,7 @@ static int efi_capsule_open(struct inode *inode, struct file *file)
 static const struct file_operations efi_capsule_fops = {
 	.owner = THIS_MODULE,
 	.open = efi_capsule_open,
-	.write = efi_capsule_write,
+	.write_iter = efi_capsule_write,
 	.release = efi_capsule_release,
 	.llseek = no_llseek,
 };
Signature · 1 line
2.43.0
author maintainer
#133 lore raw

PATCH 127/437 firmware: psci: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/firmware/psci/psci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/psci/psci.c +1 -1
index d9629ff87861..06a9aa74c1a5 100644
@@ -440,7 +440,7 @@ static const struct file_operations psci_debugfs_ops = {
 	.owner = THIS_MODULE,
 	.open = psci_debugfs_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek
 };
 
Signature · 1 line
2.43.0
author maintainer
#134 lore raw

PATCH 128/437 firmware: turris-mox-rwtm: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/firmware/turris-mox-rwtm.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/firmware/turris-mox-rwtm.c +11 -11
index 31d962cdd6eb..c7733f4b9bd4 100644
@@ -330,14 +330,14 @@ static int rwtm_debug_open(struct inode *inode, struct file *file)
 	return nonseekable_open(inode, file);
 }
 
-static ssize_t do_sign_read(struct file *file, char __user *buf, size_t len,
-			    loff_t *ppos)
+static ssize_t do_sign_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct mox_rwtm *rwtm = file->private_data;
+	struct mox_rwtm *rwtm = iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(to);
 	ssize_t ret;
 
 	/* only allow one read, of 136 bytes, from position 0 */
-	if (*ppos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (len < 136)
@@ -347,18 +347,18 @@ static ssize_t do_sign_read(struct file *file, char __user *buf, size_t len,
 		return -ENODATA;
 
 	/* 2 arrays of 17 32-bit words are 136 bytes */
-	ret = simple_read_from_buffer(buf, len, ppos, rwtm->last_sig, 136);
+	ret = simple_copy_to_iter(rwtm->last_sig, &iocb->ki_pos, 136, to);
 	rwtm->last_sig_done = 0;
 
 	return ret;
 }
 
-static ssize_t do_sign_write(struct file *file, const char __user *buf,
-			     size_t len, loff_t *ppos)
+static ssize_t do_sign_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct mox_rwtm *rwtm = file->private_data;
+	struct mox_rwtm *rwtm = iocb->ki_filp->private_data;
 	struct armada_37xx_rwtm_rx_msg *reply = &rwtm->reply;
 	struct armada_37xx_rwtm_tx_msg msg;
+	size_t len = iov_iter_count(from);
 	loff_t dummy = 0;
 	ssize_t ret;
 
@@ -385,7 +385,7 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf,
 	 *      stored by the rWTM firmware.
 	 */
 	memset(rwtm->buf, 0, 4);
-	ret = simple_write_to_buffer(rwtm->buf + 4, 64, &dummy, buf, len);
+	ret = simple_copy_from_iter(rwtm->buf + 4, &dummy, 64, from);
 	if (ret < 0)
 		goto unlock_mutex;
 	be32_to_cpu_array(rwtm->buf, rwtm->buf, 17);
@@ -426,8 +426,8 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf,
 static const struct file_operations do_sign_fops = {
 	.owner	= THIS_MODULE,
 	.open	= rwtm_debug_open,
-	.read	= do_sign_read,
-	.write	= do_sign_write,
+	.read_iter	= do_sign_read,
+	.write_iter	= do_sign_write,
 	.llseek	= no_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#135 lore raw

PATCH 129/437 firmware: tegra: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/firmware/tegra/bpmp-debugfs.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/firmware/tegra/bpmp-debugfs.c +13 -13
index 4221fed70ad4..6ef756a2d638 100644
@@ -363,21 +363,21 @@ static int bpmp_debug_show(struct seq_file *m, void *p)
 	return err;
 }
 
-static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
-		size_t count, loff_t *f_pos)
+static ssize_t bpmp_debug_store(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct inode *inode = file_inode(file);
+	struct inode *inode = file_inode(iocb->ki_filp);
 	struct tegra_bpmp *bpmp = inode->i_private;
+	size_t count = iov_iter_count(from);
 	char *databuf = NULL;
 	char fnamebuf[256];
 	const char *filename;
 	ssize_t err;
 
-	filename = get_filename(bpmp, file, fnamebuf, sizeof(fnamebuf));
+	filename = get_filename(bpmp, iocb->ki_filp, fnamebuf, sizeof(fnamebuf));
 	if (!filename)
 		return -ENOENT;
 
-	databuf = memdup_user(buf, count);
+	databuf = iterdup(from);
 	if (IS_ERR(databuf))
 		return PTR_ERR(databuf);
 
@@ -394,9 +394,9 @@ static int bpmp_debug_open(struct inode *inode, struct file *file)
 
 static const struct file_operations bpmp_debug_fops = {
 	.open		= bpmp_debug_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
-	.write		= bpmp_debug_store,
+	.write_iter	= bpmp_debug_store,
 	.release	= single_release,
 };
 
@@ -630,11 +630,11 @@ static int debugfs_open(struct inode *inode, struct file *file)
 	return single_open_size(file, debugfs_show, file, SZ_128K);
 }
 
-static ssize_t debugfs_store(struct file *file, const char __user *buf,
-		size_t count, loff_t *f_pos)
+static ssize_t debugfs_store(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct inode *inode = file_inode(file);
+	struct inode *inode = file_inode(iocb->ki_filp);
 	struct tegra_bpmp *bpmp = inode->i_private;
+	size_t count = iov_iter_count(from);
 	const size_t datasize = count;
 	const size_t namesize = SZ_256;
 	void *datavirt, *namevirt;
@@ -644,7 +644,7 @@ static ssize_t debugfs_store(struct file *file, const char __user *buf,
 	size_t len;
 	int err;
 
-	filename = get_filename(bpmp, file, fnamebuf, sizeof(fnamebuf));
+	filename = get_filename(bpmp, iocb->ki_filp, fnamebuf, sizeof(fnamebuf));
 	if (!filename)
 		return -ENOENT;
 
@@ -681,9 +681,9 @@ static ssize_t debugfs_store(struct file *file, const char __user *buf,
 
 static const struct file_operations debugfs_fops = {
 	.open		= debugfs_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
-	.write		= debugfs_store,
+	.write_iter	= debugfs_store,
 	.release	= single_release,
 };
 
Signature · 1 line
2.43.0
author maintainer
#136 lore raw

PATCH 130/437 drivers/i2c: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/i2c/i2c-dev.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/i2c/i2c-dev.c +12 -13
index 8b7e599f1674..4997e70499d5 100644
@@ -131,14 +131,13 @@ ATTRIBUTE_GROUPS(i2c);
  * needed by those system calls and by this SMBus interface.
  */
 
-static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
-		loff_t *offset)
+static ssize_t i2cdev_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	struct i2c_client *client = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	char *tmp;
 	int ret;
 
-	struct i2c_client *client = file->private_data;
-
 	if (count > 8192)
 		count = 8192;
 
@@ -146,31 +145,31 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
 	if (tmp == NULL)
 		return -ENOMEM;
 
-	pr_debug("i2c-%d reading %zu bytes.\n", iminor(file_inode(file)), count);
+	pr_debug("i2c-%d reading %zu bytes.\n", iminor(file_inode(iocb->ki_filp)), count);
 
 	ret = i2c_master_recv(client, tmp, count);
 	if (ret >= 0)
-		if (copy_to_user(buf, tmp, ret))
+		if (!copy_to_iter_full(tmp, ret, to))
 			ret = -EFAULT;
 	kfree(tmp);
 	return ret;
 }
 
-static ssize_t i2cdev_write(struct file *file, const char __user *buf,
-		size_t count, loff_t *offset)
+static ssize_t i2cdev_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	int ret;
 	char *tmp;
-	struct i2c_client *client = file->private_data;
+	struct i2c_client *client = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 
 	if (count > 8192)
 		count = 8192;
 
-	tmp = memdup_user(buf, count);
+	tmp = iterdup(from, count);
 	if (IS_ERR(tmp))
 		return PTR_ERR(tmp);
 
-	pr_debug("i2c-%d writing %zu bytes.\n", iminor(file_inode(file)), count);
+	pr_debug("i2c-%d writing %zu bytes.\n", iminor(file_inode(iocb->ki_filp)), count);
 
 	ret = i2c_master_send(client, tmp, count);
 	kfree(tmp);
@@ -626,8 +625,8 @@ static int i2cdev_release(struct inode *inode, struct file *file)
 static const struct file_operations i2cdev_fops = {
 	.owner		= THIS_MODULE,
 	.llseek		= no_llseek,
-	.read		= i2cdev_read,
-	.write		= i2cdev_write,
+	.read_iter	= i2cdev_read,
+	.write_iter	= i2cdev_write,
 	.unlocked_ioctl	= i2cdev_ioctl,
 	.compat_ioctl	= compat_i2cdev_ioctl,
 	.open		= i2cdev_open,
Signature · 1 line
2.43.0
author maintainer
#137 lore raw

PATCH 131/437 drivers/opp: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/opp/debugfs.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/opp/debugfs.c +4 -5
index 105de7c3274a..a755dacb2c61 100644
@@ -33,10 +33,9 @@ void opp_debug_remove_one(struct dev_pm_opp *opp)
 	debugfs_remove_recursive(opp->dentry);
 }
 
-static ssize_t bw_name_read(struct file *fp, char __user *userbuf,
-			    size_t count, loff_t *ppos)
+static ssize_t bw_name_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct icc_path *path = fp->private_data;
+	struct icc_path *path = iocb->ki_filp->private_data;
 	const char *name = icc_get_name(path);
 	char buf[64];
 	int i = 0;
@@ -44,12 +43,12 @@ static ssize_t bw_name_read(struct file *fp, char __user *userbuf,
 	if (name)
 		i = scnprintf(buf, sizeof(buf), "%.62s\n", name);
 
-	return simple_read_from_buffer(userbuf, count, ppos, buf, i);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, i, to);
 }
 
 static const struct file_operations bw_name_fops = {
 	.open = simple_open,
-	.read = bw_name_read,
+	.read_iter = bw_name_read,
 	.llseek = default_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#138 lore raw

PATCH 132/437 drivers/base: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/base/power/wakeup.c          |   2 +-
 drivers/base/regmap/regmap-debugfs.c | 119 ++++++++++++---------------
 2 files changed, 52 insertions(+), 69 deletions(-)
drivers/base/power/wakeup.c +1 -1
index a917219feea6..b3ae10683a95 100644
@@ -1168,7 +1168,7 @@ static int wakeup_sources_stats_open(struct inode *inode, struct file *file)
 static const struct file_operations wakeup_sources_stats_fops = {
 	.owner = THIS_MODULE,
 	.open = wakeup_sources_stats_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = seq_release_private,
 };
drivers/base/regmap/regmap-debugfs.c +51 -68

307 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#139 lore raw

PATCH 133/437 drivers/bus: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/bus/mhi/host/debugfs.c | 38 +++++++++++++++++-----------------
 drivers/bus/moxtet.c           | 30 +++++++++++++--------------
 2 files changed, 33 insertions(+), 35 deletions(-)
drivers/bus/mhi/host/debugfs.c +19 -19
index cfec7811dfbb..14d7a1132fca 100644
@@ -245,17 +245,17 @@ static int mhi_debugfs_device_wake_show(struct seq_file *m, void *d)
 	return 0;
 }
 
-static ssize_t mhi_debugfs_device_wake_write(struct file *file,
-					     const char __user *ubuf,
-					     size_t count, loff_t *ppos)
+static ssize_t mhi_debugfs_device_wake_write(struct kiocb *iocb,
+					     struct iov_iter *from)
 {
-	struct seq_file	*m = file->private_data;
+	struct seq_file	*m = iocb->ki_filp->private_data;
 	struct mhi_controller *mhi_cntrl = m->private;
 	struct mhi_device *mhi_dev = mhi_cntrl->mhi_dev;
+	size_t count = iov_iter_count(from);
 	char buf[16];
 	int ret = -EINVAL;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (!strncmp(buf, "get", 3)) {
@@ -277,15 +277,15 @@ static int mhi_debugfs_timeout_ms_show(struct seq_file *m, void *d)
 	return 0;
 }
 
-static ssize_t mhi_debugfs_timeout_ms_write(struct file *file,
-					    const char __user *ubuf,
-					    size_t count, loff_t *ppos)
+static ssize_t mhi_debugfs_timeout_ms_write(struct kiocb *iocb,
+					    struct iov_iter *from)
 {
-	struct seq_file	*m = file->private_data;
+	struct seq_file	*m = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct mhi_controller *mhi_cntrl = m->private;
 	u32 timeout_ms;
 
-	if (kstrtou32_from_user(ubuf, count, 0, &timeout_ms))
+	if (kstrtou32_from_iter(from, count, 0, &timeout_ms))
 		return -EINVAL;
 
 	mhi_cntrl->timeout_ms = timeout_ms;
@@ -331,45 +331,45 @@ static int mhi_debugfs_timeout_ms_open(struct inode *inode, struct file *fp)
 static const struct file_operations debugfs_states_fops = {
 	.open = mhi_debugfs_states_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_events_fops = {
 	.open = mhi_debugfs_events_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_channels_fops = {
 	.open = mhi_debugfs_channels_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_devices_fops = {
 	.open = mhi_debugfs_devices_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_regdump_fops = {
 	.open = mhi_debugfs_regdump_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_device_wake_fops = {
 	.open = mhi_debugfs_device_wake_open,
-	.write = mhi_debugfs_device_wake_write,
+	.write_iter = mhi_debugfs_device_wake_write,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static const struct file_operations debugfs_timeout_ms_fops = {
 	.open = mhi_debugfs_timeout_ms_open,
-	.write = mhi_debugfs_timeout_ms_write,
+	.write_iter = mhi_debugfs_timeout_ms_write,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 };
 
 static struct dentry *mhi_debugfs_root;
drivers/bus/moxtet.c +14 -16
index 641c1a6adc8a..a6635cfc8490 100644
@@ -15,6 +15,7 @@
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
 #include <linux/spi/spi.h>
+#include <linux/uio.h>
 
 /*
  * @name:	module name for sysfs
@@ -460,10 +461,9 @@ static int moxtet_debug_open(struct inode *inode, struct file *file)
 	return nonseekable_open(inode, file);
 }
 
-static ssize_t input_read(struct file *file, char __user *buf, size_t len,
-			  loff_t *ppos)
+static ssize_t input_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct moxtet *moxtet = file->private_data;
+	struct moxtet *moxtet = iocb->ki_filp->private_data;
 	u8 bin[TURRIS_MOX_MAX_MODULES];
 	u8 hex[sizeof(bin) * 2 + 1];
 	int ret, n;
@@ -477,20 +477,19 @@ static ssize_t input_read(struct file *file, char __user *buf, size_t len,
 
 	hex[2*n] = '\n';
 
-	return simple_read_from_buffer(buf, len, ppos, hex, 2*n + 1);
+	return simple_copy_to_iter(hex, &iocb->ki_pos, 2*n + 1, to);
 }
 
 static const struct file_operations input_fops = {
 	.owner	= THIS_MODULE,
 	.open	= moxtet_debug_open,
-	.read	= input_read,
+	.read_iter	= input_read,
 	.llseek	= no_llseek,
 };
 
-static ssize_t output_read(struct file *file, char __user *buf, size_t len,
-			   loff_t *ppos)
+static ssize_t output_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct moxtet *moxtet = file->private_data;
+	struct moxtet *moxtet = iocb->ki_filp->private_data;
 	u8 hex[TURRIS_MOX_MAX_MODULES * 2 + 1];
 	u8 *p = hex;
 	int i;
@@ -504,23 +503,22 @@ static ssize_t output_read(struct file *file, char __user *buf, size_t len,
 
 	*p++ = '\n';
 
-	return simple_read_from_buffer(buf, len, ppos, hex, p - hex);
+	return simple_copy_to_iter(hex, &iocb->ki_pos, p - hex, to);
 }
 
-static ssize_t output_write(struct file *file, const char __user *buf,
-			    size_t len, loff_t *ppos)
+static ssize_t output_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct moxtet *moxtet = file->private_data;
+	struct moxtet *moxtet = iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(from);
 	u8 bin[TURRIS_MOX_MAX_MODULES];
 	u8 hex[sizeof(bin) * 2 + 1];
 	ssize_t res;
-	loff_t dummy = 0;
 	int err, i;
 
 	if (len > 2 * moxtet->count + 1 || len < 2 * moxtet->count)
 		return -EINVAL;
 
-	res = simple_write_to_buffer(hex, sizeof(hex), &dummy, buf, len);
+	res = simple_copy_from_iter(hex, &iocb->ki_pos, sizeof(hex), from);
 	if (res < 0)
 		return res;
 
@@ -547,8 +545,8 @@ static ssize_t output_write(struct file *file, const char __user *buf,
 static const struct file_operations output_fops = {
 	.owner	= THIS_MODULE,
 	.open	= moxtet_debug_open,
-	.read	= output_read,
-	.write	= output_write,
+	.read_iter	= output_read,
+	.write_iter	= output_write,
 	.llseek	= no_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#140 lore raw

PATCH 134/437 drivers/regulator: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/regulator/core.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/regulator/core.c +5 -7
index dabac9772741..92fad0d0fb9c 100644
@@ -1810,11 +1810,10 @@ static void unset_regulator_supplies(struct regulator_dev *rdev)
 }
 
 #ifdef CONFIG_DEBUG_FS
-static ssize_t constraint_flags_read_file(struct file *file,
-					  char __user *user_buf,
-					  size_t count, loff_t *ppos)
+static ssize_t constraint_flags_read_file(struct kiocb *iocb,
+					  struct iov_iter *to)
 {
-	const struct regulator *regulator = file->private_data;
+	const struct regulator *regulator = iocb->ki_filp->private_data;
 	const struct regulation_constraints *c = regulator->rdev->constraints;
 	char *buf;
 	ssize_t ret;
@@ -1842,9 +1841,8 @@ static ssize_t constraint_flags_read_file(struct file *file,
 			c->pull_down,
 			c->over_current_protection);
 
-	ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+	ret = simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);
 	kfree(buf);
-
 	return ret;
 }
 
@@ -1853,7 +1851,7 @@ static ssize_t constraint_flags_read_file(struct file *file,
 static const struct file_operations constraint_flags_fops = {
 #ifdef CONFIG_DEBUG_FS
 	.open = simple_open,
-	.read = constraint_flags_read_file,
+	.read_iter = constraint_flags_read_file,
 	.llseek = default_llseek,
 #endif
 };
Signature · 1 line
2.43.0
author maintainer
#141 lore raw

PATCH 135/437 fs/notify: convert to read/write iterators

In reply to Jens Axboe
---
 fs/notify/fanotify/fanotify_user.c | 6 ++++--
 fs/notify/inotify/inotify_user.c   | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)
fs/notify/fanotify/fanotify_user.c +4 -2
index fbdc63cc10d9..52b97f6c2285 100644
@@ -868,6 +868,7 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
 		ret = buf - start;
 	return ret;
 }
+FOPS_READ_ITER_HELPER(fanotify_read);
 
 static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
 {
@@ -900,6 +901,7 @@ static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t
 
 	return count;
 }
+FOPS_WRITE_ITER_HELPER(fanotify_write);
 
 static int fanotify_release(struct inode *ignored, struct file *file)
 {
@@ -984,8 +986,8 @@ static long fanotify_ioctl(struct file *file, unsigned int cmd, unsigned long ar
 static const struct file_operations fanotify_fops = {
 	.show_fdinfo	= fanotify_show_fdinfo,
 	.poll		= fanotify_poll,
-	.read		= fanotify_read,
-	.write		= fanotify_write,
+	.read_iter	= fanotify_read_iter,
+	.write_iter	= fanotify_write_iter,
 	.fasync		= NULL,
 	.release	= fanotify_release,
 	.unlocked_ioctl	= fanotify_ioctl,
fs/notify/inotify/inotify_user.c +2 -1
index 85d8fdd55329..bdc424a79e3c 100644
@@ -297,6 +297,7 @@ static ssize_t inotify_read(struct file *file, char __user *buf,
 		ret = buf - start;
 	return ret;
 }
+FOPS_READ_ITER_HELPER(inotify_read);
 
 static int inotify_release(struct inode *ignored, struct file *file)
 {
@@ -357,7 +358,7 @@ static long inotify_ioctl(struct file *file, unsigned int cmd,
 static const struct file_operations inotify_fops = {
 	.show_fdinfo	= inotify_show_fdinfo,
 	.poll		= inotify_poll,
-	.read		= inotify_read,
+	.read_iter	= inotify_read_iter,
 	.fasync		= fsnotify_fasync,
 	.release	= inotify_release,
 	.unlocked_ioctl	= inotify_ioctl,
Signature · 1 line
2.43.0
author maintainer
#142 lore raw

PATCH 136/437 drm: switch drm_read() to be iterator based

In reply to Jens Axboe

First step of converting the GPU drivers to using read/write iterators, convert the common file read helper to be iter based.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  2 +-
 drivers/gpu/drm/drm_file.c              | 22 ++++++++++------------
 drivers/gpu/drm/gma500/psb_drv.c        |  2 +-
 drivers/gpu/drm/i915/i915_driver.c      |  2 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c   |  2 +-
 drivers/gpu/drm/radeon/radeon_drv.c     |  2 +-
 drivers/gpu/drm/tegra/drm.c             |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c     |  2 +-
 drivers/gpu/drm/xe/xe_device.c          |  2 +-
 include/drm/drm_accel.h                 |  2 +-
 include/drm/drm_file.h                  |  3 +--
 include/drm/drm_gem.h                   |  2 +-
 include/drm/drm_gem_dma_helper.h        |  2 +-
 13 files changed, 22 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
index 80b9642f2bc4..d2369e852702 100644
@@ -2863,7 +2863,7 @@ static const struct file_operations amdgpu_driver_kms_fops = {
 	.unlocked_ioctl = amdgpu_drm_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = amdgpu_kms_compat_ioctl,
 #endif
drivers/gpu/drm/drm_file.c +10 -12
index 638ffa4444f5..c5965b5a1afc 100644
@@ -110,7 +110,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev)
  *             .unlocked_ioctl = drm_ioctl,
  *             .compat_ioctl = drm_compat_ioctl, // NULL if CONFIG_COMPAT=n
  *             .poll = drm_poll,
- *             .read = drm_read,
+ *             .read_iter = drm_read,
  *             .llseek = no_llseek,
  *             .mmap = drm_gem_mmap,
  *     };
@@ -515,18 +515,16 @@ EXPORT_SYMBOL(drm_release_noglobal);
 
 /**
  * drm_read - read method for DRM file
- * @filp: file pointer
- * @buffer: userspace destination pointer for the read
- * @count: count in bytes to read
- * @offset: offset to read
+ * @iocb: metadata for IO
+ * @to: userspace destination pointer for the read
  *
  * This function must be used by drivers as their &file_operations.read
  * method if they use DRM events for asynchronous signalling to userspace.
  * Since events are used by the KMS API for vblank and page flip completion this
  * means all modern display drivers must use it.
  *
- * @offset is ignored, DRM events are read like a pipe. Polling support is
- * provided by drm_poll().
+ * offset in @iocb is ignored, DRM events are read like a pipe. Polling support
+ * is provided by drm_poll().
  *
  * This function will only ever read a full event. Therefore userspace must
  * supply a big enough buffer to fit any event to ensure forward progress. Since
@@ -538,11 +536,11 @@ EXPORT_SYMBOL(drm_release_noglobal);
  * Number of bytes read (always aligned to full events, and can be 0) or a
  * negative error code on failure.
  */
-ssize_t drm_read(struct file *filp, char __user *buffer,
-		 size_t count, loff_t *offset)
+ssize_t drm_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct drm_file *file_priv = filp->private_data;
+	struct drm_file *file_priv = iocb->ki_filp->private_data;
 	struct drm_device *dev = file_priv->minor->dev;
+	size_t count = iov_iter_count(to);
 	ssize_t ret;
 
 	ret = mutex_lock_interruptible(&file_priv->event_read_lock);
@@ -565,7 +563,7 @@ ssize_t drm_read(struct file *filp, char __user *buffer,
 			if (ret)
 				break;
 
-			if (filp->f_flags & O_NONBLOCK) {
+			if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 				ret = -EAGAIN;
 				break;
 			}
@@ -591,7 +589,7 @@ ssize_t drm_read(struct file *filp, char __user *buffer,
 				break;
 			}
 
-			if (copy_to_user(buffer + ret, e->event, length)) {
+			if (!copy_to_iter_full(e->event, length, to)) {
 				if (ret == 0)
 					ret = -EFAULT;
 				goto put_back_event;
drivers/gpu/drm/gma500/psb_drv.c +1 -1
index 8b64f61ffaf9..7489d64bea98 100644
@@ -497,7 +497,7 @@ static const struct file_operations psb_gem_fops = {
 	.compat_ioctl = drm_compat_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 };
 
 static const struct drm_driver driver = {
drivers/gpu/drm/i915/i915_driver.c +1 -1
index 4b9233c07a22..a8328ee685e8 100644
@@ -1729,7 +1729,7 @@ static const struct file_operations i915_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = i915_gem_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 	.compat_ioctl = i915_ioc32_compat_ioctl,
 	.llseek = noop_llseek,
 #ifdef CONFIG_PROC_FS
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -1
index a947e1d5f309..6b626d62781c 100644
@@ -1269,7 +1269,7 @@ nouveau_driver_fops = {
 	.unlocked_ioctl = nouveau_drm_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 #if defined(CONFIG_COMPAT)
 	.compat_ioctl = nouveau_compat_ioctl,
 #endif
drivers/gpu/drm/radeon/radeon_drv.c +1 -1
index 7bf08164140e..7011ef3475a7 100644
@@ -516,7 +516,7 @@ static const struct file_operations radeon_driver_kms_fops = {
 	.unlocked_ioctl = radeon_drm_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = radeon_kms_compat_ioctl,
 #endif
drivers/gpu/drm/tegra/drm.c +1 -1
index 03d1c76aec2d..f455aa8339a3 100644
@@ -798,7 +798,7 @@ static const struct file_operations tegra_drm_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = tegra_drm_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 	.compat_ioctl = drm_compat_ioctl,
 	.llseek = noop_llseek,
 };
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
index c7d90f96d16a..fb68d49cff51 100644
@@ -1605,7 +1605,7 @@ static const struct file_operations vmwgfx_driver_fops = {
 	.unlocked_ioctl = vmw_unlocked_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 #if defined(CONFIG_COMPAT)
 	.compat_ioctl = vmw_compat_ioctl,
 #endif
drivers/gpu/drm/xe/xe_device.c +1 -1
index d32ff3857e65..98ae007febe9 100644
@@ -143,7 +143,7 @@ static const struct file_operations xe_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.read = drm_read,
+	.read_iter = drm_read,
 	.compat_ioctl = drm_compat_ioctl,
 	.llseek = noop_llseek,
 #ifdef CONFIG_PROC_FS
include/drm/drm_accel.h +1 -1
index f4d3784b1dce..c757e0b1db46 100644
@@ -26,7 +26,7 @@
 	.unlocked_ioctl	= drm_ioctl,\
 	.compat_ioctl	= drm_compat_ioctl,\
 	.poll		= drm_poll,\
-	.read		= drm_read,\
+	.read_iter	= drm_read,\
 	.llseek		= noop_llseek, \
 	.mmap		= drm_gem_mmap
 
include/drm/drm_file.h +1 -2
index ab230d3af138..19917ff0090c 100644
@@ -436,8 +436,7 @@ void drm_file_update_pid(struct drm_file *);
 
 int drm_open(struct inode *inode, struct file *filp);
 int drm_open_helper(struct file *filp, struct drm_minor *minor);
-ssize_t drm_read(struct file *filp, char __user *buffer,
-		 size_t count, loff_t *offset);
+ssize_t drm_read(struct kiocb *iocb, struct iov_iter *to);
 int drm_release(struct inode *inode, struct file *filp);
 int drm_release_noglobal(struct inode *inode, struct file *filp);
 __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
include/drm/drm_gem.h +1 -1
index 2ebec3984cd4..29fe86ce8266 100644
@@ -445,7 +445,7 @@ struct drm_gem_object {
 	.unlocked_ioctl	= drm_ioctl,\
 	.compat_ioctl	= drm_compat_ioctl,\
 	.poll		= drm_poll,\
-	.read		= drm_read,\
+	.read_iter	= drm_read,\
 	.llseek		= noop_llseek,\
 	.mmap		= drm_gem_mmap
 
include/drm/drm_gem_dma_helper.h +1 -1
index a827bde494f6..907acd2b89fa 100644
@@ -264,7 +264,7 @@ unsigned long drm_gem_dma_get_unmapped_area(struct file *filp,
 		.unlocked_ioctl	= drm_ioctl,\
 		.compat_ioctl	= drm_compat_ioctl,\
 		.poll		= drm_poll,\
-		.read		= drm_read,\
+		.read_iter	= drm_read,\
 		.llseek		= noop_llseek,\
 		.mmap		= drm_gem_mmap,\
 		DRM_GEM_DMA_UNMAPPED_AREA_FOPS \
Signature · 1 line
2.43.0
author maintainer
#143 lore raw

PATCH 137/437 drm: convert debugfs helpers to be read/write iterator based

In reply to Jens Axboe
---
 drivers/gpu/drm/drm_debugfs.c     | 28 ++++++++++++++--------------
 drivers/gpu/drm/drm_debugfs_crc.c | 26 +++++++++++++-------------
 2 files changed, 27 insertions(+), 27 deletions(-)
drivers/gpu/drm/drm_debugfs.c +14 -14
index 08fcefd804bc..e7d7cbd930ca 100644
@@ -171,7 +171,7 @@ static int drm_debugfs_entry_open(struct inode *inode, struct file *file)
 static const struct file_operations drm_debugfs_entry_fops = {
 	.owner = THIS_MODULE,
 	.open = drm_debugfs_entry_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -179,7 +179,7 @@ static const struct file_operations drm_debugfs_entry_fops = {
 static const struct file_operations drm_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = drm_debugfs_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -403,17 +403,17 @@ static int connector_open(struct inode *inode, struct file *file)
 	return single_open(file, connector_show, dev);
 }
 
-static ssize_t connector_write(struct file *file, const char __user *ubuf,
-			       size_t len, loff_t *offp)
+static ssize_t connector_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_connector *connector = m->private;
+	size_t len = iov_iter_count(from);
 	char buf[12];
 
 	if (len > sizeof(buf) - 1)
 		return -EINVAL;
 
-	if (copy_from_user(buf, ubuf, len))
+	if (!copy_from_iter_full(buf, len, from))
 		return -EFAULT;
 
 	buf[len] = '\0';
@@ -444,15 +444,15 @@ static int edid_open(struct inode *inode, struct file *file)
 	return single_open(file, edid_show, dev);
 }
 
-static ssize_t edid_write(struct file *file, const char __user *ubuf,
-			  size_t len, loff_t *offp)
+static ssize_t edid_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_connector *connector = m->private;
+	size_t len = iov_iter_count(from);
 	char *buf;
 	int ret;
 
-	buf = memdup_user(ubuf, len);
+	buf = iterdup(from, len);
 	if (IS_ERR(buf))
 		return PTR_ERR(buf);
 
@@ -504,20 +504,20 @@ DEFINE_SHOW_ATTRIBUTE(output_bpc);
 static const struct file_operations drm_edid_fops = {
 	.owner = THIS_MODULE,
 	.open = edid_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = edid_write
+	.write_iter = edid_write
 };
 
 
 static const struct file_operations drm_connector_fops = {
 	.owner = THIS_MODULE,
 	.open = connector_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = connector_write
+	.write_iter = connector_write
 };
 
 void drm_debugfs_connector_add(struct drm_connector *connector)
drivers/gpu/drm/drm_debugfs_crc.c +13 -13
index bbc3bc4ba844..85741f3eafee 100644
@@ -117,12 +117,12 @@ static int crc_control_open(struct inode *inode, struct file *file)
 	return single_open(file, crc_control_show, crtc);
 }
 
-static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
-				 size_t len, loff_t *offp)
+static ssize_t crc_control_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_crtc *crtc = m->private;
 	struct drm_crtc_crc *crc = &crtc->crc;
+	size_t len = iov_iter_count(from);
 	char *source;
 	size_t values_cnt;
 	int ret;
@@ -136,7 +136,7 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
 		return -E2BIG;
 	}
 
-	source = memdup_user_nul(ubuf, len);
+	source = iterdup_nul(from, len);
 	if (IS_ERR(source))
 		return PTR_ERR(source);
 
@@ -162,17 +162,17 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
 
 	spin_unlock_irq(&crc->lock);
 
-	*offp += len;
+	iocb->ki_pos += len;
 	return len;
 }
 
 static const struct file_operations drm_crtc_crc_control_fops = {
 	.owner = THIS_MODULE,
 	.open = crc_control_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = crc_control_write
+	.write_iter = crc_control_write,
 };
 
 static int crtc_crc_data_count(struct drm_crtc_crc *crc)
@@ -281,11 +281,11 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
 #define LINE_LEN(values_cnt)	(10 + 11 * values_cnt + 1 + 1)
 #define MAX_LINE_LEN		(LINE_LEN(DRM_MAX_CRC_NR))
 
-static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf,
-			     size_t count, loff_t *pos)
+static ssize_t crtc_crc_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct drm_crtc *crtc = filep->f_inode->i_private;
+	struct drm_crtc *crtc = iocb->ki_filp->f_inode->i_private;
 	struct drm_crtc_crc *crc = &crtc->crc;
+	size_t count = iov_iter_count(to);
 	struct drm_crtc_crc_entry *entry;
 	char buf[MAX_LINE_LEN];
 	int ret, i;
@@ -299,7 +299,7 @@ static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf,
 
 	/* Nothing to read? */
 	while (crtc_crc_data_count(crc) == 0) {
-		if (filep->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			spin_unlock_irq(&crc->lock);
 			return -EAGAIN;
 		}
@@ -335,7 +335,7 @@ static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf,
 		sprintf(buf + 10 + i * 11, " 0x%08x", entry->crcs[i]);
 	sprintf(buf + 10 + crc->values_cnt * 11, "\n");
 
-	if (copy_to_user(user_buf, buf, LINE_LEN(crc->values_cnt)))
+	if (!copy_to_iter_full(buf, LINE_LEN(crc->values_cnt), to))
 		return -EFAULT;
 
 	return LINE_LEN(crc->values_cnt);
@@ -360,7 +360,7 @@ static __poll_t crtc_crc_poll(struct file *file, poll_table *wait)
 static const struct file_operations drm_crtc_crc_data_fops = {
 	.owner = THIS_MODULE,
 	.open = crtc_crc_open,
-	.read = crtc_crc_read,
+	.read_iter = crtc_crc_read,
 	.poll = crtc_crc_poll,
 	.release = crtc_crc_release,
 };
Signature · 1 line
2.43.0
author maintainer
#144 lore raw

PATCH 138/437 drm/i915: convert to read/write iterators

In reply to Jens Axboe
---
 .../drm/i915/display/intel_display_debugfs.c  | 114 +++++++++---------
 .../display/intel_display_debugfs_params.c    |  36 +++---
 drivers/gpu/drm/i915/display/intel_hotplug.c  |  28 ++---
 drivers/gpu/drm/i915/display/intel_wm.c       |  42 +++----
 drivers/gpu/drm/i915/display/skl_watermark.c  |  14 +--
 drivers/gpu/drm/i915/gt/intel_gt_debugfs.c    |   2 +-
 drivers/gpu/drm/i915/gt/intel_gt_debugfs.h    |   2 +-
 .../drm/i915/gt/uc/intel_guc_log_debugfs.c    |  13 +-
 drivers/gpu/drm/i915/i915_debugfs_params.c    |  43 ++++---
 drivers/gpu/drm/i915/i915_gpu_error.c         |  28 ++---
 drivers/gpu/drm/i915/i915_perf.c              |   3 +-
 11 files changed, 156 insertions(+), 169 deletions(-)
drivers/gpu/drm/i915/display/intel_display_debugfs.c +55 -59
index b99c024b0934..b8d03be584dd 100644
@@ -513,26 +513,24 @@ static int crtc_updates_open(struct inode *inode, struct file *file)
 	return single_open(file, crtc_updates_show, inode->i_private);
 }
 
-static ssize_t crtc_updates_write(struct file *file,
-				  const char __user *ubuf,
-				  size_t len, loff_t *offp)
+static ssize_t crtc_updates_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct intel_crtc *crtc = m->private;
 
 	/* May race with an update. Meh. */
 	memset(&crtc->debug.vbl, 0, sizeof(crtc->debug.vbl));
 
-	return len;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations crtc_updates_fops = {
 	.owner = THIS_MODULE,
 	.open = crtc_updates_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = crtc_updates_write
+	.write_iter = crtc_updates_write
 };
 
 static void crtc_updates_add(struct intel_crtc *crtc)
@@ -801,24 +799,24 @@ static int i915_dp_mst_info(struct seq_file *m, void *unused)
 	return 0;
 }
 
-static ssize_t i915_displayport_test_active_write(struct file *file,
-						  const char __user *ubuf,
-						  size_t len, loff_t *offp)
+static ssize_t i915_displayport_test_active_write(struct kiocb *iocb,
+						  struct iov_iter *from)
 {
 	char *input_buffer;
 	int status = 0;
 	struct drm_device *dev;
 	struct drm_connector *connector;
 	struct drm_connector_list_iter conn_iter;
+	size_t len = iov_iter_count(from);
 	struct intel_dp *intel_dp;
 	int val = 0;
 
-	dev = ((struct seq_file *)file->private_data)->private;
+	dev = ((struct seq_file *)iocb->ki_filp->private_data)->private;
 
 	if (len == 0)
 		return 0;
 
-	input_buffer = memdup_user_nul(ubuf, len);
+	input_buffer = iterdup_nul(from, len);
 	if (IS_ERR(input_buffer))
 		return PTR_ERR(input_buffer);
 
@@ -856,7 +854,7 @@ static ssize_t i915_displayport_test_active_write(struct file *file,
 	if (status < 0)
 		return status;
 
-	*offp += len;
+	iocb->ki_pos += len;
 	return len;
 }
 
@@ -903,10 +901,10 @@ static int i915_displayport_test_active_open(struct inode *inode,
 static const struct file_operations i915_displayport_test_active_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_displayport_test_active_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = i915_displayport_test_active_write
+	.write_iter = i915_displayport_test_active_write,
 };
 
 static int i915_displayport_test_data_show(struct seq_file *m, void *data)
@@ -994,16 +992,15 @@ static int i915_displayport_test_type_show(struct seq_file *m, void *data)
 DEFINE_SHOW_ATTRIBUTE(i915_displayport_test_type);
 
 static ssize_t
-i915_fifo_underrun_reset_write(struct file *filp,
-			       const char __user *ubuf,
-			       size_t cnt, loff_t *ppos)
+i915_fifo_underrun_reset_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct drm_i915_private *dev_priv = filp->private_data;
+	struct drm_i915_private *dev_priv = iocb->ki_filp->private_data;
+	size_t cnt = iov_iter_count(from);
 	struct intel_crtc *crtc;
 	int ret;
 	bool reset;
 
-	ret = kstrtobool_from_user(ubuf, cnt, &reset);
+	ret = kstrtobool_from_iter(from, cnt, &reset);
 	if (ret)
 		return ret;
 
@@ -1048,7 +1045,7 @@ i915_fifo_underrun_reset_write(struct file *filp,
 static const struct file_operations i915_fifo_underrun_reset_ops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.write = i915_fifo_underrun_reset_write,
+	.write_iter = i915_fifo_underrun_reset_write,
 	.llseek = default_llseek,
 };
 
@@ -1259,15 +1256,15 @@ static int i915_dsc_fec_support_show(struct seq_file *m, void *data)
 	return ret;
 }
 
-static ssize_t i915_dsc_fec_support_write(struct file *file,
-					  const char __user *ubuf,
-					  size_t len, loff_t *offp)
+static ssize_t i915_dsc_fec_support_write(struct kiocb *iocb,
+					  struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct intel_connector *connector = m->private;
 	struct drm_i915_private *i915 = to_i915(connector->base.dev);
 	struct intel_encoder *encoder = intel_attached_encoder(connector);
 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
+	size_t len = iov_iter_count(from);
 	bool dsc_enable = false;
 	int ret;
 
@@ -1277,7 +1274,7 @@ static ssize_t i915_dsc_fec_support_write(struct file *file,
 	drm_dbg(&i915->drm,
 		"Copied %zu bytes from user to force DSC\n", len);
 
-	ret = kstrtobool_from_user(ubuf, len, &dsc_enable);
+	ret = kstrtobool_from_iter(from, len, &dsc_enable);
 	if (ret < 0)
 		return ret;
 
@@ -1285,7 +1282,7 @@ static ssize_t i915_dsc_fec_support_write(struct file *file,
 		(dsc_enable) ? "true" : "false");
 	intel_dp->force_dsc_en = dsc_enable;
 
-	*offp += len;
+	iocb->ki_pos += len;
 	return len;
 }
 
@@ -1299,10 +1296,10 @@ static int i915_dsc_fec_support_open(struct inode *inode,
 static const struct file_operations i915_dsc_fec_support_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_dsc_fec_support_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = i915_dsc_fec_support_write
+	.write_iter = i915_dsc_fec_support_write
 };
 
 static int i915_dsc_bpc_show(struct seq_file *m, void *data)
@@ -1335,23 +1332,22 @@ out:	drm_modeset_unlock(&i915->drm.mode_config.connection_mutex);
 	return ret;
 }
 
-static ssize_t i915_dsc_bpc_write(struct file *file,
-				  const char __user *ubuf,
-				  size_t len, loff_t *offp)
+static ssize_t i915_dsc_bpc_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct intel_connector *connector = m->private;
 	struct intel_encoder *encoder = intel_attached_encoder(connector);
 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
+	size_t len = iov_iter_count(from);
 	int dsc_bpc = 0;
 	int ret;
 
-	ret = kstrtoint_from_user(ubuf, len, 0, &dsc_bpc);
+	ret = kstrtoint_from_iter(from, len, 0, &dsc_bpc);
 	if (ret < 0)
 		return ret;
 
 	intel_dp->force_dsc_bpc = dsc_bpc;
-	*offp += len;
+	iocb->ki_pos += len;
 
 	return len;
 }
@@ -1365,10 +1361,10 @@ static int i915_dsc_bpc_open(struct inode *inode,
 static const struct file_operations i915_dsc_bpc_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_dsc_bpc_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = i915_dsc_bpc_write
+	.write_iter = i915_dsc_bpc_write
 };
 
 static int i915_dsc_output_format_show(struct seq_file *m, void *data)
@@ -1416,33 +1412,33 @@ static int i915_bigjoiner_enable_show(struct seq_file *m, void *data)
 	return 0;
 }
 
-static ssize_t i915_dsc_output_format_write(struct file *file,
-					    const char __user *ubuf,
-					    size_t len, loff_t *offp)
+static ssize_t i915_dsc_output_format_write(struct kiocb *iocb,
+					    struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct intel_connector *connector = m->private;
 	struct intel_encoder *encoder = intel_attached_encoder(connector);
 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
+	size_t len = iov_iter_count(from);
 	int dsc_output_format = 0;
 	int ret;
 
-	ret = kstrtoint_from_user(ubuf, len, 0, &dsc_output_format);
+	ret = kstrtoint_from_iter(from, len, 0, &dsc_output_format);
 	if (ret < 0)
 		return ret;
 
 	intel_dp->force_dsc_output_format = dsc_output_format;
-	*offp += len;
+	iocb->ki_pos += len;
 
 	return len;
 }
 
-static ssize_t i915_bigjoiner_enable_write(struct file *file,
-					   const char __user *ubuf,
-					   size_t len, loff_t *offp)
+static ssize_t i915_bigjoiner_enable_write_iter(struct kiocb *iocb,
+						struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct intel_connector *connector = m->private;
+	size_t len = iov_iter_count(from);
 	struct drm_crtc *crtc;
 	bool bigjoiner_en = 0;
 	int ret;
@@ -1451,12 +1447,12 @@ static ssize_t i915_bigjoiner_enable_write(struct file *file,
 	if (connector->base.status != connector_status_connected || !crtc)
 		return -ENODEV;
 
-	ret = kstrtobool_from_user(ubuf, len, &bigjoiner_en);
+	ret = kstrtobool_from_iter(from, len, &bigjoiner_en);
 	if (ret < 0)
 		return ret;
 
 	connector->force_bigjoiner_enable = bigjoiner_en;
-	*offp += len;
+	iocb->ki_pos += len;
 
 	return len;
 }
@@ -1470,10 +1466,10 @@ static int i915_dsc_output_format_open(struct inode *inode,
 static const struct file_operations i915_dsc_output_format_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_dsc_output_format_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = i915_dsc_output_format_write
+	.write_iter = i915_dsc_output_format_write
 };
 
 static int i915_dsc_fractional_bpp_show(struct seq_file *m, void *data)
@@ -1508,16 +1504,16 @@ static int i915_dsc_fractional_bpp_show(struct seq_file *m, void *data)
 	return ret;
 }
 
-static ssize_t i915_dsc_fractional_bpp_write(struct file *file,
-					     const char __user *ubuf,
-					     size_t len, loff_t *offp)
+static ssize_t i915_dsc_fractional_bpp_write(struct kiocb *iocb,
+					     struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct intel_connector *connector = m->private;
 	struct intel_encoder *encoder = intel_attached_encoder(connector);
 	struct drm_i915_private *i915 = to_i915(connector->base.dev);
 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
 	bool dsc_fractional_bpp_enable = false;
+	size_t len = iov_iter_count(from);
 	int ret;
 
 	if (len == 0)
@@ -1526,7 +1522,7 @@ static ssize_t i915_dsc_fractional_bpp_write(struct file *file,
 	drm_dbg(&i915->drm,
 		"Copied %zu bytes from user to force fractional bpp for DSC\n", len);
 
-	ret = kstrtobool_from_user(ubuf, len, &dsc_fractional_bpp_enable);
+	ret = kstrtobool_from_iter(from, len, &dsc_fractional_bpp_enable);
 	if (ret < 0)
 		return ret;
 
@@ -1534,7 +1530,7 @@ static ssize_t i915_dsc_fractional_bpp_write(struct file *file,
 		(dsc_fractional_bpp_enable) ? "true" : "false");
 	intel_dp->force_dsc_fractional_bpp_en = dsc_fractional_bpp_enable;
 
-	*offp += len;
+	iocb->ki_pos += len;
 
 	return len;
 }
@@ -1548,10 +1544,10 @@ static int i915_dsc_fractional_bpp_open(struct inode *inode,
 static const struct file_operations i915_dsc_fractional_bpp_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_dsc_fractional_bpp_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = i915_dsc_fractional_bpp_write
+	.write_iter = i915_dsc_fractional_bpp_write
 };
 
 DEFINE_SHOW_STORE_ATTRIBUTE(i915_bigjoiner_enable);
drivers/gpu/drm/i915/display/intel_display_debugfs_params.c +18 -18
index f35718748555..deb2a157a4f9 100644
@@ -27,20 +27,20 @@ static int intel_display_param_int_open(struct inode *inode, struct file *file)
 	return single_open(file, intel_display_param_int_show, inode->i_private);
 }
 
-static ssize_t intel_display_param_int_write(struct file *file,
-					     const char __user *ubuf, size_t len,
-					     loff_t *offp)
+static ssize_t intel_display_param_int_write(struct kiocb *iocb,
+					     struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(from);
 	int *value = m->private;
 	int ret;
 
-	ret = kstrtoint_from_user(ubuf, len, 0, value);
+	ret = kstrtoint_from_iter(from, len, 0, value);
 	if (ret) {
 		/* support boolean values too */
 		bool b;
 
-		ret = kstrtobool_from_user(ubuf, len, &b);
+		ret = kstrtobool_from_iter(from, len, &b);
 		if (!ret)
 			*value = b;
 	}
@@ -51,8 +51,8 @@ static ssize_t intel_display_param_int_write(struct file *file,
 static const struct file_operations intel_display_param_int_fops = {
 	.owner = THIS_MODULE,
 	.open = intel_display_param_int_open,
-	.read = seq_read,
-	.write = intel_display_param_int_write,
+	.read_iter = seq_read_iter,
+	.write_iter = intel_display_param_int_write,
 	.llseek = default_llseek,
 	.release = single_release,
 };
@@ -60,7 +60,7 @@ static const struct file_operations intel_display_param_int_fops = {
 static const struct file_operations intel_display_param_int_fops_ro = {
 	.owner = THIS_MODULE,
 	.open = intel_display_param_int_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = default_llseek,
 	.release = single_release,
 };
@@ -80,20 +80,20 @@ static int intel_display_param_uint_open(struct inode *inode, struct file *file)
 	return single_open(file, intel_display_param_uint_show, inode->i_private);
 }
 
-static ssize_t intel_display_param_uint_write(struct file *file,
-					      const char __user *ubuf, size_t len,
-					      loff_t *offp)
+static ssize_t intel_display_param_uint_write(struct kiocb *iocb,
+					      struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
+	size_t len = iov_iter_count(from);
 	unsigned int *value = m->private;
 	int ret;
 
-	ret = kstrtouint_from_user(ubuf, len, 0, value);
+	ret = kstrtouint_from_iter(from, len, 0, value);
 	if (ret) {
 		/* support boolean values too */
 		bool b;
 
-		ret = kstrtobool_from_user(ubuf, len, &b);
+		ret = kstrtobool_from_iter(from, len, &b);
 		if (!ret)
 			*value = b;
 	}
@@ -104,8 +104,8 @@ static ssize_t intel_display_param_uint_write(struct file *file,
 static const struct file_operations intel_display_param_uint_fops = {
 	.owner = THIS_MODULE,
 	.open = intel_display_param_uint_open,
-	.read = seq_read,
-	.write = intel_display_param_uint_write,
+	.read_iter = seq_read_iter,
+	.write_iter = intel_display_param_uint_write,
 	.llseek = default_llseek,
 	.release = single_release,
 };
@@ -113,7 +113,7 @@ static const struct file_operations intel_display_param_uint_fops = {
 static const struct file_operations intel_display_param_uint_fops_ro = {
 	.owner = THIS_MODULE,
 	.open = intel_display_param_uint_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = default_llseek,
 	.release = single_release,
 };
drivers/gpu/drm/i915/display/intel_hotplug.c +14 -14
index d9ec349f3c8c..0a4a54fea1aa 100644
@@ -1019,13 +1019,13 @@ static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
 	return 0;
 }
 
-static ssize_t i915_hpd_storm_ctl_write(struct file *file,
-					const char __user *ubuf, size_t len,
-					loff_t *offp)
+static ssize_t i915_hpd_storm_ctl_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_i915_private *dev_priv = m->private;
 	struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
+	size_t len = iov_iter_count(from);
 	unsigned int new_threshold;
 	int i;
 	char *newline;
@@ -1034,7 +1034,7 @@ static ssize_t i915_hpd_storm_ctl_write(struct file *file,
 	if (len >= sizeof(tmp))
 		return -EINVAL;
 
-	if (copy_from_user(tmp, ubuf, len))
+	if (!copy_from_iter_full(tmp, len, from))
 		return -EFAULT;
 
 	tmp[len] = '\0';
@@ -1077,10 +1077,10 @@ static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
 static const struct file_operations i915_hpd_storm_ctl_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_hpd_storm_ctl_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = i915_hpd_storm_ctl_write
+	.write_iter = i915_hpd_storm_ctl_write
 };
 
 static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
@@ -1100,13 +1100,13 @@ i915_hpd_short_storm_ctl_open(struct inode *inode, struct file *file)
 			   inode->i_private);
 }
 
-static ssize_t i915_hpd_short_storm_ctl_write(struct file *file,
-					      const char __user *ubuf,
-					      size_t len, loff_t *offp)
+static ssize_t i915_hpd_short_storm_ctl_write(struct kiocb *iocb,
+					      struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_i915_private *dev_priv = m->private;
 	struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
+	size_t len = iov_iter_count(from);
 	char *newline;
 	char tmp[16];
 	int i;
@@ -1115,7 +1115,7 @@ static ssize_t i915_hpd_short_storm_ctl_write(struct file *file,
 	if (len >= sizeof(tmp))
 		return -EINVAL;
 
-	if (copy_from_user(tmp, ubuf, len))
+	if (!copy_from_iter_full(tmp, len, from))
 		return -EFAULT;
 
 	tmp[len] = '\0';
@@ -1150,10 +1150,10 @@ static ssize_t i915_hpd_short_storm_ctl_write(struct file *file,
 static const struct file_operations i915_hpd_short_storm_ctl_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_hpd_short_storm_ctl_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = i915_hpd_short_storm_ctl_write,
+	.write_iter = i915_hpd_short_storm_ctl_write,
 };
 
 void intel_hpd_debugfs_register(struct drm_i915_private *i915)
drivers/gpu/drm/i915/display/intel_wm.c +20 -22

108 lines not on this page · raw message

drivers/gpu/drm/i915/display/skl_watermark.c +7 -7
index c6b9be80d83c..9c87f0c1a0da 100644
@@ -3713,17 +3713,17 @@ static int skl_watermark_ipc_status_open(struct inode *inode, struct file *file)
 	return single_open(file, skl_watermark_ipc_status_show, i915);
 }
 
-static ssize_t skl_watermark_ipc_status_write(struct file *file,
-					      const char __user *ubuf,
-					      size_t len, loff_t *offp)
+static ssize_t skl_watermark_ipc_status_write(struct kiocb *iocb,
+					      struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_i915_private *i915 = m->private;
+	size_t len = iov_iter_count(from);
 	intel_wakeref_t wakeref;
 	bool enable;
 	int ret;
 
-	ret = kstrtobool_from_user(ubuf, len, &enable);
+	ret = kstrtobool_from_iter(from, len, &enable);
 	if (ret < 0)
 		return ret;
 
@@ -3741,10 +3741,10 @@ static ssize_t skl_watermark_ipc_status_write(struct file *file,
 static const struct file_operations skl_watermark_ipc_status_fops = {
 	.owner = THIS_MODULE,
 	.open = skl_watermark_ipc_status_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = skl_watermark_ipc_status_write
+	.write_iter = skl_watermark_ipc_status_write
 };
 
 static int intel_sagv_status_show(struct seq_file *m, void *unused)
drivers/gpu/drm/i915/gt/intel_gt_debugfs.c +1 -1
index 4dc23b8d3aa2..ed8c47f3cc39 100644
@@ -107,7 +107,7 @@ void intel_gt_debugfs_register_files(struct dentry *root,
 				     unsigned long count, void *data)
 {
 	while (count--) {
-		umode_t mode = files->fops->write ? 0644 : 0444;
+		umode_t mode = files->fops->write_iter ? 0644 : 0444;
 
 		if (!files->eval || files->eval(data))
 			debugfs_create_file(files->name,
drivers/gpu/drm/i915/gt/intel_gt_debugfs.h +1 -1
index e4110eebf093..1753bebb6f70 100644
@@ -14,7 +14,7 @@ struct intel_gt;
 static const struct file_operations __name ## _fops = {			\
 	.owner = THIS_MODULE,						\
 	.open = __name ## _open,					\
-	.read = seq_read,						\
+	.read_iter = seq_read_iter,					\
 	.llseek = seq_lseek,						\
 	.release = single_release,					\
 }
drivers/gpu/drm/i915/gt/uc/intel_guc_log_debugfs.c +5 -8
index ddfbe334689f..3284631a8c07 100644
@@ -117,17 +117,14 @@ static int guc_log_relay_open(struct inode *inode, struct file *file)
 	return intel_guc_log_relay_open(log);
 }
 
-static ssize_t
-guc_log_relay_write(struct file *filp,
-		    const char __user *ubuf,
-		    size_t cnt,
-		    loff_t *ppos)
+static ssize_t guc_log_relay_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct intel_guc_log *log = filp->private_data;
+	struct intel_guc_log *log = iocb->ki_filp->private_data;
+	size_t cnt = iov_iter_count(from);
 	int val;
 	int ret;
 
-	ret = kstrtoint_from_user(ubuf, cnt, 0, &val);
+	ret = kstrtoint_from_iter(from, cnt, 0, &val);
 	if (ret < 0)
 		return ret;
 
@@ -154,7 +151,7 @@ static int guc_log_relay_release(struct inode *inode, struct file *file)
 static const struct file_operations guc_log_relay_fops = {
 	.owner = THIS_MODULE,
 	.open = guc_log_relay_open,
-	.write = guc_log_relay_write,
+	.write_iter = guc_log_relay_write,
 	.release = guc_log_relay_release,
 };
 
drivers/gpu/drm/i915/i915_debugfs_params.c +21 -22

117 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gpu_error.c +12 -16
index a0b784ebaddd..ca0851c07082 100644
@@ -2380,14 +2380,14 @@ void intel_klog_error_capture(struct intel_gt *gt,
 }
 #endif
 
-static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
-			      size_t count, loff_t *pos)
+static ssize_t gpu_state_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct i915_gpu_coredump *error;
+	size_t count = iov_iter_count(to);
 	ssize_t ret;
 	void *buf;
 
-	error = file->private_data;
+	error = iocb->ki_filp->private_data;
 	if (!error)
 		return 0;
 
@@ -2396,12 +2396,12 @@ static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
 	if (!buf)
 		return -ENOMEM;
 
-	ret = i915_gpu_coredump_copy_to_buffer(error, buf, *pos, count);
+	ret = i915_gpu_coredump_copy_to_buffer(error, buf, iocb->ki_pos, count);
 	if (ret <= 0)
 		goto out;
 
-	if (!copy_to_user(ubuf, buf, ret))
-		*pos += ret;
+	if (copy_to_iter_full(buf, ret, to))
+		iocb->ki_pos += ret;
 	else
 		ret = -EFAULT;
 
@@ -2436,18 +2436,14 @@ static int i915_gpu_info_open(struct inode *inode, struct file *file)
 static const struct file_operations i915_gpu_info_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_gpu_info_open,
-	.read = gpu_state_read,
+	.read_iter = gpu_state_read,
 	.llseek = default_llseek,
 	.release = gpu_state_release,
 };
 
-static ssize_t
-i915_error_state_write(struct file *filp,
-		       const char __user *ubuf,
-		       size_t cnt,
-		       loff_t *ppos)
+static ssize_t i915_error_state_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct i915_gpu_coredump *error = filp->private_data;
+	struct i915_gpu_coredump *error = iocb->ki_filp->private_data;
 
 	if (!error)
 		return 0;
@@ -2455,7 +2451,7 @@ i915_error_state_write(struct file *filp,
 	drm_dbg(&error->i915->drm, "Resetting error state\n");
 	i915_reset_error_state(error->i915);
 
-	return cnt;
+	return iov_iter_count(from);
 }
 
 static int i915_error_state_open(struct inode *inode, struct file *file)
@@ -2473,8 +2469,8 @@ static int i915_error_state_open(struct inode *inode, struct file *file)
 static const struct file_operations i915_error_state_fops = {
 	.owner = THIS_MODULE,
 	.open = i915_error_state_open,
-	.read = gpu_state_read,
-	.write = i915_error_state_write,
+	.read_iter = gpu_state_read,
+	.write_iter = i915_error_state_write,
 	.llseek = default_llseek,
 	.release = gpu_state_release,
 };
drivers/gpu/drm/i915/i915_perf.c +2 -1
index bd9d812b1afa..8ff6d5b0b40a 100644
@@ -3512,6 +3512,7 @@ static ssize_t i915_perf_read(struct file *file,
 	/* Possible values for ret are 0, -EFAULT, -ENOSPC, -EIO, ... */
 	return offset ?: (ret ?: -EAGAIN);
 }
+FOPS_READ_ITER_HELPER(i915_perf_read);
 
 static enum hrtimer_restart oa_poll_check_timer_cb(struct hrtimer *hrtimer)
 {
@@ -3788,7 +3789,7 @@ static const struct file_operations fops = {
 	.llseek		= no_llseek,
 	.release	= i915_perf_release,
 	.poll		= i915_perf_poll,
-	.read		= i915_perf_read,
+	.read_iter	= i915_perf_read_iter,
 	.unlocked_ioctl	= i915_perf_ioctl,
 	/* Our ioctl have no arguments, so it's safe to use the same function
 	 * to handle 32bits compatibility.
Signature · 1 line
2.43.0
author maintainer
#145 lore raw

PATCH 139/437 drm: amd: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c       |   4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   |  71 +++++++----
 .../drm/amd/amdgpu/amdgpu_fw_attestation.c    |  23 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c       |   4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c    |  18 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_rap.c       |  14 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c       |  34 +++---
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    |  22 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c      |   6 +-
 .../gpu/drm/amd/amdgpu/amdgpu_securedisplay.c |  14 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  56 ++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c       |   3 +-
 drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c      |  13 +-
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  19 ++-
 .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 111 ++++++++++--------
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  11 +-
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  17 +--
 17 files changed, 231 insertions(+), 209 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +2 -2
index 493982f94649..8fd471e72ae9 100644
@@ -840,7 +840,7 @@ static int aca_dump_ce_open(struct inode *inode, struct file *file)
 static const struct file_operations aca_ce_dump_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = aca_dump_ce_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -858,7 +858,7 @@ static int aca_dump_ue_open(struct inode *inode, struct file *file)
 static const struct file_operations aca_ue_dump_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = aca_dump_ue_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +46 -25

278 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_fw_attestation.c +10 -13
index 2d4b67175b55..a5edb6de1c10 100644
@@ -50,23 +50,22 @@ struct FW_ATT_RECORD {
 	uint32_t AttFwTaId;              /* Ta ID (only in TA Attestation Table) */
 };
 
-static ssize_t amdgpu_fw_attestation_debugfs_read(struct file *f,
-						  char __user *buf,
-						  size_t size,
-						  loff_t *pos)
+static ssize_t amdgpu_fw_attestation_debugfs_read(struct kiocb *iocb,
+						  struct iov_iter *to)
 {
-	struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
+	struct amdgpu_device *adev = file_inode(iocb->ki_filp)->i_private;
 	uint64_t records_addr = 0;
 	uint64_t vram_pos = 0;
 	struct FW_ATT_DB_HEADER fw_att_hdr = {0};
 	struct FW_ATT_RECORD fw_att_record = {0};
+	size_t size = iov_iter_count(to);
 
 	if (size < sizeof(struct FW_ATT_RECORD)) {
 		DRM_WARN("FW attestation input buffer not enough memory");
 		return -EINVAL;
 	}
 
-	if ((*pos + sizeof(struct FW_ATT_DB_HEADER)) >= FW_ATTESTATION_MAX_SIZE) {
+	if ((iocb->ki_pos + sizeof(struct FW_ATT_DB_HEADER)) >= FW_ATTESTATION_MAX_SIZE) {
 		DRM_WARN("FW attestation out of bounds");
 		return 0;
 	}
@@ -78,7 +77,7 @@ static ssize_t amdgpu_fw_attestation_debugfs_read(struct file *f,
 
 	vram_pos =  records_addr - adev->gmc.vram_start;
 
-	if (*pos == 0) {
+	if (iocb->ki_pos == 0) {
 		amdgpu_device_vram_access(adev,
 					  vram_pos,
 					  (uint32_t *)&fw_att_hdr,
@@ -94,7 +93,7 @@ static ssize_t amdgpu_fw_attestation_debugfs_read(struct file *f,
 	}
 
 	amdgpu_device_vram_access(adev,
-				  vram_pos + sizeof(struct FW_ATT_DB_HEADER) + *pos,
+				  vram_pos + sizeof(struct FW_ATT_DB_HEADER) + iocb->ki_pos,
 				  (uint32_t *)&fw_att_record,
 				  sizeof(struct FW_ATT_RECORD),
 				  false);
@@ -102,18 +101,16 @@ static ssize_t amdgpu_fw_attestation_debugfs_read(struct file *f,
 	if (fw_att_record.RecordValid != FW_ATTESTATION_RECORD_VALID)
 		return 0;
 
-	if (copy_to_user(buf, (void *)&fw_att_record, sizeof(struct FW_ATT_RECORD)))
+	if (!copy_to_iter_full((void *)&fw_att_record, sizeof(struct FW_ATT_RECORD), to))
 		return -EINVAL;
 
-	*pos += sizeof(struct FW_ATT_RECORD);
-
+	iocb->ki_pos += sizeof(struct FW_ATT_RECORD);
 	return sizeof(struct FW_ATT_RECORD);
 }
 
 static const struct file_operations amdgpu_fw_attestation_debugfs_ops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_fw_attestation_debugfs_read,
-	.write = NULL,
+	.read_iter = amdgpu_fw_attestation_debugfs_read,
 	.llseek = default_llseek
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +2 -2
index 24ad4b97177b..c6a971a260df 100644
@@ -480,7 +480,7 @@ static int mca_dump_ce_open(struct inode *inode, struct file *file)
 static const struct file_operations mca_ce_dump_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = mca_dump_ce_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -498,7 +498,7 @@ static int mca_dump_ue_open(struct inode *inode, struct file *file)
 static const struct file_operations mca_ue_dump_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = mca_dump_ue_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +9 -9
index ca5c86e5f7cd..f96fde084fc6 100644
@@ -26,12 +26,9 @@
 
 #if defined(CONFIG_DEBUG_FS)
 
-static ssize_t ta_if_load_debugfs_write(struct file *fp, const char *buf,
-					    size_t len, loff_t *off);
-static ssize_t ta_if_unload_debugfs_write(struct file *fp, const char *buf,
-					    size_t len, loff_t *off);
-static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf,
-					    size_t len, loff_t *off);
+static ssize_t ta_if_load_debugfs_write_iter(struct kiocb *, struct iov_iter *);
+static ssize_t ta_if_unload_debugfs_write_iter(struct kiocb *, struct iov_iter *);
+static ssize_t ta_if_invoke_debugfs_write_iter(struct kiocb *, struct iov_iter *);
 
 static uint32_t get_bin_version(const uint8_t *bin)
 {
@@ -84,19 +81,19 @@ static void set_ta_context_funcs(struct psp_context *psp,
 }
 
 static const struct file_operations ta_load_debugfs_fops = {
-	.write  = ta_if_load_debugfs_write,
+	.write_iter  = ta_if_load_debugfs_write_iter,
 	.llseek = default_llseek,
 	.owner  = THIS_MODULE
 };
 
 static const struct file_operations ta_unload_debugfs_fops = {
-	.write  = ta_if_unload_debugfs_write,
+	.write_iter  = ta_if_unload_debugfs_write_iter,
 	.llseek = default_llseek,
 	.owner  = THIS_MODULE
 };
 
 static const struct file_operations ta_invoke_debugfs_fops = {
-	.write  = ta_if_invoke_debugfs_write,
+	.write_iter  = ta_if_invoke_debugfs_write_iter,
 	.llseek = default_llseek,
 	.owner  = THIS_MODULE
 };
@@ -240,6 +237,7 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp, const char *buf, size_t
 
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(ta_if_load_debugfs_write);
 
 static ssize_t ta_if_unload_debugfs_write(struct file *fp, const char *buf, size_t len, loff_t *off)
 {
@@ -286,6 +284,7 @@ static ssize_t ta_if_unload_debugfs_write(struct file *fp, const char *buf, size
 
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(ta_if_unload_debugfs_write);
 
 static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size_t len, loff_t *off)
 {
@@ -370,6 +369,7 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size
 
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(ta_if_invoke_debugfs_write);
 
 void amdgpu_ta_if_debugfs_init(struct amdgpu_device *adev)
 {
drivers/gpu/drm/amd/amdgpu/amdgpu_rap.c +7 -7
index 123bcf5c2bb1..b946c94972b2 100644
@@ -40,21 +40,22 @@
  * from header file ta_rap_if.h
  *
  */
-static ssize_t amdgpu_rap_debugfs_write(struct file *f, const char __user *buf,
-		size_t size, loff_t *pos)
+static ssize_t amdgpu_rap_debugfs_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
+	struct amdgpu_device *adev = file_inode(iocb->ki_filp)->i_private;
 	struct ta_rap_shared_memory *rap_shared_mem;
 	struct ta_rap_cmd_output_data *rap_cmd_output;
 	struct drm_device *dev = adev_to_drm(adev);
+	size_t size = iov_iter_count(from);
 	uint32_t op;
 	enum ta_rap_status status;
 	int ret;
 
-	if (*pos || size != 2)
+	if (iocb->ki_pos || size != 2)
 		return -EINVAL;
 
-	ret = kstrtouint_from_user(buf, size, *pos, &op);
+	ret = kstrtouint_from_iter(from, size, iocb->ki_pos, &op);
 	if (ret)
 		return ret;
 
@@ -109,8 +110,7 @@ static ssize_t amdgpu_rap_debugfs_write(struct file *f, const char __user *buf,
 
 static const struct file_operations amdgpu_rap_debugfs_ops = {
 	.owner = THIS_MODULE,
-	.read = NULL,
-	.write = amdgpu_rap_debugfs_write,
+	.write_iter = amdgpu_rap_debugfs_write,
 	.llseek = default_llseek
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +15 -19
index 8ebab6f22e5a..f8daf833f0c4 100644
@@ -201,13 +201,13 @@ static int amdgpu_reserve_page_direct(struct amdgpu_device *adev, uint64_t addre
 	return 0;
 }
 
-static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
-					size_t size, loff_t *pos)
+static ssize_t amdgpu_ras_debugfs_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct ras_manager *obj = (struct ras_manager *)file_inode(f)->i_private;
+	struct ras_manager *obj = file_inode(iocb->ki_filp)->i_private;
 	struct ras_query_if info = {
 		.head = obj->head,
 	};
+	size_t size = iov_iter_count(to);
 	ssize_t s;
 	char val[128];
 
@@ -224,25 +224,23 @@ static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
 	s = snprintf(val, sizeof(val), "%s: %lu\n%s: %lu\n",
 			"ue", info.ue_count,
 			"ce", info.ce_count);
-	if (*pos >= s)
+	if (iocb->ki_pos >= s)
 		return 0;
 
-	s -= *pos;
+	s -= iocb->ki_pos;
 	s = min_t(u64, s, size);
 
 
-	if (copy_to_user(buf, &val[*pos], s))
+	if (!copy_to_iter_full(&val[iocb->ki_pos], s, to))
 		return -EINVAL;
 
-	*pos += s;
-
+	iocb->ki_pos += s;
 	return s;
 }
 
 static const struct file_operations amdgpu_ras_debugfs_ops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_ras_debugfs_read,
-	.write = NULL,
+	.read_iter = amdgpu_ras_debugfs_read,
 	.llseek = default_llseek
 };
 
@@ -541,6 +539,7 @@ static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f,
 
 	return size;
 }
+FOPS_WRITE_ITER_HELPER(amdgpu_ras_debugfs_ctrl_write);
 
 /**
  * DOC: AMDGPU RAS debugfs EEPROM table reset interface
@@ -558,12 +557,11 @@ static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f,
  * will reset EEPROM table to 0 entries.
  *
  */
-static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f,
-					       const char __user *buf,
-					       size_t size, loff_t *pos)
+static ssize_t amdgpu_ras_debugfs_eeprom_write(struct kiocb *iocb,
+					       struct iov_iter *from)
 {
-	struct amdgpu_device *adev =
-		(struct amdgpu_device *)file_inode(f)->i_private;
+	struct amdgpu_device *adev = file_inode(iocb->ki_filp)->i_private;
+	size_t size = iov_iter_count(from);
 	int ret;
 
 	ret = amdgpu_ras_eeprom_reset_table(
@@ -581,15 +579,13 @@ static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f,
 
 static const struct file_operations amdgpu_ras_debugfs_ctrl_ops = {
 	.owner = THIS_MODULE,
-	.read = NULL,
-	.write = amdgpu_ras_debugfs_ctrl_write,
+	.write_iter = amdgpu_ras_debugfs_ctrl_write_iter,
 	.llseek = default_llseek
 };
 
 static const struct file_operations amdgpu_ras_debugfs_eeprom_ops = {
 	.owner = THIS_MODULE,
-	.read = NULL,
-	.write = amdgpu_ras_debugfs_eeprom_write,
+	.write_iter = amdgpu_ras_debugfs_eeprom_write,
 	.llseek = default_llseek
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +10 -12
index b12808c0c331..4d62691e3804 100644
@@ -1001,12 +1001,12 @@ uint32_t amdgpu_ras_eeprom_max_record_count(struct amdgpu_ras_eeprom_control *co
 }
 
 static ssize_t
-amdgpu_ras_debugfs_eeprom_size_read(struct file *f, char __user *buf,
-				    size_t size, loff_t *pos)
+amdgpu_ras_debugfs_eeprom_size_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
+	struct amdgpu_device *adev = file_inode(iocb->ki_filp)->i_private;
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
 	struct amdgpu_ras_eeprom_control *control = ras ? &ras->eeprom_control : NULL;
+	size_t size = iov_iter_count(to);
 	u8 data[50];
 	int res;
 
@@ -1020,24 +1020,22 @@ amdgpu_ras_debugfs_eeprom_size_read(struct file *f, char __user *buf,
 			       RAS_TBL_SIZE_BYTES, control->ras_max_record_count);
 	}
 
-	if (*pos >= res)
+	if (iocb->ki_pos >= res)
 		return 0;
 
-	res -= *pos;
+	res -= iocb->ki_pos;
 	res = min_t(size_t, res, size);
 
-	if (copy_to_user(buf, &data[*pos], res))
+	if (!copy_to_iter_full(&data[iocb->ki_pos], res, to))
 		return -EFAULT;
 
-	*pos += res;
-
+	iocb->ki_pos += res;
 	return res;
 }
 
 const struct file_operations amdgpu_ras_debugfs_eeprom_size_ops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_ras_debugfs_eeprom_size_read,
-	.write = NULL,
+	.read_iter = amdgpu_ras_debugfs_eeprom_size_read,
 	.llseek = default_llseek,
 };
 
@@ -1215,11 +1213,11 @@ amdgpu_ras_debugfs_eeprom_table_read(struct file *f, char __user *buf,
 		return amdgpu_ras_debugfs_table_read(f, buf, size, pos);
 	}
 }
+FOPS_READ_ITER_HELPER(amdgpu_ras_debugfs_eeprom_table_read);
 
 const struct file_operations amdgpu_ras_debugfs_eeprom_table_ops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_ras_debugfs_eeprom_table_read,
-	.write = NULL,
+	.read_iter = amdgpu_ras_debugfs_eeprom_table_read_iter,
 	.llseek = default_llseek,
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +4 -2
index 06f0a6534a94..a03bc2765b88 100644
@@ -512,10 +512,11 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, char __user *buf,
 
 	return result;
 }
+FOPS_READ_ITER_HELPER(amdgpu_debugfs_ring_read);
 
 static const struct file_operations amdgpu_debugfs_ring_fops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_debugfs_ring_read,
+	.read_iter = amdgpu_debugfs_ring_read_iter,
 	.llseek = default_llseek
 };
 
@@ -577,10 +578,11 @@ static ssize_t amdgpu_debugfs_mqd_read(struct file *f, char __user *buf,
 	kfree(kbuf);
 	return r;
 }
+FOPS_READ_ITER_HELPER(amdgpu_debugfs_mqd_read);
 
 static const struct file_operations amdgpu_debugfs_mqd_fops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_debugfs_mqd_read,
+	.read_iter = amdgpu_debugfs_mqd_read_iter,
 	.llseek = default_llseek
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +7 -7
index 8ed0e073656f..f7bfa470979f 100644
@@ -88,23 +88,24 @@ void psp_prep_securedisplay_cmd_buf(struct psp_context *psp, struct ta_securedis
 
 #if defined(CONFIG_DEBUG_FS)
 
-static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __user *buf,
-		size_t size, loff_t *pos)
+static ssize_t amdgpu_securedisplay_debugfs_write(struct kiocb *iocb,
+						  struct iov_iter *from)
 {
-	struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
+	struct amdgpu_device *adev = file_inode(iocb->ki_filp)->i_private;
 	struct psp_context *psp = &adev->psp;
 	struct ta_securedisplay_cmd *securedisplay_cmd;
 	struct drm_device *dev = adev_to_drm(adev);
+	size_t size = iov_iter_count(from);
 	uint32_t phy_id;
 	uint32_t op;
 	char str[64];
 	int ret;
 
-	if (*pos || size > sizeof(str) - 1)
+	if (iocb->ki_pos || size > sizeof(str) - 1)
 		return -EINVAL;
 
 	memset(str,  0, sizeof(str));
-	ret = copy_from_user(str, buf, size);
+	ret = !copy_from_iter_full(str, size, from);
 	if (ret)
 		return -EFAULT;
 
@@ -163,8 +164,7 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u
 
 static const struct file_operations amdgpu_securedisplay_debugfs_ops = {
 	.owner = THIS_MODULE,
-	.read = NULL,
-	.write = amdgpu_securedisplay_debugfs_write,
+	.write_iter = amdgpu_securedisplay_debugfs_write,
 	.llseek = default_llseek
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +28 -28

139 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +2 -1
index 9c514a606a2f..e2596f9fe6f0 100644
@@ -1142,10 +1142,11 @@ static ssize_t amdgpu_debugfs_vcn_fwlog_read(struct file *f, char __user *buf,
 	*pos += read_bytes;
 	return read_bytes;
 }
+FOPS_READ_ITER_HELPER(amdgpu_debugfs_vcn_fwlog_read);
 
 static const struct file_operations amdgpu_debugfs_vcnfwlog_fops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_debugfs_vcn_fwlog_read,
+	.read_iter = amdgpu_debugfs_vcn_fwlog_read_iter,
 	.llseek = default_llseek
 };
 #endif
drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c +7 -6
index 4a5a0a4e00f2..1f03e7915b99 100644
@@ -40,9 +40,10 @@ static int kfd_debugfs_hang_hws_read(struct seq_file *m, void *data)
 	return 0;
 }
 
-static ssize_t kfd_debugfs_hang_hws_write(struct file *file,
-	const char __user *user_buf, size_t size, loff_t *ppos)
+static ssize_t kfd_debugfs_hang_hws_write(struct kiocb *iocb,
+					  struct iov_iter *from)
 {
+	size_t size = iov_iter_count(from);
 	struct kfd_node *dev;
 	char tmp[16];
 	uint32_t gpu_id;
@@ -53,7 +54,7 @@ static ssize_t kfd_debugfs_hang_hws_write(struct file *file,
 		pr_err("Invalid input for gpu id.\n");
 		goto out;
 	}
-	if (copy_from_user(tmp, user_buf, size)) {
+	if (!copy_from_iter_full(tmp, size, from)) {
 		ret = -EFAULT;
 		goto out;
 	}
@@ -75,7 +76,7 @@ static ssize_t kfd_debugfs_hang_hws_write(struct file *file,
 static const struct file_operations kfd_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = kfd_debugfs_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -83,8 +84,8 @@ static const struct file_operations kfd_debugfs_fops = {
 static const struct file_operations kfd_debugfs_hang_hws_fops = {
 	.owner = THIS_MODULE,
 	.open = kfd_debugfs_open,
-	.read = seq_read,
-	.write = kfd_debugfs_hang_hws_write,
+	.read_iter = seq_read_iter,
+	.write_iter = kfd_debugfs_hang_hws_write,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +8 -11
index 06ac835190f9..04eba7e9dfae 100644
@@ -46,9 +46,8 @@ struct kfd_smi_client {
 #define MAX_KFIFO_SIZE	1024
 
 static __poll_t kfd_smi_ev_poll(struct file *, struct poll_table_struct *);
-static ssize_t kfd_smi_ev_read(struct file *, char __user *, size_t, loff_t *);
-static ssize_t kfd_smi_ev_write(struct file *, const char __user *, size_t,
-				loff_t *);
+static ssize_t kfd_smi_ev_read_iter(struct kiocb *, struct iov_iter *);
+static ssize_t kfd_smi_ev_write(struct kiocb *, struct iov_iter *);
 static int kfd_smi_ev_release(struct inode *, struct file *);
 
 static const char kfd_smi_name[] = "kfd_smi_ev";
@@ -56,8 +55,8 @@ static const char kfd_smi_name[] = "kfd_smi_ev";
 static const struct file_operations kfd_smi_ev_fops = {
 	.owner = THIS_MODULE,
 	.poll = kfd_smi_ev_poll,
-	.read = kfd_smi_ev_read,
-	.write = kfd_smi_ev_write,
+	.read_iter = kfd_smi_ev_read_iter,
+	.write_iter = kfd_smi_ev_write,
 	.release = kfd_smi_ev_release
 };
 
@@ -121,16 +120,14 @@ static ssize_t kfd_smi_ev_read(struct file *filep, char __user *user,
 	kfree(buf);
 	return ret;
 }
+FOPS_READ_ITER_HELPER(kfd_smi_ev_read);
 
-static ssize_t kfd_smi_ev_write(struct file *filep, const char __user *user,
-				size_t size, loff_t *offset)
+static ssize_t kfd_smi_ev_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct kfd_smi_client *client = filep->private_data;
+	struct kfd_smi_client *client = iocb->ki_filp->private_data;
 	uint64_t events;
 
-	if (!access_ok(user, size) || size < sizeof(events))
-		return -EFAULT;
-	if (copy_from_user(&events, user, sizeof(events)))
+	if (!copy_from_iter_full(&events, sizeof(events), from))
 		return -EFAULT;
 
 	WRITE_ONCE(client->events, events);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +64 -47

386 lines not on this page · raw message

drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -6
index f09b9d49297e..d78f7b351f7d 100644
@@ -4572,10 +4572,9 @@ DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_pm_info);
  *
  * Reads debug memory region allocated to PMFW
  */
-static ssize_t amdgpu_pm_prv_buffer_read(struct file *f, char __user *buf,
-					 size_t size, loff_t *pos)
+static ssize_t amdgpu_pm_prv_buffer_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct amdgpu_device *adev = file_inode(f)->i_private;
+	struct amdgpu_device *adev = file_inode(iocb->ki_filp)->i_private;
 	size_t smu_prv_buf_size;
 	void *smu_prv_buf;
 	int ret = 0;
@@ -4592,14 +4591,14 @@ static ssize_t amdgpu_pm_prv_buffer_read(struct file *f, char __user *buf,
 	if (!smu_prv_buf || !smu_prv_buf_size)
 		return -EINVAL;
 
-	return simple_read_from_buffer(buf, size, pos, smu_prv_buf,
-				       smu_prv_buf_size);
+	return simple_copy_to_iter(smu_prv_buf, &iocb->ki_pos,
+					smu_prv_buf_size, to);
 }
 
 static const struct file_operations amdgpu_debugfs_pm_prv_buffer_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = amdgpu_pm_prv_buffer_read,
+	.read_iter = amdgpu_pm_prv_buffer_read,
 	.llseek = default_llseek,
 };
 
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -12
index 246b211b1e85..04332432e57f 100644
@@ -3603,20 +3603,13 @@ static int smu_stb_debugfs_open(struct inode *inode, struct file *filp)
 	return r;
 }
 
-static ssize_t smu_stb_debugfs_read(struct file *filp, char __user *buf, size_t size,
-				loff_t *pos)
+static ssize_t smu_stb_debugfs_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct amdgpu_device *adev = filp->f_inode->i_private;
+	struct amdgpu_device *adev = iocb->ki_filp->f_inode->i_private;
 	struct smu_context *smu = adev->powerplay.pp_handle;
 
-
-	if (!filp->private_data)
-		return -EINVAL;
-
-	return simple_read_from_buffer(buf,
-				       size,
-				       pos, filp->private_data,
-				       smu->stb_context.stb_buf_size);
+	return simple_copy_to_iter(adev, &iocb->ki_pos,
+				       smu->stb_context.stb_buf_size, to);
 }
 
 static int smu_stb_debugfs_release(struct inode *inode, struct file *filp)
@@ -3637,7 +3630,7 @@ static int smu_stb_debugfs_release(struct inode *inode, struct file *filp)
 static const struct file_operations smu_stb_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = smu_stb_debugfs_open,
-	.read = smu_stb_debugfs_read,
+	.read_iter = smu_stb_debugfs_read,
 	.release = smu_stb_debugfs_release,
 	.llseek = default_llseek,
 };
Signature · 1 line
2.43.0
author maintainer
#146 lore raw

PATCH 140/437 drm: msm: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c | 20 +++++++++----------
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c       | 20 +++++++++----------
 drivers/gpu/drm/msm/dp/dp_debug.c             | 15 +++++++-------
 drivers/gpu/drm/msm/msm_debugfs.c             |  4 ++--
 drivers/gpu/drm/msm/msm_perf.c                | 12 +++++------
 drivers/gpu/drm/msm/msm_rd.c                  | 12 +++++------
 6 files changed, 41 insertions(+), 42 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c +10 -10
index ef871239adb2..c8971ba26cd4 100644
@@ -398,14 +398,15 @@ int dpu_core_perf_crtc_update(struct drm_crtc *crtc,
 
 #ifdef CONFIG_DEBUG_FS
 
-static ssize_t _dpu_core_perf_mode_write(struct file *file,
-		    const char __user *user_buf, size_t count, loff_t *ppos)
+static ssize_t _dpu_core_perf_mode_write(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct dpu_core_perf *perf = file->private_data;
+	struct dpu_core_perf *perf = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	u32 perf_mode = 0;
 	int ret;
 
-	ret = kstrtouint_from_user(user_buf, count, 0, &perf_mode);
+	ret = kstrtouint_from_iter(from, count, 0, &perf_mode);
 	if (ret)
 		return ret;
 
@@ -426,10 +427,9 @@ static ssize_t _dpu_core_perf_mode_write(struct file *file,
 	return count;
 }
 
-static ssize_t _dpu_core_perf_mode_read(struct file *file,
-			char __user *buff, size_t count, loff_t *ppos)
+static ssize_t _dpu_core_perf_mode_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct dpu_core_perf *perf = file->private_data;
+	struct dpu_core_perf *perf = iocb->ki_filp->private_data;
 	int len;
 	char buf[128];
 
@@ -437,13 +437,13 @@ static ssize_t _dpu_core_perf_mode_read(struct file *file,
 			"mode %d\n",
 			perf->perf_tune.mode);
 
-	return simple_read_from_buffer(buff, count, ppos, buf, len);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 }
 
 static const struct file_operations dpu_core_perf_mode_fops = {
 	.open = simple_open,
-	.read = _dpu_core_perf_mode_read,
-	.write = _dpu_core_perf_mode_write,
+	.read_iter = _dpu_core_perf_mode_read,
+	.write_iter = _dpu_core_perf_mode_write,
 };
 
 int dpu_core_perf_debugfs_init(struct dpu_kms *dpu_kms, struct dentry *parent)
drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c +10 -10
index a1f5d7c4ab91..0c1484439229 100644
@@ -105,16 +105,15 @@ static int dpu_debugfs_safe_stats_show(struct seq_file *s, void *v)
 }
 DEFINE_SHOW_ATTRIBUTE(dpu_debugfs_safe_stats);
 
-static ssize_t _dpu_plane_danger_read(struct file *file,
-			char __user *buff, size_t count, loff_t *ppos)
+static ssize_t _dpu_plane_danger_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct dpu_kms *kms = file->private_data;
+	struct dpu_kms *kms = iocb->ki_filp->private_data;
 	int len;
 	char buf[40];
 
 	len = scnprintf(buf, sizeof(buf), "%d\n", !kms->has_danger_ctrl);
 
-	return simple_read_from_buffer(buff, count, ppos, buf, len);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 }
 
 static void _dpu_plane_set_danger_state(struct dpu_kms *kms, bool enable)
@@ -140,14 +139,15 @@ static void _dpu_plane_set_danger_state(struct dpu_kms *kms, bool enable)
 	}
 }
 
-static ssize_t _dpu_plane_danger_write(struct file *file,
-		    const char __user *user_buf, size_t count, loff_t *ppos)
+static ssize_t _dpu_plane_danger_write(struct kiocb *iocb,
+				       struct iov_iter *from)
 {
-	struct dpu_kms *kms = file->private_data;
+	struct dpu_kms *kms = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	int disable_panic;
 	int ret;
 
-	ret = kstrtouint_from_user(user_buf, count, 0, &disable_panic);
+	ret = kstrtouint_from_iter(from, count, 0, &disable_panic);
 	if (ret)
 		return ret;
 
@@ -168,8 +168,8 @@ static ssize_t _dpu_plane_danger_write(struct file *file,
 
 static const struct file_operations dpu_plane_danger_enable = {
 	.open = simple_open,
-	.read = _dpu_plane_danger_read,
-	.write = _dpu_plane_danger_write,
+	.read_iter = _dpu_plane_danger_read,
+	.write_iter = _dpu_plane_danger_write,
 };
 
 static void dpu_debugfs_danger_init(struct dpu_kms *dpu_kms,
drivers/gpu/drm/msm/dp/dp_debug.c +7 -8
index eca5a02f9003..7589f40309ff 100644
@@ -123,23 +123,22 @@ static int dp_test_type_show(struct seq_file *m, void *data)
 }
 DEFINE_SHOW_ATTRIBUTE(dp_test_type);
 
-static ssize_t dp_test_active_write(struct file *file,
-		const char __user *ubuf,
-		size_t len, loff_t *offp)
+static ssize_t dp_test_active_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	char *input_buffer;
 	int status = 0;
 	const struct dp_debug_private *debug;
 	const struct drm_connector *connector;
+	size_t len = iov_iter_count(from);
 	int val = 0;
 
-	debug = ((struct seq_file *)file->private_data)->private;
+	debug = ((struct seq_file *)iocb->ki_filp->private_data)->private;
 	connector = debug->connector;
 
 	if (len == 0)
 		return 0;
 
-	input_buffer = memdup_user_nul(ubuf, len);
+	input_buffer = iterdup_nul(from, len);
 	if (IS_ERR(input_buffer))
 		return PTR_ERR(input_buffer);
 
@@ -162,7 +161,7 @@ static ssize_t dp_test_active_write(struct file *file,
 	}
 	kfree(input_buffer);
 
-	*offp += len;
+	iocb->ki_pos += len;
 	return len;
 }
 
@@ -193,10 +192,10 @@ static int dp_test_active_open(struct inode *inode,
 static const struct file_operations test_active_fops = {
 	.owner = THIS_MODULE,
 	.open = dp_test_active_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = dp_test_active_write
+	.write_iter = dp_test_active_write,
 };
 
 static void dp_debug_init(struct dp_debug *dp_debug, struct dentry *root, bool is_edp)
drivers/gpu/drm/msm/msm_debugfs.c +2 -2
index 4494f6d1c7cb..237bb6dace46 100644
@@ -112,7 +112,7 @@ static int msm_gpu_open(struct inode *inode, struct file *file)
 static const struct file_operations msm_gpu_fops = {
 	.owner = THIS_MODULE,
 	.open = msm_gpu_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = msm_gpu_release,
 };
@@ -175,7 +175,7 @@ static int msm_kms_open(struct inode *inode, struct file *file)
 static const struct file_operations msm_kms_fops = {
 	.owner = THIS_MODULE,
 	.open = msm_kms_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = msm_kms_release,
 };
drivers/gpu/drm/msm/msm_perf.c +6 -6
index 3d3da79fec2a..494d714ce6a2 100644
@@ -117,10 +117,10 @@ static int refill_buf(struct msm_perf_state *perf)
 	return 0;
 }
 
-static ssize_t perf_read(struct file *file, char __user *buf,
-		size_t sz, loff_t *ppos)
+static ssize_t perf_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct msm_perf_state *perf = file->private_data;
+	struct msm_perf_state *perf = iocb->ki_filp->private_data;
+	size_t sz = iov_iter_count(to);
 	int n = 0, ret = 0;
 
 	mutex_lock(&perf->read_lock);
@@ -132,13 +132,13 @@ static ssize_t perf_read(struct file *file, char __user *buf,
 	}
 
 	n = min((int)sz, perf->buftot - perf->bufpos);
-	if (copy_to_user(buf, &perf->buf[perf->bufpos], n)) {
+	if (!copy_to_iter_full(&perf->buf[perf->bufpos], n, to)) {
 		ret = -EFAULT;
 		goto out;
 	}
 
 	perf->bufpos += n;
-	*ppos += n;
+	iocb->ki_pos += n;
 
 out:
 	mutex_unlock(&perf->read_lock);
@@ -191,7 +191,7 @@ static int perf_release(struct inode *inode, struct file *file)
 static const struct file_operations perf_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = perf_open,
-	.read = perf_read,
+	.read_iter = perf_read,
 	.llseek = no_llseek,
 	.release = perf_release,
 };
drivers/gpu/drm/msm/msm_rd.c +6 -6
index ca44fd291c5b..d5f65377ba65 100644
@@ -130,12 +130,12 @@ static void rd_write_section(struct msm_rd_state *rd,
 	rd_write(rd, buf, sz);
 }
 
-static ssize_t rd_read(struct file *file, char __user *buf,
-		size_t sz, loff_t *ppos)
+static ssize_t rd_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct msm_rd_state *rd = file->private_data;
+	struct msm_rd_state *rd = iocb->ki_filp->private_data;
 	struct circ_buf *fifo = &rd->fifo;
 	const char *fptr = &fifo->buf[fifo->tail];
+	size_t sz = iov_iter_count(to);
 	int n = 0, ret = 0;
 
 	mutex_lock(&rd->read_lock);
@@ -150,13 +150,13 @@ static ssize_t rd_read(struct file *file, char __user *buf,
 	 * once.
 	 */
 	n = min_t(int, sz, circ_count_to_end(&rd->fifo));
-	if (copy_to_user(buf, fptr, n)) {
+	if (!copy_to_iter_full(fptr, n, to)) {
 		ret = -EFAULT;
 		goto out;
 	}
 
 	smp_store_release(&fifo->tail, (fifo->tail + n) & (BUF_SZ - 1));
-	*ppos += n;
+	iocb->ki_pos += n;
 
 	wake_up_all(&rd->fifo_event);
 
@@ -226,7 +226,7 @@ static int rd_release(struct inode *inode, struct file *file)
 static const struct file_operations rd_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = rd_open,
-	.read = rd_read,
+	.read_iter = rd_read,
 	.llseek = no_llseek,
 	.release = rd_release,
 };
Signature · 1 line
2.43.0
author maintainer
#147 lore raw

PATCH 141/437 drm: nouveau: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/nouveau/dispnv50/crc.c    | 13 ++++++-------
 drivers/gpu/drm/nouveau/nouveau_debugfs.c | 12 ++++++------
 2 files changed, 12 insertions(+), 13 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/crc.c +6 -7
index 9c942fbd836d..a7859e3cb39d 100644
@@ -648,11 +648,9 @@ nv50_crc_debugfs_flip_threshold_open(struct inode *inode, struct file *file)
 }
 
 static ssize_t
-nv50_crc_debugfs_flip_threshold_set(struct file *file,
-				    const char __user *ubuf, size_t len,
-				    loff_t *offp)
+nv50_crc_debugfs_flip_threshold_set(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct nv50_head *head = m->private;
 	struct nv50_head_atom *armh;
 	struct drm_crtc *crtc = &head->base.base;
@@ -660,9 +658,10 @@ nv50_crc_debugfs_flip_threshold_set(struct file *file,
 	struct nv50_crc *crc = &head->crc;
 	const struct nv50_crc_func *func =
 		nv50_disp(crtc->dev)->core->func->crc;
+	size_t len = iov_iter_count(from);
 	int value, ret;
 
-	ret = kstrtoint_from_user(ubuf, len, 10, &value);
+	ret = kstrtoint_from_iter(from, len, 10, &value);
 	if (ret)
 		return ret;
 
@@ -697,8 +696,8 @@ nv50_crc_debugfs_flip_threshold_set(struct file *file,
 static const struct file_operations nv50_crc_flip_threshold_fops = {
 	.owner = THIS_MODULE,
 	.open = nv50_crc_debugfs_flip_threshold_open,
-	.read = seq_read,
-	.write = nv50_crc_debugfs_flip_threshold_set,
+	.read_iter = seq_read_iter,
+	.write_iter = nv50_crc_debugfs_flip_threshold_set,
 	.release = single_release,
 };
 
drivers/gpu/drm/nouveau/nouveau_debugfs.c +6 -6
index e83db051e851..02cfac6f6c39 100644
@@ -139,14 +139,14 @@ nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
 }
 
 static ssize_t
-nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
-			   size_t len, loff_t *offp)
+nouveau_debugfs_pstate_set(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_device *drm = m->private;
 	struct nouveau_debugfs *debugfs = nouveau_debugfs(drm);
 	struct nvif_control_pstate_user_v0 args = { .pwrsrc = -EINVAL };
 	char buf[32] = {}, *tmp, *cur = buf;
+	size_t len = iov_iter_count(from);
 	long value, ret;
 
 	if (!debugfs)
@@ -155,7 +155,7 @@ nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
 	if (len >= sizeof(buf))
 		return -EINVAL;
 
-	if (copy_from_user(buf, ubuf, len))
+	if (!copy_from_iter_full(buf, len, from))
 		return -EFAULT;
 
 	if ((tmp = strchr(buf, '\n')))
@@ -244,8 +244,8 @@ nouveau_debugfs_gpuva(struct seq_file *m, void *data)
 static const struct file_operations nouveau_pstate_fops = {
 	.owner = THIS_MODULE,
 	.open = nouveau_debugfs_pstate_open,
-	.read = seq_read,
-	.write = nouveau_debugfs_pstate_set,
+	.read_iter = seq_read_iter,
+	.write_iter = nouveau_debugfs_pstate_set,
 	.release = single_release,
 };
 
Signature · 1 line
2.43.0
author maintainer
#148 lore raw

PATCH 142/437 drm: mipi: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/drm_mipi_dbi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_mipi_dbi.c +7 -7
index daac649aabdb..43198c3b2eed 100644
@@ -1332,12 +1332,12 @@ EXPORT_SYMBOL(mipi_dbi_spi_transfer);
 
 #ifdef CONFIG_DEBUG_FS
 
-static ssize_t mipi_dbi_debugfs_command_write(struct file *file,
-					      const char __user *ubuf,
-					      size_t count, loff_t *ppos)
+static ssize_t mipi_dbi_debugfs_command_write(struct kiocb *iocb,
+					      struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct mipi_dbi_dev *dbidev = m->private;
+	size_t count = iov_iter_count(from);
 	u8 val, cmd = 0, parameters[64];
 	char *buf, *pos, *token;
 	int i, ret, idx;
@@ -1345,7 +1345,7 @@ static ssize_t mipi_dbi_debugfs_command_write(struct file *file,
 	if (!drm_dev_enter(&dbidev->drm, &idx))
 		return -ENODEV;
 
-	buf = memdup_user_nul(ubuf, count);
+	buf = iterdup_nul(from, count);
 	if (IS_ERR(buf)) {
 		ret = PTR_ERR(buf);
 		goto err_exit;
@@ -1446,10 +1446,10 @@ static int mipi_dbi_debugfs_command_open(struct inode *inode,
 static const struct file_operations mipi_dbi_debugfs_command_fops = {
 	.owner = THIS_MODULE,
 	.open = mipi_dbi_debugfs_command_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = mipi_dbi_debugfs_command_write,
+	.write_iter = mipi_dbi_debugfs_command_write,
 };
 
 /**
Signature · 1 line
2.43.0
author maintainer
#149 lore raw

PATCH 143/437 drm: mali: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/arm/malidp_drv.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +5 -6
index 6682131d2910..cc0490e3ae4c 100644
@@ -522,10 +522,9 @@ static int malidp_debugfs_open(struct inode *inode, struct file *file)
 	return single_open(file, malidp_show_stats, inode->i_private);
 }
 
-static ssize_t malidp_debugfs_write(struct file *file, const char __user *ubuf,
-				    size_t len, loff_t *offp)
+static ssize_t malidp_debugfs_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct drm_device *drm = m->private;
 	struct malidp_drm *malidp = drm_to_malidp(drm);
 	unsigned long irqflags;
@@ -534,14 +533,14 @@ static ssize_t malidp_debugfs_write(struct file *file, const char __user *ubuf,
 	malidp_error_stats_init(&malidp->de_errors);
 	malidp_error_stats_init(&malidp->se_errors);
 	spin_unlock_irqrestore(&malidp->errors_lock, irqflags);
-	return len;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations malidp_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = malidp_debugfs_open,
-	.read = seq_read,
-	.write = malidp_debugfs_write,
+	.read_iter = seq_read_iter,
+	.write_iter = malidp_debugfs_write,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#150 lore raw

PATCH 144/437 drm/bridge: it6505: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/bridge/ite-it6505.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/bridge/ite-it6505.c +6 -8
index 27334173e911..3f280f85d49d 100644
@@ -3208,14 +3208,14 @@ static void it6505_parse_dt(struct it6505 *it6505)
 			     it6505->max_dpi_pixel_clock);
 }
 
-static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf,
-					   size_t len, loff_t *ppos)
+static ssize_t receive_timing_debugfs_show(struct kiocb *iocb,
+					   struct iov_iter *to)
 {
-	struct it6505 *it6505 = file->private_data;
+	struct it6505 *it6505 = iocb->ki_filp->private_data;
 	struct drm_display_mode *vid;
 	u8 read_buf[READ_BUFFER_SIZE];
 	u8 *str = read_buf, *end = read_buf + READ_BUFFER_SIZE;
-	ssize_t ret, count;
+	ssize_t count;
 
 	if (!it6505)
 		return -ENODEV;
@@ -3243,9 +3243,7 @@ static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf,
 			 vid->vtotal - vid->vsync_end);
 
 	count = str - read_buf;
-	ret = simple_read_from_buffer(buf, len, ppos, read_buf, count);
-
-	return ret;
+	return simple_copy_to_iter(read_buf, &iocb->ki_pos, count, to);
 }
 
 static int force_power_on_off_debugfs_write(void *data, u64 value)
@@ -3307,7 +3305,7 @@ static int enable_drv_hold_debugfs_write(void *data, u64 drv_hold)
 static const struct file_operations receive_timing_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = receive_timing_debugfs_show,
+	.read_iter = receive_timing_debugfs_show,
 	.llseek = default_llseek,
 };
 
Signature · 1 line
2.43.0
author maintainer
#151 lore raw

PATCH 145/437 drm/imagination: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/imagination/pvr_fw_trace.c | 2 +-
 drivers/gpu/drm/imagination/pvr_params.c   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/imagination/pvr_fw_trace.c +1 -1
index 31199e45b72e..ff5827dd6390 100644
@@ -438,7 +438,7 @@ static int fw_trace_release(struct inode *inode, struct file *file)
 static const struct file_operations pvr_fw_trace_fops = {
 	.owner = THIS_MODULE,
 	.open = fw_trace_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = fw_trace_release,
 };
drivers/gpu/drm/imagination/pvr_params.c +2 -2
index b91759f362c5..4fe0105ca0c9 100644
@@ -119,8 +119,8 @@ static struct {
 		.owner = THIS_MODULE,                      \
 		.open = __pvr_device_param_##name_##_open, \
 		.release = simple_attr_release,            \
-		.read = simple_attr_read,                  \
-		.write = simple_attr_write,                \
+		.read_iter = simple_attr_read_iter,        \
+		.write_iter = simple_attr_write_iter,      \
 		.llseek = generic_file_llseek,             \
 	},
 	PVR_DEVICE_PARAMS
Signature · 1 line
2.43.0
author maintainer
#152 lore raw

PATCH 146/437 drm/loongson: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/loongson/lsdc_crtc.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/loongson/lsdc_crtc.c +6 -8
index 827acab580fa..fde7c8d6cc3d 100644
@@ -628,20 +628,18 @@ static int lsdc_crtc_man_op_open(struct inode *inode, struct file *file)
 	return single_open(file, lsdc_crtc_man_op_show, crtc);
 }
 
-static ssize_t lsdc_crtc_man_op_write(struct file *file,
-				      const char __user *ubuf,
-				      size_t len,
-				      loff_t *offp)
+static ssize_t lsdc_crtc_man_op_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct lsdc_crtc *lcrtc = m->private;
 	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+	size_t len = iov_iter_count(from);
 	char buf[16];
 
 	if (len > sizeof(buf) - 1)
 		return -EINVAL;
 
-	if (copy_from_user(buf, ubuf, len))
+	if (!copy_from_iter_full(buf, len, from))
 		return -EFAULT;
 
 	buf[len] = '\0';
@@ -663,10 +661,10 @@ static ssize_t lsdc_crtc_man_op_write(struct file *file,
 static const struct file_operations lsdc_crtc_man_op_fops = {
 	.owner = THIS_MODULE,
 	.open = lsdc_crtc_man_op_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
-	.write = lsdc_crtc_man_op_write,
+	.write_iter = lsdc_crtc_man_op_write,
 };
 
 static int lsdc_crtc_late_register(struct drm_crtc *crtc)
Signature · 1 line
2.43.0
author maintainer
#153 lore raw

PATCH 147/437 drm/radeon/radeon_ttm: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 40 ++++++++++++++---------------
 1 file changed, 19 insertions(+), 21 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +19 -21
index 2078b0000e22..2570babc690c 100644
@@ -786,37 +786,36 @@ static int radeon_ttm_vram_open(struct inode *inode, struct file *filep)
 	return 0;
 }
 
-static ssize_t radeon_ttm_vram_read(struct file *f, char __user *buf,
-				    size_t size, loff_t *pos)
+static ssize_t radeon_ttm_vram_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct radeon_device *rdev = f->private_data;
+	struct radeon_device *rdev = iocb->ki_filp->private_data;
+	size_t size = iov_iter_count(to);
 	ssize_t result = 0;
 	int r;
 
-	if (size & 0x3 || *pos & 0x3)
+	if (size & 0x3 || iocb->ki_pos & 0x3)
 		return -EINVAL;
 
 	while (size) {
 		unsigned long flags;
 		uint32_t value;
 
-		if (*pos >= rdev->mc.mc_vram_size)
+		if (iocb->ki_pos >= rdev->mc.mc_vram_size)
 			return result;
 
 		spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
-		WREG32(RADEON_MM_INDEX, ((uint32_t)*pos) | 0x80000000);
+		WREG32(RADEON_MM_INDEX, ((uint32_t)iocb->ki_pos) | 0x80000000);
 		if (rdev->family >= CHIP_CEDAR)
-			WREG32(EVERGREEN_MM_INDEX_HI, *pos >> 31);
+			WREG32(EVERGREEN_MM_INDEX_HI, iocb->ki_pos >> 31);
 		value = RREG32(RADEON_MM_DATA);
 		spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
 
-		r = put_user(value, (uint32_t __user *)buf);
+		r = put_iter(value, to);
 		if (r)
 			return r;
 
 		result += 4;
-		buf += 4;
-		*pos += 4;
+		iocb->ki_pos += 4;
 		size -= 4;
 	}
 
@@ -826,7 +825,7 @@ static ssize_t radeon_ttm_vram_read(struct file *f, char __user *buf,
 static const struct file_operations radeon_ttm_vram_fops = {
 	.owner = THIS_MODULE,
 	.open = radeon_ttm_vram_open,
-	.read = radeon_ttm_vram_read,
+	.read_iter = radeon_ttm_vram_read,
 	.llseek = default_llseek
 };
 
@@ -838,16 +837,16 @@ static int radeon_ttm_gtt_open(struct inode *inode, struct file *filep)
 	return 0;
 }
 
-static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
-				   size_t size, loff_t *pos)
+static ssize_t radeon_ttm_gtt_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct radeon_device *rdev = f->private_data;
+	struct radeon_device *rdev = iocb->ki_filp->private_data;
+	size_t size = iov_iter_count(to);
 	ssize_t result = 0;
 	int r;
 
 	while (size) {
-		loff_t p = *pos / PAGE_SIZE;
-		unsigned off = *pos & ~PAGE_MASK;
+		loff_t p = iocb->ki_pos / PAGE_SIZE;
+		unsigned off = iocb->ki_pos & ~PAGE_MASK;
 		size_t cur_size = min_t(size_t, size, PAGE_SIZE - off);
 		struct page *page;
 		void *ptr;
@@ -860,17 +859,16 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
 			ptr = kmap_local_page(page);
 			ptr += off;
 
-			r = copy_to_user(buf, ptr, cur_size);
+			r = !copy_to_iter_full(ptr, cur_size, to);
 			kunmap_local(ptr);
 		} else
-			r = clear_user(buf, cur_size);
+			r = iov_iter_zero(cur_size, to) != cur_size;
 
 		if (r)
 			return -EFAULT;
 
 		result += cur_size;
-		buf += cur_size;
-		*pos += cur_size;
+		iocb->ki_pos += cur_size;
 		size -= cur_size;
 	}
 
@@ -880,7 +878,7 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
 static const struct file_operations radeon_ttm_gtt_fops = {
 	.owner = THIS_MODULE,
 	.open = radeon_ttm_gtt_open,
-	.read = radeon_ttm_gtt_read,
+	.read_iter = radeon_ttm_gtt_read,
 	.llseek = default_llseek
 };
 
Signature · 1 line
2.43.0
author maintainer
#154 lore raw

PATCH 148/437 drm: armada: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/armada/armada_debugfs.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/armada/armada_debugfs.c +7 -6
index 29f4b52e3c8d..eaa0384a3bd4 100644
@@ -48,22 +48,23 @@ static int armada_debugfs_crtc_reg_open(struct inode *inode, struct file *file)
 			   inode->i_private);
 }
 
-static int armada_debugfs_crtc_reg_write(struct file *file,
-	const char __user *ptr, size_t len, loff_t *off)
+static int armada_debugfs_crtc_reg_write(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
+	size_t len = iov_iter_count(from);
 	struct armada_crtc *dcrtc;
 	unsigned long reg, mask, val;
 	char buf[32];
 	int ret;
 	u32 v;
 
-	if (*off != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (len > sizeof(buf) - 1)
 		len = sizeof(buf) - 1;
 
-	ret = strncpy_from_user(buf, ptr, len);
+	ret = strncpy_from_iter(from, ptr, len);
 	if (ret < 0)
 		return ret;
 	buf[len] = '\0';
@@ -85,8 +86,8 @@ static int armada_debugfs_crtc_reg_write(struct file *file,
 static const struct file_operations armada_debugfs_crtc_reg_fops = {
 	.owner = THIS_MODULE,
 	.open = armada_debugfs_crtc_reg_open,
-	.read = seq_read,
-	.write = armada_debugfs_crtc_reg_write,
+	.read_iter = seq_read_iter,
+	.write_iter = armada_debugfs_crtc_reg_write,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#155 lore raw

PATCH 149/437 drm: omap: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/drm/omapdrm/dss/dss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/dss/dss.c +1 -1
index 988888e164d7..2f0a3cda2c6c 100644
@@ -916,7 +916,7 @@ static int dss_debug_open(struct inode *inode, struct file *file)
 
 static const struct file_operations dss_debug_fops = {
 	.open		= dss_debug_open,
-	.read		= seq_read,
+	.read_iter	= seq_read,
 	.llseek		= seq_lseek,
 	.release	= single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#156 lore raw

PATCH 150/437 vga_switcheroo: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/gpu/vga/vga_switcheroo.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/vga/vga_switcheroo.c +5 -5
index 365e6ddbe90f..b7afc48ab39c 100644
@@ -772,8 +772,7 @@ static bool check_can_switch(void)
 }
 
 static ssize_t
-vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
-			     size_t cnt, loff_t *ppos)
+vga_switcheroo_debugfs_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	char usercmd[64];
 	int ret;
@@ -781,11 +780,12 @@ vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
 	bool just_mux = false;
 	enum vga_switcheroo_client_id client_id = VGA_SWITCHEROO_UNKNOWN_ID;
 	struct vga_switcheroo_client *client = NULL;
+	size_t cnt = iov_iter_count(from);
 
 	if (cnt > 63)
 		cnt = 63;
 
-	if (copy_from_user(usercmd, ubuf, cnt))
+	if (!copy_from_iter_full(usercmd, cnt, from))
 		return -EFAULT;
 
 	mutex_lock(&vgasr_mutex);
@@ -899,8 +899,8 @@ vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
 static const struct file_operations vga_switcheroo_debugfs_fops = {
 	.owner = THIS_MODULE,
 	.open = vga_switcheroo_debugfs_open,
-	.write = vga_switcheroo_debugfs_write,
-	.read = seq_read,
+	.write_iter = vga_switcheroo_debugfs_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#157 lore raw

PATCH 151/437 drivers/clk: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/clk/clk.c                              | 11 +++++------
 drivers/clk/starfive/clk-starfive-jh7110-pll.c |  2 +-
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/clk/clk.c +5 -6
index 25371c91a58f..5a6371a9cad8 100644
@@ -3539,16 +3539,15 @@ static int current_parent_show(struct seq_file *s, void *data)
 DEFINE_SHOW_ATTRIBUTE(current_parent);
 
 #ifdef CLOCK_ALLOW_WRITE_DEBUGFS
-static ssize_t current_parent_write(struct file *file, const char __user *ubuf,
-				    size_t count, loff_t *ppos)
+static ssize_t current_parent_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *s = file->private_data;
+	struct seq_file *s = iocb->ki_filp->private_data;
 	struct clk_core *core = s->private;
 	struct clk_core *parent;
 	u8 idx;
 	int err;
 
-	err = kstrtou8_from_user(ubuf, count, 0, &idx);
+	err = kstrtou8_from_iter(from, count, 0, &idx);
 	if (err < 0)
 		return err;
 
@@ -3567,8 +3566,8 @@ static ssize_t current_parent_write(struct file *file, const char __user *ubuf,
 
 static const struct file_operations current_parent_rw_fops = {
 	.open		= current_parent_open,
-	.write		= current_parent_write,
-	.read		= seq_read,
+	.write_iter	= current_parent_write,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= single_release,
 };
drivers/clk/starfive/clk-starfive-jh7110-pll.c +1 -1
index 3598390e8fd0..1b00fdc92b17 100644
@@ -420,7 +420,7 @@ static const struct file_operations jh7110_pll_registers_ops = {
 	.owner = THIS_MODULE,
 	.open = jh7110_pll_registers_open,
 	.release = single_release,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek
 };
 
Signature · 1 line
2.43.0
author maintainer
#158 lore raw

PATCH 152/437 drivers/rtc: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/rtc/dev.c        | 20 ++++++++------------
 drivers/rtc/rtc-m41t80.c | 18 +++++++-----------
 2 files changed, 15 insertions(+), 23 deletions(-)
drivers/rtc/dev.c +8 -12
index 4aad9bb99868..b37e6d448ee4 100644
@@ -138,10 +138,10 @@ EXPORT_SYMBOL(rtc_dev_update_irq_enable_emul);
 
 #endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */
 
-static ssize_t
-rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t rtc_dev_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct rtc_device *rtc = file->private_data;
+	struct rtc_device *rtc = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 
 	DECLARE_WAITQUEUE(wait, current);
 	unsigned long data;
@@ -163,7 +163,7 @@ rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 			ret = 0;
 			break;
 		}
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			ret = -EAGAIN;
 			break;
 		}
@@ -177,13 +177,9 @@ rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 	remove_wait_queue(&rtc->irq_queue, &wait);
 
 	if (ret == 0) {
-		if (sizeof(int) != sizeof(long) &&
-		    count == sizeof(unsigned int))
-			ret = put_user(data, (unsigned int __user *)buf) ?:
-				sizeof(unsigned int);
-		else
-			ret = put_user(data, (unsigned long __user *)buf) ?:
-				sizeof(unsigned long);
+		ret = sizeof(data);
+		if (put_iter(data, to))
+			ret = -EFAULT;
 	}
 	return ret;
 }
@@ -524,7 +520,7 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
 static const struct file_operations rtc_dev_fops = {
 	.owner		= THIS_MODULE,
 	.llseek		= no_llseek,
-	.read		= rtc_dev_read,
+	.read_iter	= rtc_dev_read,
 	.poll		= rtc_dev_poll,
 	.unlocked_ioctl	= rtc_dev_ioctl,
 #ifdef CONFIG_COMPAT
drivers/rtc/rtc-m41t80.c +7 -11
index 0013bff0447d..2487aafd9698 100644
@@ -686,26 +686,22 @@ static void wdt_disable(void)
 
 /**
  *	wdt_write - write to watchdog.
- *	@file: file handle to the watchdog
- *	@buf: buffer to write (unused as data does not matter here
- *	@count: count of bytes
- *	@ppos: pointer to the position to write. No seeks allowed
+ *	@iocb: metadata for IO
+ *	@from: buffer to write (unused as data does not matter here
  *
  *	A write to a watchdog device is defined as a keepalive signal. Any
  *	write of data will do, as we don't define content meaning.
  */
-static ssize_t wdt_write(struct file *file, const char __user *buf,
-			 size_t count, loff_t *ppos)
+static ssize_t wdt_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	if (count) {
+	if (iov_iter_count(from)) {
 		wdt_ping();
 		return 1;
 	}
 	return 0;
 }
 
-static ssize_t wdt_read(struct file *file, char __user *buf,
-			size_t count, loff_t *ppos)
+static ssize_t wdt_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	return 0;
 }
@@ -844,10 +840,10 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
 
 static const struct file_operations wdt_fops = {
 	.owner	= THIS_MODULE,
-	.read	= wdt_read,
+	.read_iter	= wdt_read,
 	.unlocked_ioctl = wdt_unlocked_ioctl,
 	.compat_ioctl = compat_ptr_ioctl,
-	.write	= wdt_write,
+	.write_iter	= wdt_write,
 	.open	= wdt_open,
 	.release = wdt_release,
 	.llseek = no_llseek,
Signature · 1 line
2.43.0
author maintainer
#159 lore raw

PATCH 153/437 drivers/dma: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/dma/xilinx/xilinx_dpdma.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dpdma.c +8 -7
index b82815e64d24..8a443cd0cd44 100644
@@ -354,14 +354,14 @@ static struct xilinx_dpdma_debugfs_request dpdma_debugfs_reqs[] = {
 	},
 };
 
-static ssize_t xilinx_dpdma_debugfs_read(struct file *f, char __user *buf,
-					 size_t size, loff_t *pos)
+static ssize_t xilinx_dpdma_debugfs_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	enum xilinx_dpdma_testcases testcase;
+	size_t size = iov_iter_count(to);
 	char *kern_buff;
 	int ret = 0;
 
-	if (*pos != 0 || size <= 0)
+	if (iocb->ki_pos != 0 || size <= 0)
 		return -EINVAL;
 
 	kern_buff = kzalloc(XILINX_DPDMA_DEBUGFS_READ_MAX_SIZE, GFP_KERNEL);
@@ -381,7 +381,7 @@ static ssize_t xilinx_dpdma_debugfs_read(struct file *f, char __user *buf,
 	}
 
 	size = min(size, strlen(kern_buff));
-	if (copy_to_user(buf, kern_buff, size))
+	if (!copy_to_iter_full(kern_buff, size, to))
 		ret = -EFAULT;
 
 done:
@@ -389,7 +389,7 @@ static ssize_t xilinx_dpdma_debugfs_read(struct file *f, char __user *buf,
 	if (ret)
 		return ret;
 
-	*pos = size + 1;
+	iocb->ki_pos = size + 1;
 	return size;
 }
 
@@ -441,11 +441,12 @@ static ssize_t xilinx_dpdma_debugfs_write(struct file *f,
 	kfree(kern_buff_start);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(xilinx_dpdma_debugfs_write);
 
 static const struct file_operations fops_xilinx_dpdma_dbgfs = {
 	.owner = THIS_MODULE,
-	.read = xilinx_dpdma_debugfs_read,
-	.write = xilinx_dpdma_debugfs_write,
+	.read_iter = xilinx_dpdma_debugfs_read,
+	.write_iter = xilinx_dpdma_debugfs_write_iter,
 };
 
 static void xilinx_dpdma_debugfs_init(struct xilinx_dpdma_device *xdev)
Signature · 1 line
2.43.0
author maintainer
#160 lore raw

PATCH 154/437 fs/debugfs: convert to read/write iterators

In reply to Jens Axboe
---
 fs/debugfs/file.c | 54 +++++++++++++++++------------------------------
 1 file changed, 19 insertions(+), 35 deletions(-)
fs/debugfs/file.c +19 -35
index 31749d8c35f8..6463b4a274d4 100644
@@ -318,15 +318,13 @@ FULL_PROXY_FUNC(llseek, loff_t, filp,
 		PROTO(struct file *filp, loff_t offset, int whence),
 		ARGS(filp, offset, whence));
 
-FULL_PROXY_FUNC(read, ssize_t, filp,
-		PROTO(struct file *filp, char __user *buf, size_t size,
-			loff_t *ppos),
-		ARGS(filp, buf, size, ppos));
+FULL_PROXY_FUNC(read_iter, ssize_t, iocb->ki_filp,
+		PROTO(struct kiocb *iocb, struct iov_iter *to),
+		ARGS(iocb, to));
 
-FULL_PROXY_FUNC(write, ssize_t, filp,
-		PROTO(struct file *filp, const char __user *buf, size_t size,
-			loff_t *ppos),
-		ARGS(filp, buf, size, ppos));
+FULL_PROXY_FUNC(write_iter, ssize_t, iocb->ki_filp,
+		PROTO(struct kiocb *iocb, struct iov_iter *from),
+		ARGS(iocb, from));
 
 FULL_PROXY_FUNC(unlocked_ioctl, long, filp,
 		PROTO(struct file *filp, unsigned int cmd, unsigned long arg),
@@ -376,10 +374,10 @@ static void __full_proxy_fops_init(struct file_operations *proxy_fops,
 	proxy_fops->release = full_proxy_release;
 	if (real_fops->llseek)
 		proxy_fops->llseek = full_proxy_llseek;
-	if (real_fops->read)
-		proxy_fops->read = full_proxy_read;
-	if (real_fops->write)
-		proxy_fops->write = full_proxy_write;
+	if (real_fops->read_iter)
+		proxy_fops->read_iter = full_proxy_read_iter;
+	if (real_fops->write_iter)
+		proxy_fops->write_iter = full_proxy_write_iter;
 	if (real_fops->poll)
 		proxy_fops->poll = full_proxy_poll;
 	if (real_fops->unlocked_ioctl)
@@ -914,19 +912,17 @@ void debugfs_create_atomic_t(const char *name, umode_t mode,
 }
 EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);
 
-static ssize_t __debugfs_read_file_bool(struct file *file,
-					char __user *user_buf, size_t count,
-					loff_t *ppos)
+ssize_t debugfs_read_file_bool(struct kiocb *iocb, struct iov_iter *to)
 {
 	char buf[2];
 	bool val;
 	int r;
-	struct dentry *dentry = F_DENTRY(file);
+	struct dentry *dentry = F_DENTRY(iocb->ki_filp);
 
 	r = debugfs_file_get(dentry);
 	if (unlikely(r))
 		return r;
-	val = *(bool *)file->private_data;
+	val = *(bool *)iocb->ki_filp->private_data;
 	debugfs_file_put(dentry);
 
 	if (val)
@@ -934,25 +930,19 @@ static ssize_t __debugfs_read_file_bool(struct file *file,
 	else
 		buf[0] = 'N';
 	buf[1] = '\n';
-	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
-}
-
-ssize_t debugfs_read_file_bool(struct kiocb *iocb, struct iov_iter *to)
-{
-	return vfs_read_iter(iocb, to, __debugfs_read_file_bool);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, 2, to);
 }
 EXPORT_SYMBOL_GPL(debugfs_read_file_bool);
 
-static ssize_t __debugfs_write_file_bool(struct file *file,
-					 const char __user *user_buf,
-					 size_t count, loff_t *ppos)
+ssize_t debugfs_write_file_bool(struct kiocb *iocb, struct iov_iter *from)
 {
 	bool bv;
 	int r;
-	bool *val = file->private_data;
-	struct dentry *dentry = F_DENTRY(file);
+	bool *val = iocb->ki_filp->private_data;
+	struct dentry *dentry = F_DENTRY(iocb->ki_filp);
+	size_t count = iov_iter_count(from);
 
-	r = kstrtobool_from_user(user_buf, count, &bv);
+	r = kstrtobool_from_iter(from, count, &bv);
 	if (!r) {
 		r = debugfs_file_get(dentry);
 		if (unlikely(r))
@@ -964,12 +954,6 @@ static ssize_t __debugfs_write_file_bool(struct file *file,
 	return count;
 }
 
-ssize_t debugfs_write_file_bool(struct kiocb *iocb, struct iov_iter *from)
-{
-	return vfs_write_iter(iocb, from, __debugfs_write_file_bool);
-}
-EXPORT_SYMBOL_GPL(debugfs_write_file_bool);
-
 static const struct file_operations fops_bool = {
 	.read_iter =	debugfs_read_file_bool,
 	.write_iter =	debugfs_write_file_bool,
Signature · 1 line
2.43.0
author maintainer
#161 lore raw

PATCH 155/437 HID: usbhid: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/hid/usbhid/hiddev.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/hid/usbhid/hiddev.c +9 -8
index 59cf3ddfdf78..19b3e663cf3d 100644
@@ -308,7 +308,7 @@ static int hiddev_open(struct inode *inode, struct file *file)
 /*
  * "write" file op
  */
-static ssize_t hiddev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
+static ssize_t hiddev_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	return -EINVAL;
 }
@@ -316,10 +316,11 @@ static ssize_t hiddev_write(struct file * file, const char __user * buffer, size
 /*
  * "read" file op
  */
-static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
+static ssize_t hiddev_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	DEFINE_WAIT(wait);
-	struct hiddev_list *list = file->private_data;
+	struct hiddev_list *list = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	int event_size;
 	int retval;
 
@@ -347,7 +348,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
 					retval = -EIO;
 					break;
 				}
-				if (file->f_flags & O_NONBLOCK) {
+				if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 					retval = -EAGAIN;
 					break;
 				}
@@ -379,7 +380,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
 
 					event.hid = list->buffer[list->tail].usage_code;
 					event.value = list->buffer[list->tail].value;
-					if (copy_to_user(buffer + retval, &event, sizeof(struct hiddev_event))) {
+					if (!copy_to_iter_full(&event, sizeof(struct hiddev_event), to)) {
 						mutex_unlock(&list->thread_lock);
 						return -EFAULT;
 					}
@@ -389,7 +390,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
 				if (list->buffer[list->tail].field_index != HID_FIELD_INDEX_NONE ||
 				    (list->flags & HIDDEV_FLAG_REPORT) != 0) {
 
-					if (copy_to_user(buffer + retval, list->buffer + list->tail, sizeof(struct hiddev_usage_ref))) {
+					if (!copy_to_iter_full(list->buffer + list->tail, sizeof(struct hiddev_usage_ref), to)) {
 						mutex_unlock(&list->thread_lock);
 						return -EFAULT;
 					}
@@ -846,8 +847,8 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 static const struct file_operations hiddev_fops = {
 	.owner =	THIS_MODULE,
-	.read =		hiddev_read,
-	.write =	hiddev_write,
+	.read_iter =	hiddev_read,
+	.write_iter =	hiddev_write,
 	.poll =		hiddev_poll,
 	.open =		hiddev_open,
 	.release =	hiddev_release,
Signature · 1 line
2.43.0
author maintainer
#162 lore raw

PATCH 156/437 usb: chipidea: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/chipidea/debug.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/usb/chipidea/debug.c +7 -6
index e72c43615d77..fa080c6dabf3 100644
@@ -6,6 +6,7 @@
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
 #include <linux/uaccess.h>
+#include <linux/uio.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/phy.h>
@@ -70,10 +71,10 @@ static int ci_port_test_show(struct seq_file *s, void *data)
 /*
  * ci_port_test_write: writes port test mode
  */
-static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf,
-				  size_t count, loff_t *ppos)
+static ssize_t ci_port_test_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *s = file->private_data;
+	struct seq_file *s = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct ci_hdrc *ci = s->private;
 	unsigned long flags;
 	unsigned mode;
@@ -81,7 +82,7 @@ static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf,
 	int ret;
 
 	count = min_t(size_t, sizeof(buf) - 1, count);
-	if (copy_from_user(buf, ubuf, count))
+	if (!copy_from_iter_full(buf, count, from))
 		return -EFAULT;
 
 	/* sscanf requires a zero terminated string */
@@ -109,8 +110,8 @@ static int ci_port_test_open(struct inode *inode, struct file *file)
 
 static const struct file_operations ci_port_test_fops = {
 	.open		= ci_port_test_open,
-	.write		= ci_port_test_write,
-	.read		= seq_read,
+	.write_iter	= ci_port_test_write,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#163 lore raw

PATCH 157/437 usb: class: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/class/cdc-wdm.c | 18 +++++++++---------
 drivers/usb/class/usblp.c   |  6 ++++--
 drivers/usb/class/usbtmc.c  |  6 ++++--
 3 files changed, 17 insertions(+), 13 deletions(-)
drivers/usb/class/cdc-wdm.c +9 -9
index c8262e2f2917..a811000b5eb2 100644
@@ -476,6 +476,7 @@ static ssize_t wdm_write
 	kfree(buf);
 	return rv;
 }
+FOPS_WRITE_ITER_HELPER(wdm_write);
 
 /*
  * Submit the read urb if resp_count is non-zero.
@@ -520,13 +521,12 @@ static int service_outstanding_interrupt(struct wdm_device *desc)
 	return rv;
 }
 
-static ssize_t wdm_read
-(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t wdm_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	int rv, cntr;
 	int i = 0;
-	struct wdm_device *desc = file->private_data;
-
+	struct wdm_device *desc = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 
 	rv = mutex_lock_interruptible(&desc->rlock); /*concurrent reads */
 	if (rv < 0)
@@ -546,7 +546,7 @@ static ssize_t wdm_read
 			goto err;
 		}
 		i++;
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			if (!test_bit(WDM_READ, &desc->flags)) {
 				rv = -EAGAIN;
 				goto err;
@@ -604,8 +604,8 @@ static ssize_t wdm_read
 
 	if (cntr > count)
 		cntr = count;
-	rv = copy_to_user(buffer, desc->ubuf, cntr);
-	if (rv > 0) {
+	rv = !copy_to_iter_full(desc->ubuf, cntr, to);
+	if (rv) {
 		rv = -EFAULT;
 		goto err;
 	}
@@ -810,8 +810,8 @@ static long wdm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 static const struct file_operations wdm_fops = {
 	.owner =	THIS_MODULE,
-	.read =		wdm_read,
-	.write =	wdm_write,
+	.read_iter =	wdm_read,
+	.write_iter =	wdm_write_iter,
 	.fsync =	wdm_fsync,
 	.open =		wdm_open,
 	.flush =	wdm_flush,
drivers/usb/class/usblp.c +4 -2
index 5a2e43331064..2f16b7916963 100644
@@ -832,6 +832,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
 raise_biglock:
 	return writecount ? writecount : rv;
 }
+FOPS_WRITE_ITER_HELPER(usblp_write);
 
 /*
  * Notice that we fail to restart in a few cases: on EFAULT, on restart
@@ -885,6 +886,7 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
 	mutex_unlock(&usblp->mut);
 	return count;
 }
+FOPS_READ_ITER_HELPER(usblp_read);
 
 /*
  * Wait for the write path to come idle.
@@ -1080,8 +1082,8 @@ static unsigned int usblp_quirks(__u16 vendor, __u16 product)
 
 static const struct file_operations usblp_fops = {
 	.owner =	THIS_MODULE,
-	.read =		usblp_read,
-	.write =	usblp_write,
+	.read_iter =	usblp_read_iter,
+	.write_iter =	usblp_write_iter,
 	.poll =		usblp_poll,
 	.unlocked_ioctl =	usblp_ioctl,
 	.compat_ioctl =		usblp_ioctl,
drivers/usb/class/usbtmc.c +4 -2
index 311007b1d904..281eeb29cf7f 100644
@@ -1506,6 +1506,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
 	kfree(buffer);
 	return retval;
 }
+FOPS_READ_ITER_HELPER(usbtmc_read);
 
 static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
 			    size_t count, loff_t *f_pos)
@@ -1644,6 +1645,7 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
 	mutex_unlock(&data->io_mutex);
 	return retval;
 }
+FOPS_WRITE_ITER_HELPER(usbtmc_write);
 
 static int usbtmc_ioctl_clear(struct usbtmc_device_data *data)
 {
@@ -2261,8 +2263,8 @@ static __poll_t usbtmc_poll(struct file *file, poll_table *wait)
 
 static const struct file_operations fops = {
 	.owner		= THIS_MODULE,
-	.read		= usbtmc_read,
-	.write		= usbtmc_write,
+	.read_iter	= usbtmc_read_iter,
+	.write_iter	= usbtmc_write_iter,
 	.open		= usbtmc_open,
 	.release	= usbtmc_release,
 	.flush		= usbtmc_flush,
Signature · 1 line
2.43.0
author maintainer
#164 lore raw

PATCH 158/437 usb: core: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/core/devices.c | 3 ++-
 drivers/usb/core/devio.c   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/usb/core/devices.c +2 -1
index a247da73f34d..f367132a6770 100644
@@ -538,8 +538,9 @@ static ssize_t usb_device_read(struct file *file, char __user *buf,
 	mutex_unlock(&usb_bus_idr_lock);
 	return total_written;
 }
+FOPS_READ_ITER_HELPER(usb_device_read);
 
 const struct file_operations usbfs_devices_fops = {
 	.llseek =	no_seek_end_llseek,
-	.read =		usb_device_read,
+	.read_iter =	usb_device_read_iter,
 };
drivers/usb/core/devio.c +2 -1
index 3beb6a862e80..bebfbebc1f69 100644
@@ -390,6 +390,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
 	usb_unlock_device(dev);
 	return ret;
 }
+FOPS_READ_ITER_HELPER(usbdev_read);
 
 /*
  * async list handling
@@ -2846,7 +2847,7 @@ static __poll_t usbdev_poll(struct file *file,
 const struct file_operations usbdev_file_operations = {
 	.owner =	  THIS_MODULE,
 	.llseek =	  no_seek_end_llseek,
-	.read =		  usbdev_read,
+	.read_iter =	  usbdev_read_iter,
 	.poll =		  usbdev_poll,
 	.unlocked_ioctl = usbdev_ioctl,
 	.compat_ioctl =   compat_ptr_ioctl,
Signature · 1 line
2.43.0
author maintainer
#165 lore raw

PATCH 159/437 usb: dwc2: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/dwc2/debugfs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/dwc2/debugfs.c +6 -6
index 1d72ece9cfe4..b106744e13b5 100644
@@ -24,16 +24,16 @@
  * @count: The ubuf size.
  * @ppos: Unused parameter.
  */
-static ssize_t testmode_write(struct file *file, const char __user *ubuf, size_t
-		count, loff_t *ppos)
+static ssize_t testmode_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file		*s = file->private_data;
+	struct seq_file		*s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct dwc2_hsotg	*hsotg = s->private;
 	unsigned long		flags;
 	u32			testmode = 0;
 	char			buf[32];
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (!strncmp(buf, "test_j", 6))
@@ -108,8 +108,8 @@ static int testmode_open(struct inode *inode, struct file *file)
 static const struct file_operations testmode_fops = {
 	.owner		= THIS_MODULE,
 	.open		= testmode_open,
-	.write		= testmode_write,
-	.read		= seq_read,
+	.write_iter	= testmode_write,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#166 lore raw

PATCH 160/437 usb: dwc3: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/dwc3/debugfs.c | 48 +++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/usb/dwc3/debugfs.c +24 -24
index ebf03468fac4..5af745ef00a0 100644
@@ -365,17 +365,17 @@ static int dwc3_lsp_open(struct inode *inode, struct file *file)
 	return single_open(file, dwc3_lsp_show, inode->i_private);
 }
 
-static ssize_t dwc3_lsp_write(struct file *file, const char __user *ubuf,
-			      size_t count, loff_t *ppos)
+static ssize_t dwc3_lsp_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file		*s = file->private_data;
+	struct seq_file		*s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct dwc3		*dwc = s->private;
 	unsigned long		flags;
 	char			buf[32] = { 0 };
 	u32			sel;
 	int			ret;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	ret = kstrtouint(buf, 0, &sel);
@@ -391,8 +391,8 @@ static ssize_t dwc3_lsp_write(struct file *file, const char __user *ubuf,
 
 static const struct file_operations dwc3_lsp_fops = {
 	.open			= dwc3_lsp_open,
-	.write			= dwc3_lsp_write,
-	.read			= seq_read,
+	.write_iter		= dwc3_lsp_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
@@ -436,15 +436,15 @@ static int dwc3_mode_open(struct inode *inode, struct file *file)
 	return single_open(file, dwc3_mode_show, inode->i_private);
 }
 
-static ssize_t dwc3_mode_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
+static ssize_t dwc3_mode_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file		*s = file->private_data;
+	struct seq_file		*s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct dwc3		*dwc = s->private;
 	u32			mode = 0;
 	char			buf[32];
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (dwc->dr_mode != USB_DR_MODE_OTG)
@@ -466,8 +466,8 @@ static ssize_t dwc3_mode_write(struct file *file,
 
 static const struct file_operations dwc3_mode_fops = {
 	.open			= dwc3_mode_open,
-	.write			= dwc3_mode_write,
-	.read			= seq_read,
+	.write_iter		= dwc3_mode_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
@@ -522,17 +522,17 @@ static int dwc3_testmode_open(struct inode *inode, struct file *file)
 	return single_open(file, dwc3_testmode_show, inode->i_private);
 }
 
-static ssize_t dwc3_testmode_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
+static ssize_t dwc3_testmode_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file		*s = file->private_data;
+	struct seq_file		*s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct dwc3		*dwc = s->private;
 	unsigned long		flags;
 	u32			testmode = 0;
 	char			buf[32];
 	int			ret;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (!strncmp(buf, "test_j", 6))
@@ -563,8 +563,8 @@ static ssize_t dwc3_testmode_write(struct file *file,
 
 static const struct file_operations dwc3_testmode_fops = {
 	.open			= dwc3_testmode_open,
-	.write			= dwc3_testmode_write,
-	.read			= seq_read,
+	.write_iter		= dwc3_testmode_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
@@ -610,10 +610,10 @@ static int dwc3_link_state_open(struct inode *inode, struct file *file)
 	return single_open(file, dwc3_link_state_show, inode->i_private);
 }
 
-static ssize_t dwc3_link_state_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
+static ssize_t dwc3_link_state_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file		*s = file->private_data;
+	struct seq_file		*s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct dwc3		*dwc = s->private;
 	unsigned long		flags;
 	enum dwc3_link_state	state = 0;
@@ -622,7 +622,7 @@ static ssize_t dwc3_link_state_write(struct file *file,
 	u8			speed;
 	int			ret;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (!strncmp(buf, "SS.Disabled", 11))
@@ -672,8 +672,8 @@ static ssize_t dwc3_link_state_write(struct file *file,
 
 static const struct file_operations dwc3_link_state_fops = {
 	.open			= dwc3_link_state_open,
-	.write			= dwc3_link_state_write,
-	.read			= seq_read,
+	.write_iter		= dwc3_link_state_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#167 lore raw

PATCH 161/437 usb: fotg210-hcd: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/fotg210/fotg210-hcd.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/usb/fotg210/fotg210-hcd.c +7 -10
index 8c5aaf860635..6a7334164ca7 100644
@@ -283,27 +283,27 @@ static int debug_periodic_open(struct inode *, struct file *);
 static int debug_registers_open(struct inode *, struct file *);
 static int debug_async_open(struct inode *, struct file *);
 
-static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
+static ssize_t debug_output(struct kiocb *, struct iov_iter *);
 static int debug_close(struct inode *, struct file *);
 
 static const struct file_operations debug_async_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_async_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
 static const struct file_operations debug_periodic_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_periodic_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
 static const struct file_operations debug_registers_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_registers_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
@@ -773,10 +773,9 @@ static int fill_buffer(struct debug_buffer *buf)
 	return ret;
 }
 
-static ssize_t debug_output(struct file *file, char __user *user_buf,
-		size_t len, loff_t *offset)
+static ssize_t debug_output(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct debug_buffer *buf = file->private_data;
+	struct debug_buffer *buf = iocb->ki_filp->private_data;
 	int ret = 0;
 
 	mutex_lock(&buf->mutex);
@@ -789,9 +788,7 @@ static ssize_t debug_output(struct file *file, char __user *user_buf,
 	}
 	mutex_unlock(&buf->mutex);
 
-	ret = simple_read_from_buffer(user_buf, len, offset,
-			buf->output_buf, buf->count);
-
+	ret = simple_copy_to_iter(buf->output_buf, &iocb->ki_pos, buf->count, to);
 out:
 	return ret;
 
Signature · 1 line
2.43.0
author maintainer
#168 lore raw

PATCH 162/437 usb: gadget: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/gadget/function/f_fs.c      |  6 ++++--
 drivers/usb/gadget/function/f_hid.c     | 17 ++++++++--------
 drivers/usb/gadget/function/f_printer.c | 26 ++++++++++++-------------
 drivers/usb/gadget/legacy/inode.c       |  6 ++++--
 drivers/usb/gadget/udc/renesas_usb3.c   | 14 ++++++-------
 5 files changed, 36 insertions(+), 33 deletions(-)
drivers/usb/gadget/function/f_fs.c +4 -2
index bffbc1dc651f..e3514d295e55 100644
@@ -495,6 +495,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
 	mutex_unlock(&ffs->mutex);
 	return ret;
 }
+FOPS_WRITE_ITER_HELPER(ffs_ep0_write);
 
 /* Called with ffs->ev.waitq.lock and ffs->mutex held, both released on exit. */
 static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
@@ -632,6 +633,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
 	kfree(data);
 	return ret;
 }
+FOPS_READ_ITER_HELPER(ffs_ep0_read);
 
 static int ffs_ep0_open(struct inode *inode, struct file *file)
 {
@@ -720,8 +722,8 @@ static const struct file_operations ffs_ep0_operations = {
 	.llseek =	no_llseek,
 
 	.open =		ffs_ep0_open,
-	.write =	ffs_ep0_write,
-	.read =		ffs_ep0_read,
+	.write_iter =	ffs_ep0_write_iter,
+	.read_iter =	ffs_ep0_read_iter,
 	.release =	ffs_ep0_release,
 	.unlocked_ioctl =	ffs_ep0_ioctl,
 	.poll =		ffs_ep0_poll,
drivers/usb/gadget/function/f_hid.c +9 -8
index 3c8a9dd585c0..13e5bab6e1b2 100644
@@ -414,6 +414,7 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,
 	else
 		return f_hidg_ssreport_read(file, buffer, count, ptr);
 }
+FOPS_READ_ITER_HELPER(f_hidg_read);
 
 static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -431,10 +432,10 @@ static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
 	wake_up(&hidg->write_queue);
 }
 
-static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
-			    size_t count, loff_t *offp)
+static ssize_t f_hidg_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct f_hidg *hidg  = file->private_data;
+	struct f_hidg *hidg  = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct usb_request *req;
 	unsigned long flags;
 	ssize_t status = -ENOMEM;
@@ -451,7 +452,7 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
 	/* write queue */
 	while (!WRITE_COND) {
 		spin_unlock_irqrestore(&hidg->write_spinlock, flags);
-		if (file->f_flags & O_NONBLOCK)
+		if (iocb->ki_filp->f_flags & O_NONBLOCK)
 			return -EAGAIN;
 
 		if (wait_event_interruptible_exclusive(
@@ -473,8 +474,8 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
 		goto release_write_pending;
 	}
 
-	status = copy_from_user(req->buf, buffer, count);
-	if (status != 0) {
+	status = copy_from_iter_full(req->buf, count, from);
+	if (!status) {
 		ERROR(hidg->func.config->cdev,
 			"copy_from_user error\n");
 		status = -EINVAL;
@@ -906,8 +907,8 @@ static const struct file_operations f_hidg_fops = {
 	.owner		= THIS_MODULE,
 	.open		= f_hidg_open,
 	.release	= f_hidg_release,
-	.write		= f_hidg_write,
-	.read		= f_hidg_read,
+	.write_iter	= f_hidg_write,
+	.read_iter	= f_hidg_read_iter,
 	.poll		= f_hidg_poll,
 	.llseek		= noop_llseek,
 };
drivers/usb/gadget/function/f_printer.c +12 -14
index 076dd4c1be96..de3863f0bfb6 100644
@@ -426,10 +426,10 @@ setup_rx_reqs(struct printer_dev *dev)
 	}
 }
 
-static ssize_t
-printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
+static ssize_t printer_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct printer_dev		*dev = fd->private_data;
+	struct printer_dev		*dev = iocb->ki_filp->private_data;
+	size_t				len = iov_iter_count(to);
 	unsigned long			flags;
 	size_t				size;
 	size_t				bytes_copied;
@@ -485,7 +485,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 		 * If no data is available check if this is a NON-Blocking
 		 * call or not.
 		 */
-		if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
+		if (iocb->ki_filp->f_flags & (O_NONBLOCK|O_NDELAY)) {
 			mutex_unlock(&dev->lock_printer_io);
 			return -EAGAIN;
 		}
@@ -522,10 +522,9 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 		else
 			size = len;
 
-		size -= copy_to_user(buf, current_rx_buf, size);
+		size -= copy_to_iter(current_rx_buf, size, to);
 		bytes_copied += size;
 		len -= size;
-		buf += size;
 
 		spin_lock_irqsave(&dev->lock, flags);
 
@@ -568,10 +567,10 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 		return -EAGAIN;
 }
 
-static ssize_t
-printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
+static ssize_t printer_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct printer_dev	*dev = fd->private_data;
+	struct printer_dev	*dev = iocb->ki_filp->private_data;
+	size_t			len = iov_iter_count(from);
 	unsigned long		flags;
 	size_t			size;	/* Amount of data in a TX request. */
 	size_t			bytes_copied = 0;
@@ -604,7 +603,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 		 * If write buffers are available check if this is
 		 * a NON-Blocking call or not.
 		 */
-		if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
+		if (iocb->ki_filp->f_flags & (O_NONBLOCK|O_NDELAY)) {
 			mutex_unlock(&dev->lock_printer_io);
 			return -EAGAIN;
 		}
@@ -642,7 +641,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 		/* Don't leave irqs off while doing memory copies */
 		spin_unlock_irqrestore(&dev->lock, flags);
 
-		if (copy_from_user(req->buf, buf, size)) {
+		if (!copy_from_iter_full(req->buf, size, from)) {
 			list_add(&req->list, &dev->tx_reqs);
 			mutex_unlock(&dev->lock_printer_io);
 			return bytes_copied;
@@ -650,7 +649,6 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 
 		bytes_copied += size;
 		len -= size;
-		buf += size;
 
 		spin_lock_irqsave(&dev->lock, flags);
 
@@ -794,8 +792,8 @@ printer_ioctl(struct file *fd, unsigned int code, unsigned long arg)
 static const struct file_operations printer_io_operations = {
 	.owner =	THIS_MODULE,
 	.open =		printer_open,
-	.read =		printer_read,
-	.write =	printer_write,
+	.read_iter =	printer_read,
+	.write_iter =	printer_write,
 	.fsync =	printer_fsync,
 	.poll =		printer_poll,
 	.unlocked_ioctl = printer_ioctl,
drivers/usb/gadget/legacy/inode.c +4 -2
index 03179b1880fd..2898840a7a41 100644
@@ -1080,6 +1080,7 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 	spin_unlock_irq (&dev->lock);
 	return retval;
 }
+FOPS_READ_ITER_HELPER(ep0_read);
 
 static struct usb_gadgetfs_event *
 next_event (struct dev_data *dev, enum usb_gadgetfs_event_type type)
@@ -1919,6 +1920,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 	dev->buf = NULL;
 	return value;
 }
+FOPS_WRITE_ITER_HELPER(dev_config);
 
 static int
 gadget_dev_open (struct inode *inode, struct file *fd)
@@ -1942,8 +1944,8 @@ static const struct file_operations ep0_operations = {
 	.llseek =	no_llseek,
 
 	.open =		gadget_dev_open,
-	.read =		ep0_read,
-	.write =	dev_config,
+	.read_iter =	ep0_read_iter,
+	.write_iter =	dev_config_iter,
 	.fasync =	ep0_fasync,
 	.poll =		ep0_poll,
 	.unlocked_ioctl = gadget_dev_ioctl,
drivers/usb/gadget/udc/renesas_usb3.c +7 -7
index 3b01734ce1b7..61f5d7ac47ee 100644
@@ -2603,18 +2603,18 @@ static int renesas_usb3_b_device_open(struct inode *inode, struct file *file)
 	return single_open(file, renesas_usb3_b_device_show, inode->i_private);
 }
 
-static ssize_t renesas_usb3_b_device_write(struct file *file,
-					   const char __user *ubuf,
-					   size_t count, loff_t *ppos)
+static ssize_t renesas_usb3_b_device_write(struct kiocb *iocb,
+					   struct iov_iter *from)
 {
-	struct seq_file *s = file->private_data;
+	struct seq_file *s = iocb->ki_filp->private_data;
 	struct renesas_usb3 *usb3 = s->private;
+	size_t count = iov_iter_count(from);
 	char buf[32];
 
 	if (!usb3->driver)
 		return -ENODEV;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	usb3->start_to_connect = false;
@@ -2637,8 +2637,8 @@ static ssize_t renesas_usb3_b_device_write(struct file *file,
 
 static const struct file_operations renesas_usb3_b_device_fops = {
 	.open = renesas_usb3_b_device_open,
-	.write = renesas_usb3_b_device_write,
-	.read = seq_read,
+	.write_iter = renesas_usb3_b_device_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#169 lore raw

PATCH 163/437 usb: host: ehci: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/host/ehci-dbg.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/usb/host/ehci-dbg.c +8 -11
index c063fb042926..c9390a17c432 100644
@@ -293,13 +293,13 @@ static int debug_bandwidth_open(struct inode *, struct file *);
 static int debug_periodic_open(struct inode *, struct file *);
 static int debug_registers_open(struct inode *, struct file *);
 
-static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
+static ssize_t debug_output(struct kiocb *, struct iov_iter *);
 static int debug_close(struct inode *, struct file *);
 
 static const struct file_operations debug_async_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_async_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
@@ -307,7 +307,7 @@ static const struct file_operations debug_async_fops = {
 static const struct file_operations debug_bandwidth_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_bandwidth_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
@@ -315,7 +315,7 @@ static const struct file_operations debug_bandwidth_fops = {
 static const struct file_operations debug_periodic_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_periodic_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
@@ -323,7 +323,7 @@ static const struct file_operations debug_periodic_fops = {
 static const struct file_operations debug_registers_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_registers_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
@@ -952,10 +952,9 @@ static int fill_buffer(struct debug_buffer *buf)
 	return ret;
 }
 
-static ssize_t debug_output(struct file *file, char __user *user_buf,
-		size_t len, loff_t *offset)
+static ssize_t debug_output(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct debug_buffer *buf = file->private_data;
+	struct debug_buffer *buf = iocb->ki_filp->private_data;
 	int ret;
 
 	mutex_lock(&buf->mutex);
@@ -968,9 +967,7 @@ static ssize_t debug_output(struct file *file, char __user *user_buf,
 	}
 	mutex_unlock(&buf->mutex);
 
-	ret = simple_read_from_buffer(user_buf, len, offset,
-				      buf->output_buf, buf->count);
-
+	ret = simple_copy_to_iter(buf->output_buf, &iocb->ki_pos, buf->count, to);
 out:
 	return ret;
 }
Signature · 1 line
2.43.0
author maintainer
#170 lore raw

PATCH 164/437 usb: host: ohci: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/host/ohci-dbg.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/usb/host/ohci-dbg.c +7 -10
index 76bc8d56325d..dc40e655f824 100644
@@ -361,27 +361,27 @@ static int debug_async_open(struct inode *, struct file *);
 static int debug_periodic_open(struct inode *, struct file *);
 static int debug_registers_open(struct inode *, struct file *);
 static int debug_async_open(struct inode *, struct file *);
-static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
+static ssize_t debug_output(struct kiocb *, struct iov_iter *);
 static int debug_close(struct inode *, struct file *);
 
 static const struct file_operations debug_async_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_async_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
 static const struct file_operations debug_periodic_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_periodic_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
 static const struct file_operations debug_registers_fops = {
 	.owner		= THIS_MODULE,
 	.open		= debug_registers_open,
-	.read		= debug_output,
+	.read_iter	= debug_output,
 	.release	= debug_close,
 	.llseek		= default_llseek,
 };
@@ -701,10 +701,9 @@ static int fill_buffer(struct debug_buffer *buf)
 	return ret;
 }
 
-static ssize_t debug_output(struct file *file, char __user *user_buf,
-			size_t len, loff_t *offset)
+static ssize_t debug_output(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct debug_buffer *buf = file->private_data;
+	struct debug_buffer *buf = iocb->ki_filp->private_data;
 	int ret;
 
 	mutex_lock(&buf->mutex);
@@ -717,9 +716,7 @@ static ssize_t debug_output(struct file *file, char __user *user_buf,
 	}
 	mutex_unlock(&buf->mutex);
 
-	ret = simple_read_from_buffer(user_buf, len, offset,
-				      buf->page, buf->count);
-
+	ret = simple_copy_to_iter(buf->page, &iocb->ki_pos, buf->count, to);
 out:
 	return ret;
 
Signature · 1 line
2.43.0
author maintainer
#171 lore raw

PATCH 165/437 usb: host: uhci: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/host/uhci-debug.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/usb/host/uhci-debug.c +4 -5
index c4e67c4b51f6..e8329c44db59 100644
@@ -589,11 +589,10 @@ static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
 	return no_seek_end_llseek_size(file, off, whence, up->size);
 }
 
-static ssize_t uhci_debug_read(struct file *file, char __user *buf,
-				size_t nbytes, loff_t *ppos)
+static ssize_t uhci_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct uhci_debug *up = file->private_data;
-	return simple_read_from_buffer(buf, nbytes, ppos, up->data, up->size);
+	struct uhci_debug *up = iocb->ki_filp->private_data;
+	return simple_copy_to_iter(up->data, &iocb->ki_pos, up->size, to);
 }
 
 static int uhci_debug_release(struct inode *inode, struct file *file)
@@ -610,7 +609,7 @@ static const struct file_operations uhci_debug_operations = {
 	.owner =	THIS_MODULE,
 	.open =		uhci_debug_open,
 	.llseek =	uhci_debug_lseek,
-	.read =		uhci_debug_read,
+	.read_iter =	uhci_debug_read,
 	.release =	uhci_debug_release,
 };
 #define UHCI_DEBUG_OPS
Signature · 1 line
2.43.0
author maintainer
#172 lore raw

PATCH 166/437 usb: host: xhci: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/host/xhci-debugfs.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/usb/host/xhci-debugfs.c +14 -14
index f8ba15e7c225..751e48d0b555 100644
@@ -251,7 +251,7 @@ static int xhci_ring_open(struct inode *inode, struct file *file)
 
 static const struct file_operations xhci_ring_fops = {
 	.open			= xhci_ring_open,
-	.read			= seq_read,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
@@ -336,7 +336,7 @@ static int xhci_context_open(struct inode *inode, struct file *file)
 
 static const struct file_operations xhci_context_fops = {
 	.open			= xhci_context_open,
-	.read			= seq_read,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
@@ -360,17 +360,17 @@ static int xhci_port_open(struct inode *inode, struct file *file)
 	return single_open(file, xhci_portsc_show, inode->i_private);
 }
 
-static ssize_t xhci_port_write(struct file *file,  const char __user *ubuf,
-			       size_t count, loff_t *ppos)
+static ssize_t xhci_port_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file         *s = file->private_data;
+	struct seq_file         *s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct xhci_port	*port = s->private;
 	struct xhci_hcd		*xhci = hcd_to_xhci(port->rhub->hcd);
 	char                    buf[32];
 	u32			portsc;
 	unsigned long		flags;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (!strncmp(buf, "compliance", 10)) {
@@ -397,8 +397,8 @@ static ssize_t xhci_port_write(struct file *file,  const char __user *ubuf,
 
 static const struct file_operations port_fops = {
 	.open			= xhci_port_open,
-	.write                  = xhci_port_write,
-	.read			= seq_read,
+	.write_iter             = xhci_port_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
@@ -502,10 +502,10 @@ static int xhci_stream_id_open(struct inode *inode, struct file *file)
 	return single_open(file, xhci_stream_id_show, inode->i_private);
 }
 
-static ssize_t xhci_stream_id_write(struct file *file,  const char __user *ubuf,
-			       size_t count, loff_t *ppos)
+static ssize_t xhci_stream_id_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file         *s = file->private_data;
+	struct seq_file         *s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct xhci_ep_priv	*epriv = s->private;
 	int			ret;
 	u16			stream_id; /* MaxPStreams + 1 <= 16 */
@@ -514,7 +514,7 @@ static ssize_t xhci_stream_id_write(struct file *file,  const char __user *ubuf,
 		return -EPERM;
 
 	/* Decimal number */
-	ret = kstrtou16_from_user(ubuf, count, 10, &stream_id);
+	ret = kstrtou16_from_iter(from, count, 10, &stream_id);
 	if (ret)
 		return ret;
 
@@ -529,8 +529,8 @@ static ssize_t xhci_stream_id_write(struct file *file,  const char __user *ubuf,
 
 static const struct file_operations stream_id_fops = {
 	.open			= xhci_stream_id_open,
-	.write                  = xhci_stream_id_write,
-	.read			= seq_read,
+	.write_iter             = xhci_stream_id_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#173 lore raw

PATCH 167/437 usb: image: mdc800: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/image/mdc800.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/usb/image/mdc800.c +7 -8
index 7b7e1554ea20..ec52a144f8d7 100644
@@ -677,10 +677,10 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
 /*
  * The Device read callback Function
  */
-static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t len, loff_t *pos)
+static ssize_t mdc800_device_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t len = iov_iter_count(to);
 	size_t left=len, sts=len; /* single transfer size */
-	char __user *ptr = buf;
 	int retval;
 
 	mutex_lock(&mdc800->io_lock);
@@ -754,12 +754,11 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
 		else
 		{
 			/* Copy Bytes */
-			if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
-						sts)) {
+			if (!copy_to_iter_full(&mdc800->out [mdc800->out_ptr],
+						sts, to)) {
 				mutex_unlock(&mdc800->io_lock);
 				return -EFAULT;
 			}
-			ptr+=sts;
 			left-=sts;
 			mdc800->out_ptr+=sts;
 		}
@@ -936,7 +935,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
 	mutex_unlock(&mdc800->io_lock);
 	return i;
 }
-
+FOPS_WRITE_ITER_HELPER(mdc800_device_write);
 
 /***************************************************************************
 	Init and Cleanup this driver (Structs and types)
@@ -946,8 +945,8 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
 static const struct file_operations mdc800_device_ops =
 {
 	.owner =	THIS_MODULE,
-	.read =		mdc800_device_read,
-	.write =	mdc800_device_write,
+	.read_iter =	mdc800_device_read,
+	.write_iter =	mdc800_device_write_iter,
 	.open =		mdc800_device_open,
 	.release =	mdc800_device_release,
 	.llseek =	noop_llseek,
Signature · 1 line
2.43.0
author maintainer
#174 lore raw

PATCH 168/437 usb: misc: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/misc/adutux.c              |  6 ++++--
 drivers/usb/misc/chaoskey.c            | 13 +++++--------
 drivers/usb/misc/idmouse.c             | 15 ++++++---------
 drivers/usb/misc/iowarrior.c           |  6 ++++--
 drivers/usb/misc/ldusb.c               | 24 ++++++++++++------------
 drivers/usb/misc/legousbtower.c        | 26 ++++++++++++++------------
 drivers/usb/misc/sisusbvga/sisusbvga.c |  6 ++++--
 drivers/usb/misc/usblcd.c              | 20 ++++++++++----------
 drivers/usb/misc/yurex.c               | 19 +++++++++----------
 9 files changed, 68 insertions(+), 67 deletions(-)
drivers/usb/misc/adutux.c +4 -2
index ed6a19254d2f..20d6107682c2 100644
@@ -499,6 +499,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
 
 	return retval;
 }
+FOPS_READ_ITER_HELPER(adu_read);
 
 static ssize_t adu_write(struct file *file, const __user char *buffer,
 			 size_t count, loff_t *ppos)
@@ -619,12 +620,13 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
 	remove_wait_queue(&dev->write_wait, &waita);
 	return retval;
 }
+FOPS_WRITE_ITER_HELPER(adu_write);
 
 /* file operations needed when we register this driver */
 static const struct file_operations adu_fops = {
 	.owner = THIS_MODULE,
-	.read  = adu_read,
-	.write = adu_write,
+	.read_iter  = adu_read_iter,
+	.write_iter = adu_write_iter,
 	.open = adu_open,
 	.release = adu_release,
 	.llseek = noop_llseek,
drivers/usb/misc/chaoskey.c +5 -8
index 6fb5140e29b9..400b19bb1ee6 100644
@@ -403,18 +403,16 @@ static int _chaoskey_fill(struct chaoskey *dev)
 	return result;
 }
 
-static ssize_t chaoskey_read(struct file *file,
-			     char __user *buffer,
-			     size_t count,
-			     loff_t *ppos)
+static ssize_t chaoskey_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct chaoskey *dev;
 	ssize_t read_count = 0;
 	int this_time;
 	int result = 0;
 	unsigned long remain;
+	size_t count = iov_iter_count(to);
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	if (dev == NULL || !dev->present)
 		return -ENODEV;
@@ -446,7 +444,7 @@ static ssize_t chaoskey_read(struct file *file,
 		if (this_time > count)
 			this_time = count;
 
-		remain = copy_to_user(buffer, dev->buf + dev->used, this_time);
+		remain = !copy_to_iter_full(dev->buf + dev->used, this_time, to);
 		if (remain) {
 			result = -EFAULT;
 
@@ -460,7 +458,6 @@ static ssize_t chaoskey_read(struct file *file,
 
 		count -= this_time;
 		read_count += this_time;
-		buffer += this_time;
 		dev->used += this_time;
 		mutex_unlock(&dev->lock);
 	}
@@ -554,7 +551,7 @@ static int chaoskey_resume(struct usb_interface *interface)
 /* file operation pointers */
 static const struct file_operations chaoskey_fops = {
 	.owner = THIS_MODULE,
-	.read = chaoskey_read,
+	.read_iter = chaoskey_read,
 	.open = chaoskey_open,
 	.release = chaoskey_release,
 	.llseek = default_llseek,
drivers/usb/misc/idmouse.c +6 -9
index ea39243efee3..91534f0982ea 100644
@@ -79,9 +79,7 @@ struct usb_idmouse {
 };
 
 /* local function prototypes */
-static ssize_t idmouse_read(struct file *file, char __user *buffer,
-				size_t count, loff_t * ppos);
-
+static ssize_t idmouse_read(struct kiocb *iocb, struct iov_iter *to);
 static int idmouse_open(struct inode *inode, struct file *file);
 static int idmouse_release(struct inode *inode, struct file *file);
 
@@ -95,7 +93,7 @@ static int idmouse_resume(struct usb_interface *intf);
 /* file operation pointers */
 static const struct file_operations idmouse_fops = {
 	.owner = THIS_MODULE,
-	.read = idmouse_read,
+	.read_iter = idmouse_read,
 	.open = idmouse_open,
 	.release = idmouse_release,
 	.llseek = default_llseek,
@@ -290,10 +288,9 @@ static int idmouse_release(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count,
-				loff_t * ppos)
+static ssize_t idmouse_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct usb_idmouse *dev = file->private_data;
+	struct usb_idmouse *dev = iocb->ki_filp->private_data;
 	int result;
 
 	/* lock this object */
@@ -305,8 +302,8 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
 		return -ENODEV;
 	}
 
-	result = simple_read_from_buffer(buffer, count, ppos,
-					dev->bulk_in_buffer, IMGSIZE);
+	result = simple_copy_to_iter(dev->bulk_in_buffer, &iocb->ki_pos,
+					IMGSIZE, to);
 	/* unlock the device */
 	mutex_unlock(&dev->lock);
 	return result;
drivers/usb/misc/iowarrior.c +4 -2
index 6d28467ce352..bb0f28e1cdca 100644
@@ -332,6 +332,7 @@ static ssize_t iowarrior_read(struct file *file, char __user *buffer,
 	atomic_set(&dev->read_idx, read_idx);
 	return count;
 }
+FOPS_READ_ITER_HELPER(iowarrior_read);
 
 /*
  * iowarrior_write
@@ -468,6 +469,7 @@ static ssize_t iowarrior_write(struct file *file,
 	mutex_unlock(&dev->mutex);
 	return retval;
 }
+FOPS_WRITE_ITER_HELPER(iowarrior_write);
 
 /*
  *	iowarrior_ioctl
@@ -707,8 +709,8 @@ static __poll_t iowarrior_poll(struct file *file, poll_table * wait)
  */
 static const struct file_operations iowarrior_fops = {
 	.owner = THIS_MODULE,
-	.write = iowarrior_write,
-	.read = iowarrior_read,
+	.write_iter = iowarrior_write_iter,
+	.read_iter = iowarrior_read_iter,
 	.unlocked_ioctl = iowarrior_ioctl,
 	.open = iowarrior_open,
 	.release = iowarrior_release,
drivers/usb/misc/ldusb.c +12 -12
index 7cbef74dfc9a..7fef44f35b45 100644
@@ -433,16 +433,16 @@ static __poll_t ld_usb_poll(struct file *file, poll_table *wait)
 /*
  *	ld_usb_read
  */
-static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
-			   loff_t *ppos)
+static ssize_t ld_usb_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	struct ld_usb *dev;
 	size_t *actual_buffer;
 	size_t bytes_to_read;
 	int retval = 0;
 	int rv;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	/* verify that we actually have some data to read */
 	if (count == 0)
@@ -466,7 +466,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
 	while (dev->ring_head == dev->ring_tail) {
 		dev->interrupt_in_done = 0;
 		spin_unlock_irq(&dev->rbsl);
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
 			goto unlock_exit;
 		}
@@ -490,7 +490,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
 			 *actual_buffer-bytes_to_read);
 
 	/* copy one interrupt_in_buffer from ring_buffer into userspace */
-	if (copy_to_user(buffer, actual_buffer+1, bytes_to_read)) {
+	if (!copy_to_iter_full(actual_buffer+1, bytes_to_read, to)) {
 		retval = -EFAULT;
 		goto unlock_exit;
 	}
@@ -520,14 +520,14 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
 /*
  *	ld_usb_write
  */
-static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
-			    size_t count, loff_t *ppos)
+static ssize_t ld_usb_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	struct ld_usb *dev;
 	size_t bytes_to_write;
 	int retval = 0;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	/* verify that we actually have some data to write */
 	if (count == 0)
@@ -548,7 +548,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
 
 	/* wait until previous transfer is finished */
 	if (dev->interrupt_out_busy) {
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
 			goto unlock_exit;
 		}
@@ -566,7 +566,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
 	dev_dbg(&dev->intf->dev, "%s: count = %zu, bytes_to_write = %zu\n",
 		__func__, count, bytes_to_write);
 
-	if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
+	if (!copy_from_iter_full(dev->interrupt_out_buffer, bytes_to_write, from)) {
 		retval = -EFAULT;
 		goto unlock_exit;
 	}
@@ -622,8 +622,8 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
 /* file operations needed when we register this driver */
 static const struct file_operations ld_usb_fops = {
 	.owner =	THIS_MODULE,
-	.read  =	ld_usb_read,
-	.write =	ld_usb_write,
+	.read_iter  =	ld_usb_read,
+	.write_iter =	ld_usb_write,
 	.open =		ld_usb_open,
 	.release =	ld_usb_release,
 	.poll =		ld_usb_poll,
drivers/usb/misc/legousbtower.c +14 -12
index 379cf01a6e96..57dcb5612734 100644
@@ -218,8 +218,8 @@ struct lego_usb_tower {
 
 
 /* local function prototypes */
-static ssize_t tower_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos);
-static ssize_t tower_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos);
+static ssize_t tower_read(struct kiocb *iocb, struct iov_iter *to);
+static ssize_t tower_write(struct kiocb *iocb, struct iov_iter *from);
 static inline void tower_delete(struct lego_usb_tower *dev);
 static int tower_open(struct inode *inode, struct file *file);
 static int tower_release(struct inode *inode, struct file *file);
@@ -237,8 +237,8 @@ static void tower_disconnect(struct usb_interface *interface);
 /* file operations needed when we register this driver */
 static const struct file_operations tower_fops = {
 	.owner =	THIS_MODULE,
-	.read  =	tower_read,
-	.write =	tower_write,
+	.read_iter  =	tower_read,
+	.write_iter =	tower_write,
 	.open =		tower_open,
 	.release =	tower_release,
 	.poll =		tower_poll,
@@ -489,15 +489,16 @@ static loff_t tower_llseek(struct file *file, loff_t off, int whence)
 /*
  *	tower_read
  */
-static ssize_t tower_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t tower_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	struct lego_usb_tower *dev;
 	size_t bytes_to_read;
 	int i;
 	int retval = 0;
 	unsigned long timeout = 0;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	/* lock this object */
 	if (mutex_lock_interruptible(&dev->lock)) {
@@ -523,7 +524,7 @@ static ssize_t tower_read(struct file *file, char __user *buffer, size_t count,
 	/* wait for data */
 	tower_check_for_read_packet(dev);
 	while (dev->read_packet_length == 0) {
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
 			goto unlock_exit;
 		}
@@ -547,7 +548,7 @@ static ssize_t tower_read(struct file *file, char __user *buffer, size_t count,
 	/* copy the data from read_buffer into userspace */
 	bytes_to_read = min(count, dev->read_packet_length);
 
-	if (copy_to_user(buffer, dev->read_buffer, bytes_to_read)) {
+	if (!copy_to_iter_full(dev->read_buffer, bytes_to_read, to)) {
 		retval = -EFAULT;
 		goto unlock_exit;
 	}
@@ -573,13 +574,14 @@ static ssize_t tower_read(struct file *file, char __user *buffer, size_t count,
 /*
  *	tower_write
  */
-static ssize_t tower_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t tower_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	struct lego_usb_tower *dev;
 	size_t bytes_to_write;
 	int retval = 0;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	/* lock this object */
 	if (mutex_lock_interruptible(&dev->lock)) {
@@ -601,7 +603,7 @@ static ssize_t tower_write(struct file *file, const char __user *buffer, size_t
 
 	/* wait until previous transfer is finished */
 	while (dev->interrupt_out_busy) {
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
 			goto unlock_exit;
 		}
@@ -616,7 +618,7 @@ static ssize_t tower_write(struct file *file, const char __user *buffer, size_t
 	dev_dbg(&dev->udev->dev, "%s: count = %zd, bytes_to_write = %zd\n",
 		__func__, count, bytes_to_write);
 
-	if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
+	if (!copy_from_iter_full(dev->interrupt_out_buffer, bytes_to_write, from)) {
 		retval = -EFAULT;
 		goto unlock_exit;
 	}
drivers/usb/misc/sisusbvga/sisusbvga.c +4 -2
index febf34f9f049..88a94fafe594 100644
@@ -2428,6 +2428,7 @@ static ssize_t sisusb_read(struct file *file, char __user *buffer,
 
 	return errno ? errno : bytes_read;
 }
+FOPS_READ_ITER_HELPER(sisusb_read);
 
 static ssize_t sisusb_write(struct file *file, const char __user *buffer,
 		size_t count, loff_t *ppos)
@@ -2572,6 +2573,7 @@ static ssize_t sisusb_write(struct file *file, const char __user *buffer,
 
 	return errno ? errno : bytes_written;
 }
+FOPS_WRITE_ITER_HELPER(sisusb_write);
 
 static loff_t sisusb_lseek(struct file *file, loff_t offset, int orig)
 {
@@ -2757,8 +2759,8 @@ static const struct file_operations usb_sisusb_fops = {
 	.owner =	THIS_MODULE,
 	.open =		sisusb_open,
 	.release =	sisusb_release,
-	.read =		sisusb_read,
-	.write =	sisusb_write,
+	.read_iter =	sisusb_read_iter,
+	.write_iter =	sisusb_write_iter,
 	.llseek =	sisusb_lseek,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = sisusb_compat_ioctl,
drivers/usb/misc/usblcd.c +10 -10
index bb546f624a45..8d826e648b84 100644
@@ -121,14 +121,14 @@ static int lcd_release(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t lcd_read(struct file *file, char __user * buffer,
-			size_t count, loff_t *ppos)
+static ssize_t lcd_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	struct usb_lcd *dev;
 	int retval = 0;
 	int bytes_read;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	down_read(&dev->io_rwsem);
 
@@ -147,7 +147,7 @@ static ssize_t lcd_read(struct file *file, char __user * buffer,
 
 	/* if the read was successful, copy the data to userspace */
 	if (!retval) {
-		if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read))
+		if (!copy_to_iter_full(dev->bulk_in_buffer, bytes_read, to))
 			retval = -EFAULT;
 		else
 			retval = bytes_read;
@@ -214,15 +214,15 @@ static void lcd_write_bulk_callback(struct urb *urb)
 	up(&dev->limit_sem);
 }
 
-static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
-			 size_t count, loff_t *ppos)
+static ssize_t lcd_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	struct usb_lcd *dev;
 	int retval = 0, r;
 	struct urb *urb = NULL;
 	char *buf = NULL;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	/* verify that we actually have some data to write */
 	if (count == 0)
@@ -253,7 +253,7 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
 		goto error;
 	}
 
-	if (copy_from_user(buf, user_buffer, count)) {
+	if (!copy_from_iter_full(buf, count, from)) {
 		retval = -EFAULT;
 		goto error;
 	}
@@ -296,8 +296,8 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
 
 static const struct file_operations lcd_fops = {
 	.owner =        THIS_MODULE,
-	.read =         lcd_read,
-	.write =        lcd_write,
+	.read_iter =    lcd_read,
+	.write_iter =   lcd_write,
 	.open =         lcd_open,
 	.unlocked_ioctl = lcd_ioctl,
 	.release =      lcd_release,
drivers/usb/misc/yurex.c +9 -10
index 9a0649d23693..b3dd24aeae23 100644
@@ -398,15 +398,14 @@ static int yurex_release(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
-			  loff_t *ppos)
+static ssize_t yurex_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct usb_yurex *dev;
 	int len = 0;
 	char in_buffer[MAX_S64_STRLEN];
 	unsigned long flags;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	mutex_lock(&dev->io_mutex);
 	if (dev->disconnected) {		/* already disconnected */
@@ -424,11 +423,10 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
 	spin_unlock_irqrestore(&dev->lock, flags);
 	mutex_unlock(&dev->io_mutex);
 
-	return simple_read_from_buffer(buffer, count, ppos, in_buffer, len);
+	return simple_copy_to_iter(in_buffer, &iocb->ki_pos, len, to);
 }
 
-static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
-			   size_t count, loff_t *ppos)
+static ssize_t yurex_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	struct usb_yurex *dev;
 	int i, set = 0, retval = 0;
@@ -436,10 +434,11 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
 	char *data = buffer;
 	unsigned long long c, c2 = 0;
 	signed long timeout = 0;
+	size_t count = iov_iter_count(from);
 	DEFINE_WAIT(wait);
 
 	count = min(sizeof(buffer) - 1, count);
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	/* verify that we actually have some data to write */
 	if (count == 0)
@@ -452,7 +451,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
 		goto error;
 	}
 
-	if (copy_from_user(buffer, user_buffer, count)) {
+	if (!copy_from_iter_full(buffer, count, from)) {
 		mutex_unlock(&dev->io_mutex);
 		retval = -EFAULT;
 		goto error;
@@ -521,8 +520,8 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
 
 static const struct file_operations yurex_fops = {
 	.owner =	THIS_MODULE,
-	.read =		yurex_read,
-	.write =	yurex_write,
+	.read_iter =	yurex_read,
+	.write_iter =	yurex_write,
 	.open =		yurex_open,
 	.release =	yurex_release,
 	.fasync	=	yurex_fasync,
Signature · 1 line
2.43.0
author maintainer
#175 lore raw

PATCH 169/437 usb: mon: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/mon/mon_bin.c  | 3 ++-
 drivers/usb/mon/mon_stat.c | 9 ++++-----
 drivers/usb/mon/mon_text.c | 6 ++++--
 3 files changed, 10 insertions(+), 8 deletions(-)
drivers/usb/mon/mon_bin.c +2 -1
index 4e30de4db1c0..af88dd18eafe 100644
@@ -867,6 +867,7 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
 	mutex_unlock(&rp->fetch_lock);
 	return done;
 }
+FOPS_READ_ITER_HELPER(mon_bin_read);
 
 /*
  * Remove at most nevents from chunked buffer.
@@ -1290,7 +1291,7 @@ static const struct file_operations mon_fops_binary = {
 	.owner =	THIS_MODULE,
 	.open =		mon_bin_open,
 	.llseek =	no_llseek,
-	.read =		mon_bin_read,
+	.read_iter =	mon_bin_read_iter,
 	/* .write =	mon_text_write, */
 	.poll =		mon_bin_poll,
 	.unlocked_ioctl = mon_bin_ioctl,
drivers/usb/mon/mon_stat.c +4 -5
index 3c23805ab1a4..e13a81ade7cf 100644
@@ -43,12 +43,11 @@ static int mon_stat_open(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t mon_stat_read(struct file *file, char __user *buf,
-				size_t nbytes, loff_t *ppos)
+static ssize_t mon_stat_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct snap *sp = file->private_data;
+	struct snap *sp = iocb->ki_filp->private_data;
 
-	return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
+	return simple_copy_to_iter(sp->str, &iocb->ki_pos, sp->slen, to);
 }
 
 static int mon_stat_release(struct inode *inode, struct file *file)
@@ -63,7 +62,7 @@ const struct file_operations mon_fops_stat = {
 	.owner =	THIS_MODULE,
 	.open =		mon_stat_open,
 	.llseek =	no_llseek,
-	.read =		mon_stat_read,
+	.read_iter =	mon_stat_read,
 	/* .write =	mon_stat_write, */
 	/* .poll =		mon_stat_poll, */
 	/* .unlocked_ioctl =	mon_stat_ioctl, */
drivers/usb/mon/mon_text.c +4 -2
index 2fe9b95bac1d..ec50a0e23117 100644
@@ -428,6 +428,7 @@ static ssize_t mon_text_read_t(struct file *file, char __user *buf,
 	mutex_unlock(&rp->printf_lock);
 	return ret;
 }
+FOPS_READ_ITER_HELPER(mon_text_read_t);
 
 /* ppos is not advanced since the llseek operation is not permitted. */
 static ssize_t mon_text_read_u(struct file *file, char __user *buf,
@@ -476,6 +477,7 @@ static ssize_t mon_text_read_u(struct file *file, char __user *buf,
 	mutex_unlock(&rp->printf_lock);
 	return ret;
 }
+FOPS_READ_ITER_HELPER(mon_text_read_u);
 
 static struct mon_event_text *mon_text_read_wait(struct mon_reader_text *rp,
     struct file *file)
@@ -686,7 +688,7 @@ static const struct file_operations mon_fops_text_t = {
 	.owner =	THIS_MODULE,
 	.open =		mon_text_open,
 	.llseek =	no_llseek,
-	.read =		mon_text_read_t,
+	.read_iter =	mon_text_read_t_iter,
 	.release =	mon_text_release,
 };
 
@@ -694,7 +696,7 @@ static const struct file_operations mon_fops_text_u = {
 	.owner =	THIS_MODULE,
 	.open =		mon_text_open,
 	.llseek =	no_llseek,
-	.read =		mon_text_read_u,
+	.read_iter =	mon_text_read_u_iter,
 	.release =	mon_text_release,
 };
 
Signature · 1 line
2.43.0
author maintainer
#176 lore raw

PATCH 170/437 usb: mtu3: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/mtu3/mtu3_debugfs.c | 40 ++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/usb/mtu3/mtu3_debugfs.c +20 -20
index f0de99858353..da73f486bfea 100644
@@ -272,7 +272,7 @@ static int mtu3_ep_open(struct inode *inode, struct file *file)
 
 static const struct file_operations mtu3_ep_fops = {
 	.open = mtu3_ep_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -311,18 +311,18 @@ static int mtu3_probe_open(struct inode *inode, struct file *file)
 	return single_open(file, mtu3_probe_show, inode->i_private);
 }
 
-static ssize_t mtu3_probe_write(struct file *file, const char __user *ubuf,
-				size_t count, loff_t *ppos)
+static ssize_t mtu3_probe_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	const char *file_name = file_dentry(file)->d_iname;
-	struct seq_file *sf = file->private_data;
+	const char *file_name = file_dentry(iocb->ki_filp)->d_iname;
+	struct seq_file *sf = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct mtu3 *mtu = sf->private;
 	const struct debugfs_reg32 *regs;
 	char buf[32];
 	u32 val;
 	int i;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (kstrtou32(buf, 0, &val))
@@ -341,8 +341,8 @@ static ssize_t mtu3_probe_write(struct file *file, const char __user *ubuf,
 
 static const struct file_operations mtu3_probe_fops = {
 	.open = mtu3_probe_open,
-	.write = mtu3_probe_write,
-	.read = seq_read,
+	.write_iter = mtu3_probe_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -443,14 +443,14 @@ static int ssusb_mode_open(struct inode *inode, struct file *file)
 	return single_open(file, ssusb_mode_show, inode->i_private);
 }
 
-static ssize_t ssusb_mode_write(struct file *file, const char __user *ubuf,
-				size_t count, loff_t *ppos)
+static ssize_t ssusb_mode_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *sf = file->private_data;
+	struct seq_file *sf = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct ssusb_mtk *ssusb = sf->private;
 	char buf[16];
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (!strncmp(buf, "host", 4) && !ssusb->is_host) {
@@ -467,8 +467,8 @@ static ssize_t ssusb_mode_write(struct file *file, const char __user *ubuf,
 
 static const struct file_operations ssusb_mode_fops = {
 	.open = ssusb_mode_open,
-	.write = ssusb_mode_write,
-	.read = seq_read,
+	.write_iter = ssusb_mode_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -489,16 +489,16 @@ static int ssusb_vbus_open(struct inode *inode, struct file *file)
 	return single_open(file, ssusb_vbus_show, inode->i_private);
 }
 
-static ssize_t ssusb_vbus_write(struct file *file, const char __user *ubuf,
-				size_t count, loff_t *ppos)
+static ssize_t ssusb_vbus_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *sf = file->private_data;
+	struct seq_file *sf = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct ssusb_mtk *ssusb = sf->private;
 	struct otg_switch_mtk *otg_sx = &ssusb->otg_switch;
 	char buf[16];
 	bool enable;
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	if (kstrtobool(buf, &enable)) {
@@ -513,8 +513,8 @@ static ssize_t ssusb_vbus_write(struct file *file, const char __user *ubuf,
 
 static const struct file_operations ssusb_vbus_fops = {
 	.open = ssusb_vbus_open,
-	.write = ssusb_vbus_write,
-	.read = seq_read,
+	.write_iter = ssusb_vbus_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#177 lore raw

PATCH 171/437 usb: musb: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/musb/musb_debugfs.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/usb/musb/musb_debugfs.c +12 -12
index 2d623284edf6..7123057d12f7 100644
@@ -160,17 +160,17 @@ static int musb_test_mode_open(struct inode *inode, struct file *file)
 	return single_open(file, musb_test_mode_show, inode->i_private);
 }
 
-static ssize_t musb_test_mode_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
+static ssize_t musb_test_mode_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file		*s = file->private_data;
+	struct seq_file		*s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct musb		*musb = s->private;
 	u8			test;
 	char			buf[24];
 
 	memset(buf, 0x00, sizeof(buf));
 
-	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	pm_runtime_get_sync(musb->controller);
@@ -223,8 +223,8 @@ static ssize_t musb_test_mode_write(struct file *file,
 
 static const struct file_operations musb_test_mode_fops = {
 	.open			= musb_test_mode_open,
-	.write			= musb_test_mode_write,
-	.read			= seq_read,
+	.write_iter		= musb_test_mode_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
@@ -260,17 +260,17 @@ static int musb_softconnect_open(struct inode *inode, struct file *file)
 	return single_open(file, musb_softconnect_show, inode->i_private);
 }
 
-static ssize_t musb_softconnect_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
+static ssize_t musb_softconnect_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file		*s = file->private_data;
+	struct seq_file		*s = iocb->ki_filp->private_data;
+	size_t			count = iov_iter_count(from);
 	struct musb		*musb = s->private;
 	char			buf[2];
 	u8			reg;
 
 	memset(buf, 0x00, sizeof(buf));
 
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(&buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	pm_runtime_get_sync(musb->controller);
@@ -315,8 +315,8 @@ static ssize_t musb_softconnect_write(struct file *file,
  */
 static const struct file_operations musb_softconnect_fops = {
 	.open			= musb_softconnect_open,
-	.write			= musb_softconnect_write,
-	.read			= seq_read,
+	.write_iter		= musb_softconnect_write,
+	.read_iter		= seq_read_iter,
 	.llseek			= seq_lseek,
 	.release		= single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#178 lore raw

PATCH 172/437 usb: skeleton: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/usb-skeleton.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/usb/usb-skeleton.c +13 -13
index 900a64ad25e4..f039a13382c1 100644
@@ -221,14 +221,14 @@ static int skel_do_read_io(struct usb_skel *dev, size_t count)
 	return rv;
 }
 
-static ssize_t skel_read(struct file *file, char *buffer, size_t count,
-			 loff_t *ppos)
+static ssize_t skel_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	struct usb_skel *dev;
 	int rv;
 	bool ongoing_io;
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	if (!count)
 		return 0;
@@ -251,7 +251,7 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
 
 	if (ongoing_io) {
 		/* nonblocking IO shall not wait */
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			rv = -EAGAIN;
 			goto exit;
 		}
@@ -301,9 +301,9 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
 		 * chunk tells us how much shall be copied
 		 */
 
-		if (copy_to_user(buffer,
+		if (!copy_to_iter_full(
 				 dev->bulk_in_buffer + dev->bulk_in_copied,
-				 chunk))
+				 chunk, to))
 			rv = -EFAULT;
 		else
 			rv = chunk;
@@ -356,16 +356,16 @@ static void skel_write_bulk_callback(struct urb *urb)
 	up(&dev->limit_sem);
 }
 
-static ssize_t skel_write(struct file *file, const char *user_buffer,
-			  size_t count, loff_t *ppos)
+static ssize_t skel_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	struct usb_skel *dev;
 	int retval = 0;
 	struct urb *urb = NULL;
 	char *buf = NULL;
 	size_t writesize = min_t(size_t, count, MAX_TRANSFER);
 
-	dev = file->private_data;
+	dev = iocb->ki_filp->private_data;
 
 	/* verify that we actually have some data to write */
 	if (count == 0)
@@ -375,7 +375,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
 	 * limit the number of URBs in flight to stop a user from using up all
 	 * RAM
 	 */
-	if (!(file->f_flags & O_NONBLOCK)) {
+	if (!(iocb->ki_filp->f_flags & O_NONBLOCK)) {
 		if (down_interruptible(&dev->limit_sem)) {
 			retval = -ERESTARTSYS;
 			goto exit;
@@ -413,7 +413,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
 		goto error;
 	}
 
-	if (copy_from_user(buf, user_buffer, writesize)) {
+	if (!copy_from_iter_full(buf, writesize, from)) {
 		retval = -EFAULT;
 		goto error;
 	}
@@ -467,8 +467,8 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
 
 static const struct file_operations skel_fops = {
 	.owner =	THIS_MODULE,
-	.read =		skel_read,
-	.write =	skel_write,
+	.read_iter =	skel_read,
+	.write_iter =	skel_write,
 	.open =		skel_open,
 	.release =	skel_release,
 	.flush =	skel_flush,
Signature · 1 line
2.43.0
author maintainer
#179 lore raw

PATCH 173/437 usb: gadget: atmel_usba_udc: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc/atmel_usba_udc.c +7 -8
index b76885d78e8a..318e9152f295 100644
@@ -122,6 +122,7 @@ static ssize_t queue_dbg_read(struct file *file, char __user *buf,
 
 	return actual;
 }
+FOPS_READ_ITER_HELPER(queue_dbg_read);
 
 static int queue_dbg_release(struct inode *inode, struct file *file)
 {
@@ -163,16 +164,14 @@ static int regs_dbg_open(struct inode *inode, struct file *file)
 	return ret;
 }
 
-static ssize_t regs_dbg_read(struct file *file, char __user *buf,
-		size_t nbytes, loff_t *ppos)
+static ssize_t regs_dbg_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct inode *inode = file_inode(file);
+	struct inode *inode = file_inode(iocb->ki_filp);
 	int ret;
 
 	inode_lock(inode);
-	ret = simple_read_from_buffer(buf, nbytes, ppos,
-			file->private_data,
-			file_inode(file)->i_size);
+	ret = simple_copy_to_iter(iocb->ki_filp->private_data, &iocb->ki_pos,
+			file_inode(iocb->ki_filp)->i_size, to);
 	inode_unlock(inode);
 
 	return ret;
@@ -188,7 +187,7 @@ static const struct file_operations queue_dbg_fops = {
 	.owner		= THIS_MODULE,
 	.open		= queue_dbg_open,
 	.llseek		= no_llseek,
-	.read		= queue_dbg_read,
+	.read_iter	= queue_dbg_read_iter,
 	.release	= queue_dbg_release,
 };
 
@@ -196,7 +195,7 @@ static const struct file_operations regs_dbg_fops = {
 	.owner		= THIS_MODULE,
 	.open		= regs_dbg_open,
 	.llseek		= generic_file_llseek,
-	.read		= regs_dbg_read,
+	.read_iter	= regs_dbg_read,
 	.release	= regs_dbg_release,
 };
 
Signature · 1 line
2.43.0
author maintainer
#180 lore raw

PATCH 174/437 soc: qcom: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/soc/qcom/cmd-db.c    |  2 +-
 drivers/soc/qcom/qcom_aoss.c | 14 ++++++-------
 drivers/soc/qcom/rmtfs_mem.c | 38 ++++++++++++++++++------------------
 drivers/soc/qcom/socinfo.c   |  4 ++--
 4 files changed, 29 insertions(+), 29 deletions(-)
drivers/soc/qcom/cmd-db.c +1 -1
index a5fd68411bed..0589e63fdb0d 100644
@@ -308,7 +308,7 @@ static const struct file_operations cmd_db_debugfs_ops = {
 #ifdef CONFIG_DEBUG_FS
 	.open = open_cmd_db_debugfs,
 #endif
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
drivers/soc/qcom/qcom_aoss.c +7 -7
index ca2f6b7629ce..6ce5fdf96432 100644
@@ -504,11 +504,11 @@ static const struct qmp_debugfs_entry qmp_debugfs_entries[QMP_DEBUGFS_FILES] = {
 	{ "prevent_ddr_collapse", "{class: ddr_mol, res: ddr, val: %s}", true, "mol", "off" },
 };
 
-static ssize_t qmp_debugfs_write(struct file *file, const char __user *user_buf,
-				 size_t count, loff_t *pos)
+static ssize_t qmp_debugfs_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	const struct qmp_debugfs_entry *entry = NULL;
-	struct qmp *qmp = file->private_data;
+	struct qmp *qmp = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	char buf[QMP_MSG_LEN];
 	unsigned int uint_val;
 	const char *str_val;
@@ -517,7 +517,7 @@ static ssize_t qmp_debugfs_write(struct file *file, const char __user *user_buf,
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(qmp->debugfs_files); i++) {
-		if (qmp->debugfs_files[i] == file->f_path.dentry) {
+		if (qmp->debugfs_files[i] == iocb->ki_filp->f_path.dentry) {
 			entry = &qmp_debugfs_entries[i];
 			break;
 		}
@@ -526,7 +526,7 @@ static ssize_t qmp_debugfs_write(struct file *file, const char __user *user_buf,
 		return -EFAULT;
 
 	if (entry->is_bool) {
-		ret = kstrtobool_from_user(user_buf, count, &bool_val);
+		ret = kstrtobool_from_iter(from, count, &bool_val);
 		if (ret)
 			return ret;
 
@@ -536,7 +536,7 @@ static ssize_t qmp_debugfs_write(struct file *file, const char __user *user_buf,
 		if (ret >= sizeof(buf))
 			return -EINVAL;
 	} else {
-		ret = kstrtou32_from_user(user_buf, count, 0, &uint_val);
+		ret = kstrtou32_from_iter(from, count, 0, &uint_val);
 		if (ret)
 			return ret;
 
@@ -554,7 +554,7 @@ static ssize_t qmp_debugfs_write(struct file *file, const char __user *user_buf,
 
 static const struct file_operations qmp_debugfs_fops = {
 	.open = simple_open,
-	.write = qmp_debugfs_write,
+	.write_iter = qmp_debugfs_write,
 };
 
 static void qmp_debugfs_create(struct qmp *qmp)
drivers/soc/qcom/rmtfs_mem.c +19 -19
index df850d073102..065faa808f49 100644
@@ -15,6 +15,7 @@
 #include <linux/uaccess.h>
 #include <linux/io.h>
 #include <linux/firmware/qcom/qcom_scm.h>
+#include <linux/uio.h>
 
 #define QCOM_RMTFS_MEM_DEV_MAX	(MINORMASK + 1)
 #define NUM_MAX_VMIDS		2
@@ -79,40 +80,39 @@ static int qcom_rmtfs_mem_open(struct inode *inode, struct file *filp)
 
 	return 0;
 }
-static ssize_t qcom_rmtfs_mem_read(struct file *filp,
-			      char __user *buf, size_t count, loff_t *f_pos)
+static ssize_t qcom_rmtfs_mem_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct qcom_rmtfs_mem *rmtfs_mem = filp->private_data;
+	struct qcom_rmtfs_mem *rmtfs_mem = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 
-	if (*f_pos >= rmtfs_mem->size)
+	if (iocb->ki_pos >= rmtfs_mem->size)
 		return 0;
 
-	if (*f_pos + count >= rmtfs_mem->size)
-		count = rmtfs_mem->size - *f_pos;
+	if (iocb->ki_pos + count >= rmtfs_mem->size)
+		count = rmtfs_mem->size - iocb->ki_pos;
 
-	if (copy_to_user(buf, rmtfs_mem->base + *f_pos, count))
+	if (!copy_to_iter_full(rmtfs_mem->base + iocb->ki_pos, count, to))
 		return -EFAULT;
 
-	*f_pos += count;
+	iocb->ki_pos += count;
 	return count;
 }
 
-static ssize_t qcom_rmtfs_mem_write(struct file *filp,
-			       const char __user *buf, size_t count,
-			       loff_t *f_pos)
+static ssize_t qcom_rmtfs_mem_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct qcom_rmtfs_mem *rmtfs_mem = filp->private_data;
+	struct qcom_rmtfs_mem *rmtfs_mem = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 
-	if (*f_pos >= rmtfs_mem->size)
+	if (iocb->ki_pos >= rmtfs_mem->size)
 		return 0;
 
-	if (*f_pos + count >= rmtfs_mem->size)
-		count = rmtfs_mem->size - *f_pos;
+	if (iocb->ki_pos + count >= rmtfs_mem->size)
+		count = rmtfs_mem->size - iocb->ki_pos;
 
-	if (copy_from_user(rmtfs_mem->base + *f_pos, buf, count))
+	if (!copy_from_iter_full(rmtfs_mem->base + iocb->ki_pos, count, from))
 		return -EFAULT;
 
-	*f_pos += count;
+	iocb->ki_pos += count;
 	return count;
 }
 
@@ -152,8 +152,8 @@ static int qcom_rmtfs_mem_mmap(struct file *filep, struct vm_area_struct *vma)
 static const struct file_operations qcom_rmtfs_mem_fops = {
 	.owner = THIS_MODULE,
 	.open = qcom_rmtfs_mem_open,
-	.read = qcom_rmtfs_mem_read,
-	.write = qcom_rmtfs_mem_write,
+	.read_iter = qcom_rmtfs_mem_read,
+	.write_iter = qcom_rmtfs_mem_write,
 	.release = qcom_rmtfs_mem_release,
 	.llseek = default_llseek,
 	.mmap = qcom_rmtfs_mem_mmap,
drivers/soc/qcom/socinfo.c +2 -2
index e8ff9819ac47..fbee271d4646 100644
@@ -467,7 +467,7 @@ static int qcom_open_##name(struct inode *inode, struct file *file)	\
 									\
 static const struct file_operations qcom_ ##name## _ops = {		\
 	.open = qcom_open_##name,					\
-	.read = seq_read,						\
+	.read_iter = seq_read_iter,					\
 	.llseek = seq_lseek,						\
 	.release = single_release,					\
 }
@@ -570,7 +570,7 @@ static int open_image_##type(struct inode *inode, struct file *file)	  \
 									  \
 static const struct file_operations qcom_image_##type##_ops = {	  \
 	.open = open_image_##type,					  \
-	.read = seq_read,						  \
+	.read_iter = seq_read_iter,					  \
 	.llseek = seq_lseek,						  \
 	.release = single_release,					  \
 }
Signature · 1 line
2.43.0
author maintainer
#181 lore raw

PATCH 175/437 soc: aspeed: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/soc/aspeed/aspeed-lpc-snoop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/soc/aspeed/aspeed-lpc-snoop.c +2 -1
index 888b5840c015..e807893b1624 100644
@@ -98,6 +98,7 @@ static ssize_t snoop_file_read(struct file *file, char __user *buffer,
 
 	return copied;
 }
+FOPS_READ_ITER_HELPER(snoop_file_read);
 
 static __poll_t snoop_file_poll(struct file *file,
 				    struct poll_table_struct *pt)
@@ -110,7 +111,7 @@ static __poll_t snoop_file_poll(struct file *file,
 
 static const struct file_operations snoop_fops = {
 	.owner  = THIS_MODULE,
-	.read   = snoop_file_read,
+	.read_iter   = snoop_file_read_iter,
 	.poll   = snoop_file_poll,
 	.llseek = noop_llseek,
 };
Signature · 1 line
2.43.0
author maintainer
#182 lore raw

PATCH 176/437 soc: fsl: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/soc/fsl/dpaa2-console.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/soc/fsl/dpaa2-console.c +7 -8
index 6dbc77db7718..c0ababa17763 100644
@@ -189,12 +189,12 @@ static int dpaa2_console_close(struct inode *node, struct file *fp)
 	return 0;
 }
 
-static ssize_t dpaa2_console_read(struct file *fp, char __user *buf,
-				  size_t count, loff_t *f_pos)
+static ssize_t dpaa2_console_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct console_data *cd = fp->private_data;
+	struct console_data *cd = iocb->ki_filp->private_data;
 	size_t bytes = dpaa2_console_size(cd);
 	size_t bytes_end = cd->end_addr - cd->cur_ptr;
+	size_t count = iov_iter_count(to);
 	size_t written = 0;
 	void *kbuf;
 	int err;
@@ -214,18 +214,17 @@ static ssize_t dpaa2_console_read(struct file *fp, char __user *buf,
 
 	if (bytes > bytes_end) {
 		memcpy_fromio(kbuf, cd->cur_ptr, bytes_end);
-		if (copy_to_user(buf, kbuf, bytes_end)) {
+		if (!copy_to_iter_full(kbuf, bytes_end, to)) {
 			err = -EFAULT;
 			goto err_free_buf;
 		}
-		buf += bytes_end;
 		cd->cur_ptr = cd->start_addr;
 		bytes -= bytes_end;
 		written += bytes_end;
 	}
 
 	memcpy_fromio(kbuf, cd->cur_ptr, bytes);
-	if (copy_to_user(buf, kbuf, bytes)) {
+	if (!copy_to_iter_full(kbuf, bytes, to)) {
 		err = -EFAULT;
 		goto err_free_buf;
 	}
@@ -245,7 +244,7 @@ static const struct file_operations dpaa2_mc_console_fops = {
 	.owner          = THIS_MODULE,
 	.open           = dpaa2_mc_console_open,
 	.release        = dpaa2_console_close,
-	.read           = dpaa2_console_read,
+	.read_iter      = dpaa2_console_read,
 };
 
 static struct miscdevice dpaa2_mc_console_dev = {
@@ -258,7 +257,7 @@ static const struct file_operations dpaa2_aiop_console_fops = {
 	.owner          = THIS_MODULE,
 	.open           = dpaa2_aiop_console_open,
 	.release        = dpaa2_console_close,
-	.read           = dpaa2_console_read,
+	.read_iter      = dpaa2_console_read,
 };
 
 static struct miscdevice dpaa2_aiop_console_dev = {
Signature · 1 line
2.43.0
author maintainer
#183 lore raw

PATCH 177/437 soc: mediatek: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/soc/mediatek/mtk-svs.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/soc/mediatek/mtk-svs.c +7 -8
index c832f5c670bc..49e687a96aa0 100644
@@ -149,7 +149,7 @@ static DEFINE_SPINLOCK(svs_lock);
 	static const struct file_operations svs_##name##_debug_fops = {	\
 		.owner = THIS_MODULE,					\
 		.open = svs_##name##_debug_open,			\
-		.read = seq_read,					\
+		.read_iter = seq_read_iter,				\
 		.llseek = seq_lseek,					\
 		.release = single_release,				\
 	}
@@ -164,8 +164,8 @@ static DEFINE_SPINLOCK(svs_lock);
 	static const struct file_operations svs_##name##_debug_fops = {	\
 		.owner = THIS_MODULE,					\
 		.open = svs_##name##_debug_open,			\
-		.read = seq_read,					\
-		.write = svs_##name##_debug_write,			\
+		.read_iter = seq_read_iter,				\
+		.write_iter = svs_##name##_debug_write,			\
 		.llseek = seq_lseek,					\
 		.release = single_release,				\
 	}
@@ -782,19 +782,18 @@ static int svs_enable_debug_show(struct seq_file *m, void *v)
 	return 0;
 }
 
-static ssize_t svs_enable_debug_write(struct file *filp,
-				      const char __user *buffer,
-				      size_t count, loff_t *pos)
+static ssize_t svs_enable_debug_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct svs_bank *svsb = file_inode(filp)->i_private;
+	struct svs_bank *svsb = file_inode(iocb->ki_filp)->i_private;
 	struct svs_platform *svsp = dev_get_drvdata(svsb->dev);
+	size_t count = iov_iter_count(from);
 	int enabled, ret;
 	char *buf = NULL;
 
 	if (count >= PAGE_SIZE)
 		return -EINVAL;
 
-	buf = (char *)memdup_user_nul(buffer, count);
+	buf = iterdup_nul(from, count);
 	if (IS_ERR(buf))
 		return PTR_ERR(buf);
 
Signature · 1 line
2.43.0
author maintainer
#184 lore raw

PATCH 178/437 soc: sifive: ccache: convert to read/write iterators

In reply to Jens Axboe
---
 drivers/cache/sifive_ccache.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cache/sifive_ccache.c +4 -4
index 89ed6cd6b059..bcb6691f8f7c 100644
@@ -71,12 +71,12 @@ enum {
 #ifdef CONFIG_DEBUG_FS
 static struct dentry *sifive_test;
 
-static ssize_t ccache_write(struct file *file, const char __user *data,
-			    size_t count, loff_t *ppos)
+static ssize_t ccache_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	unsigned int val;
 
-	if (kstrtouint_from_user(data, count, 0, &val))
+	if (kstrtouint_from_iter(from, count, 0, &val))
 		return -EINVAL;
 	if ((val < 0xFF) || (val >= 0x10000 && val < 0x100FF))
 		writel(val, ccache_base + SIFIVE_CCACHE_ECCINJECTERR);
@@ -88,7 +88,7 @@ static ssize_t ccache_write(struct file *file, const char __user *data,
 static const struct file_operations ccache_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.write = ccache_write
+	.write_iter = ccache_write
 };
 
 static void setup_sifive_debug(void)
Signature · 1 line
2.43.0
author maintainer
#185 lore raw

PATCH 179/437 drivers/pinctrl: convert to ->read_iter and ->write_iter

In reply to Jens Axboe
---
 drivers/pinctrl/pinmux.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pinctrl/pinmux.c +5 -5
index d924207d629b..c7b229d76d7b 100644
@@ -675,18 +675,18 @@ void pinmux_show_setting(struct seq_file *s,
 DEFINE_SHOW_ATTRIBUTE(pinmux_functions);
 DEFINE_SHOW_ATTRIBUTE(pinmux_pins);
 
-static ssize_t pinmux_select(struct file *file, const char __user *user_buf,
-				   size_t len, loff_t *ppos)
+static ssize_t pinmux_select(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *sfile = file->private_data;
+	struct seq_file *sfile = iocb->ki_filp->private_data;
 	struct pinctrl_dev *pctldev = sfile->private;
 	const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
+	size_t len = iov_iter_count(from);
 	const char *const *groups;
 	char *buf, *gname, *fname;
 	unsigned int num_groups;
 	int fsel, gsel, ret;
 
-	buf = memdup_user_nul(user_buf, len);
+	buf = iterdup_nul(from, len);
 	if (IS_ERR(buf))
 		return PTR_ERR(buf);
 
@@ -758,7 +758,7 @@ static int pinmux_select_open(struct inode *inode, struct file *file)
 static const struct file_operations pinmux_select_ops = {
 	.owner = THIS_MODULE,
 	.open = pinmux_select_open,
-	.write = pinmux_select,
+	.write_iter = pinmux_select,
 	.llseek = no_llseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#186 lore raw

PATCH 180/437 drivers/phy: convert to ->read_iter and ->write_iter

In reply to Jens Axboe
---
 drivers/phy/mediatek/phy-mtk-tphy.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/phy/mediatek/phy-mtk-tphy.c +14 -14
index 25b86bbb9cec..8c57e2d89415 100644
@@ -448,19 +448,19 @@ static int u2_phy_params_open(struct inode *inode, struct file *file)
 	return single_open(file, u2_phy_params_show, inode->i_private);
 }
 
-static ssize_t u2_phy_params_write(struct file *file, const char __user *ubuf,
-				   size_t count, loff_t *ppos)
+static ssize_t u2_phy_params_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	const char *fname = file_dentry(file)->d_iname;
-	struct seq_file *sf = file->private_data;
+	const char *fname = file_dentry(iocb->ki_filp)->d_iname;
+	struct seq_file *sf = iocb->ki_filp->private_data;
 	struct mtk_phy_instance *inst = sf->private;
 	struct u2phy_banks *u2_banks = &inst->u2_banks;
+	size_t count = iov_iter_count(from);
 	void __iomem *com = u2_banks->com;
 	ssize_t rc;
 	u32 val;
 	int ret;
 
-	rc = kstrtouint_from_user(ubuf, USER_BUF_LEN(count), 0, &val);
+	rc = kstrtouint_from_iter(from, USER_BUF_LEN(count), 0, &val);
 	if (rc)
 		return rc;
 
@@ -504,8 +504,8 @@ static ssize_t u2_phy_params_write(struct file *file, const char __user *ubuf,
 
 static const struct file_operations u2_phy_fops = {
 	.open = u2_phy_params_open,
-	.write = u2_phy_params_write,
-	.read = seq_read,
+	.write_iter = u2_phy_params_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
@@ -574,19 +574,19 @@ static int u3_phy_params_open(struct inode *inode, struct file *file)
 	return single_open(file, u3_phy_params_show, inode->i_private);
 }
 
-static ssize_t u3_phy_params_write(struct file *file, const char __user *ubuf,
-				   size_t count, loff_t *ppos)
+static ssize_t u3_phy_params_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	const char *fname = file_dentry(file)->d_iname;
-	struct seq_file *sf = file->private_data;
+	const char *fname = file_dentry(iocb->ki_filp)->d_iname;
+	struct seq_file *sf = iocb->ki_filp->private_data;
 	struct mtk_phy_instance *inst = sf->private;
 	struct u3phy_banks *u3_banks = &inst->u3_banks;
 	void __iomem *phyd = u3_banks->phyd;
+	size_t count = iov_iter_count(from);
 	ssize_t rc;
 	u32 val;
 	int ret;
 
-	rc = kstrtouint_from_user(ubuf, USER_BUF_LEN(count), 0, &val);
+	rc = kstrtouint_from_iter(from, USER_BUF_LEN(count), 0, &val);
 	if (rc)
 		return rc;
 
@@ -624,8 +624,8 @@ static ssize_t u3_phy_params_write(struct file *file, const char __user *ubuf,
 
 static const struct file_operations u3_phy_fops = {
 	.open = u3_phy_params_open,
-	.write = u3_phy_params_write,
-	.read = seq_read,
+	.write_iter = u3_phy_params_write,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#187 lore raw

PATCH 181/437 drivers/ufs: convert to ->read_iter and ->write_iter

In reply to Jens Axboe
---
 drivers/ufs/core/ufs-debugfs.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/ufs/core/ufs-debugfs.c +7 -7
index e3baed6c70bd..6f5116d024f3 100644
@@ -157,17 +157,17 @@ static int ufs_saved_err_show(struct seq_file *s, void *data)
 	return 0;
 }
 
-static ssize_t ufs_saved_err_write(struct file *file, const char __user *buf,
-				   size_t count, loff_t *ppos)
+static ssize_t ufs_saved_err_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct ufs_debugfs_attr *attr = file->f_inode->i_private;
-	struct ufs_hba *hba = hba_from_file(file);
+	struct ufs_debugfs_attr *attr = iocb->ki_filp->f_inode->i_private;
+	struct ufs_hba *hba = hba_from_file(iocb->ki_filp);
+	size_t count = iov_iter_count(from);
 	char val_str[16] = { };
 	int val, ret;
 
 	if (count > sizeof(val_str))
 		return -EINVAL;
-	if (copy_from_user(val_str, buf, count))
+	if (!copy_from_iter_full(val_str, count, from))
 		return -EFAULT;
 	ret = kstrtoint(val_str, 0, &val);
 	if (ret < 0)
@@ -196,8 +196,8 @@ static int ufs_saved_err_open(struct inode *inode, struct file *file)
 static const struct file_operations ufs_saved_err_fops = {
 	.owner		= THIS_MODULE,
 	.open		= ufs_saved_err_open,
-	.read		= seq_read,
-	.write		= ufs_saved_err_write,
+	.read_iter	= seq_read_iter,
+	.write_iter	= ufs_saved_err_write,
 	.llseek		= seq_lseek,
 	.release	= single_release,
 };
Signature · 1 line
2.43.0
author maintainer
#188 lore raw

PATCH 182/437 drivers/uio: convert to ->read_iter and ->write_iter

In reply to Jens Axboe
---
 drivers/uio/uio.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/uio/uio.c +11 -11
index 009158fef2a8..510d3707e694 100644
@@ -563,10 +563,10 @@ static __poll_t uio_poll(struct file *filep, poll_table *wait)
 	return 0;
 }
 
-static ssize_t uio_read(struct file *filep, char __user *buf,
-			size_t count, loff_t *ppos)
+static ssize_t uio_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct uio_listener *listener = filep->private_data;
+	struct uio_listener *listener = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	struct uio_device *idev = listener->dev;
 	DECLARE_WAITQUEUE(wait, current);
 	ssize_t retval = 0;
@@ -591,7 +591,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
 		event_count = atomic_read(&idev->event);
 		if (event_count != listener->event_count) {
 			__set_current_state(TASK_RUNNING);
-			if (copy_to_user(buf, &event_count, count))
+			if (!copy_to_iter_full(&event_count, count, to))
 				retval = -EFAULT;
 			else {
 				listener->event_count = event_count;
@@ -600,7 +600,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
 			break;
 		}
 
-		if (filep->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
 			break;
 		}
@@ -618,18 +618,18 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
 	return retval;
 }
 
-static ssize_t uio_write(struct file *filep, const char __user *buf,
-			size_t count, loff_t *ppos)
+static ssize_t uio_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct uio_listener *listener = filep->private_data;
+	struct uio_listener *listener = iocb->ki_filp->private_data;
 	struct uio_device *idev = listener->dev;
+	size_t count = iov_iter_count(from);
 	ssize_t retval;
 	s32 irq_on;
 
 	if (count != sizeof(s32))
 		return -EINVAL;
 
-	if (copy_from_user(&irq_on, buf, count))
+	if (!copy_from_iter_full(&irq_on, count, from))
 		return -EFAULT;
 
 	mutex_lock(&idev->info_lock);
@@ -866,8 +866,8 @@ static const struct file_operations uio_fops = {
 	.owner		= THIS_MODULE,
 	.open		= uio_open,
 	.release	= uio_release,
-	.read		= uio_read,
-	.write		= uio_write,
+	.read_iter	= uio_read,
+	.write_iter	= uio_write,
 	.mmap		= uio_mmap,
 	.poll		= uio_poll,
 	.fasync		= uio_fasync,
Signature · 1 line
2.43.0