lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-318-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:17:37 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 317/437] drivers/net/wwan: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/net/wwan/iosm/iosm_ipc_trace.c | 21 ++++++-------
 drivers/net/wwan/wwan_core.c           | 26 ++++++++--------
 drivers/net/wwan/wwan_hwsim.c          | 42 ++++++++++++--------------
 3 files changed, 42 insertions(+), 47 deletions(-)

diff --git a/drivers/net/wwan/iosm/iosm_ipc_trace.c b/drivers/net/wwan/iosm/iosm_ipc_trace.c
index eeecfa3d10c5..8374bd4826bc 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_trace.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_trace.c
@@ -70,10 +70,9 @@ static struct rchan_callbacks relay_callbacks = {
 };
 
 /* Copy the trace control mode to user buffer */
-static ssize_t ipc_trace_ctrl_file_read(struct file *filp, char __user *buffer,
-					size_t count, loff_t *ppos)
+static ssize_t ipc_trace_ctrl_file_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct iosm_trace *ipc_trace = filp->private_data;
+	struct iosm_trace *ipc_trace = iocb->ki_filp->private_data;
 	char buf[16];
 	int len;
 
@@ -81,19 +80,19 @@ static ssize_t ipc_trace_ctrl_file_read(struct file *filp, char __user *buffer,
 	len = snprintf(buf, sizeof(buf), "%d\n", ipc_trace->mode);
 	mutex_unlock(&ipc_trace->trc_mutex);
 
-	return simple_read_from_buffer(buffer, count, ppos, buf, len);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 }
 
 /* Open and close the trace channel depending on user input */
-static ssize_t ipc_trace_ctrl_file_write(struct file *filp,
-					 const char __user *buffer,
-					 size_t count, loff_t *ppos)
+static ssize_t ipc_trace_ctrl_file_write(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct iosm_trace *ipc_trace = filp->private_data;
+	struct iosm_trace *ipc_trace = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	unsigned long val;
 	int ret;
 
-	ret = kstrtoul_from_user(buffer, count, 10, &val);
+	ret = kstrtoul_from_iter(from, count, 10, &val);
 	if (ret)
 		return ret;
 
@@ -122,8 +121,8 @@ static ssize_t ipc_trace_ctrl_file_write(struct file *filp,
 
 static const struct file_operations ipc_trace_fops = {
 	.open = simple_open,
-	.write = ipc_trace_ctrl_file_write,
-	.read  = ipc_trace_ctrl_file_read,
+	.write_iter = ipc_trace_ctrl_file_write,
+	.read_iter  = ipc_trace_ctrl_file_read,
 };
 
 /**
diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c
index 17431f1b1a0c..1007d0255427 100644
--- a/drivers/net/wwan/wwan_core.c
+++ b/drivers/net/wwan/wwan_core.c
@@ -684,15 +684,15 @@ static int wwan_port_fops_release(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static ssize_t wwan_port_fops_read(struct file *filp, char __user *buf,
-				   size_t count, loff_t *ppos)
+static ssize_t wwan_port_fops_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct wwan_port *port = filp->private_data;
+	struct wwan_port *port = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	struct sk_buff *skb;
 	size_t copied;
 	int ret;
 
-	ret = wwan_wait_rx(port, !!(filp->f_flags & O_NONBLOCK));
+	ret = wwan_wait_rx(port, !!(iocb->ki_filp->f_flags & O_NONBLOCK));
 	if (ret)
 		return ret;
 
@@ -701,7 +701,7 @@ static ssize_t wwan_port_fops_read(struct file *filp, char __user *buf,
 		return -EIO;
 
 	copied = min_t(size_t, count, skb->len);
-	if (copy_to_user(buf, skb->data, copied)) {
+	if (!copy_to_iter_full(skb->data, copied, to)) {
 		kfree_skb(skb);
 		return -EFAULT;
 	}
@@ -716,15 +716,15 @@ static ssize_t wwan_port_fops_read(struct file *filp, char __user *buf,
 	return copied;
 }
 
-static ssize_t wwan_port_fops_write(struct file *filp, const char __user *buf,
-				    size_t count, loff_t *offp)
+static ssize_t wwan_port_fops_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	struct sk_buff *skb, *head = NULL, *tail = NULL;
-	struct wwan_port *port = filp->private_data;
+	struct wwan_port *port = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	size_t frag_len, remain = count;
 	int ret;
 
-	ret = wwan_wait_tx(port, !!(filp->f_flags & O_NONBLOCK));
+	ret = wwan_wait_tx(port, !!(iocb->ki_filp->f_flags & O_NONBLOCK));
 	if (ret)
 		return ret;
 
@@ -747,7 +747,7 @@ static ssize_t wwan_port_fops_write(struct file *filp, const char __user *buf,
 			tail = skb;
 		}
 
-		if (copy_from_user(skb_put(skb, frag_len), buf + count - remain, frag_len)) {
+		if (!copy_from_iter_full(skb_put(skb, frag_len), frag_len, from)) {
 			ret = -EFAULT;
 			goto freeskb;
 		}
@@ -759,7 +759,7 @@ static ssize_t wwan_port_fops_write(struct file *filp, const char __user *buf,
 		}
 	} while (remain -= frag_len);
 
-	ret = wwan_port_op_tx(port, head, !!(filp->f_flags & O_NONBLOCK));
+	ret = wwan_port_op_tx(port, head, !!(iocb->ki_filp->f_flags & O_NONBLOCK));
 	if (!ret)
 		return count;
 
@@ -897,8 +897,8 @@ static const struct file_operations wwan_port_fops = {
 	.owner = THIS_MODULE,
 	.open = wwan_port_fops_open,
 	.release = wwan_port_fops_release,
-	.read = wwan_port_fops_read,
-	.write = wwan_port_fops_write,
+	.read_iter = wwan_port_fops_read,
+	.write_iter = wwan_port_fops_write,
 	.poll = wwan_port_fops_poll,
 	.unlocked_ioctl = wwan_port_fops_ioctl,
 #ifdef CONFIG_COMPAT
diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c
index b02befd1b6fb..7bf9a275b3c0 100644
--- a/drivers/net/wwan/wwan_hwsim.c
+++ b/drivers/net/wwan/wwan_hwsim.c
@@ -364,11 +364,10 @@ static void wwan_hwsim_dev_del_work(struct work_struct *work)
 	wwan_hwsim_dev_del(dev);
 }
 
-static ssize_t wwan_hwsim_debugfs_portdestroy_write(struct file *file,
-						    const char __user *usrbuf,
-						    size_t count, loff_t *ppos)
+static ssize_t wwan_hwsim_debugfs_portdestroy_write(struct kiocb *iocb,
+						    struct iov_iter *from)
 {
-	struct wwan_hwsim_port *port = file->private_data;
+	struct wwan_hwsim_port *port = iocb->ki_filp->private_data;
 
 	/* We can not delete port here since it will cause a deadlock due to
 	 * waiting this callback to finish in the debugfs_remove() call. So,
@@ -376,20 +375,19 @@ static ssize_t wwan_hwsim_debugfs_portdestroy_write(struct file *file,
 	 */
 	queue_work(wwan_wq, &port->del_work);
 
-	return count;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations wwan_hwsim_debugfs_portdestroy_fops = {
-	.write = wwan_hwsim_debugfs_portdestroy_write,
+	.write_iter = wwan_hwsim_debugfs_portdestroy_write,
 	.open = simple_open,
 	.llseek = noop_llseek,
 };
 
-static ssize_t wwan_hwsim_debugfs_portcreate_write(struct file *file,
-						   const char __user *usrbuf,
-						   size_t count, loff_t *ppos)
+static ssize_t wwan_hwsim_debugfs_portcreate_write(struct kiocb *iocb,
+						   struct iov_iter *from)
 {
-	struct wwan_hwsim_dev *dev = file->private_data;
+	struct wwan_hwsim_dev *dev = iocb->ki_filp->private_data;
 	struct wwan_hwsim_port *port;
 
 	port = wwan_hwsim_port_new(dev);
@@ -400,20 +398,19 @@ static ssize_t wwan_hwsim_debugfs_portcreate_write(struct file *file,
 	list_add_tail(&port->list, &dev->ports);
 	spin_unlock(&dev->ports_lock);
 
-	return count;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations wwan_hwsim_debugfs_portcreate_fops = {
-	.write = wwan_hwsim_debugfs_portcreate_write,
+	.write_iter = wwan_hwsim_debugfs_portcreate_write,
 	.open = simple_open,
 	.llseek = noop_llseek,
 };
 
-static ssize_t wwan_hwsim_debugfs_devdestroy_write(struct file *file,
-						   const char __user *usrbuf,
-						   size_t count, loff_t *ppos)
+static ssize_t wwan_hwsim_debugfs_devdestroy_write(struct kiocb *iocb,
+						   struct iov_iter *from)
 {
-	struct wwan_hwsim_dev *dev = file->private_data;
+	struct wwan_hwsim_dev *dev = iocb->ki_filp->private_data;
 
 	/* We can not delete device here since it will cause a deadlock due to
 	 * waiting this callback to finish in the debugfs_remove() call. So,
@@ -421,18 +418,17 @@ static ssize_t wwan_hwsim_debugfs_devdestroy_write(struct file *file,
 	 */
 	queue_work(wwan_wq, &dev->del_work);
 
-	return count;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations wwan_hwsim_debugfs_devdestroy_fops = {
-	.write = wwan_hwsim_debugfs_devdestroy_write,
+	.write_iter = wwan_hwsim_debugfs_devdestroy_write,
 	.open = simple_open,
 	.llseek = noop_llseek,
 };
 
-static ssize_t wwan_hwsim_debugfs_devcreate_write(struct file *file,
-						  const char __user *usrbuf,
-						  size_t count, loff_t *ppos)
+static ssize_t wwan_hwsim_debugfs_devcreate_write(struct kiocb *iocb,
+						  struct iov_iter *from)
 {
 	struct wwan_hwsim_dev *dev;
 
@@ -444,11 +440,11 @@ static ssize_t wwan_hwsim_debugfs_devcreate_write(struct file *file,
 	list_add_tail(&dev->list, &wwan_hwsim_devs);
 	spin_unlock(&wwan_hwsim_devs_lock);
 
-	return count;
+	return iov_iter_count(from);
 }
 
 static const struct file_operations wwan_hwsim_debugfs_devcreate_fops = {
-	.write = wwan_hwsim_debugfs_devcreate_write,
+	.write_iter = wwan_hwsim_debugfs_devcreate_write,
 	.open = simple_open,
 	.llseek = noop_llseek,
 };
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ