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-399-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:18:58 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 398/437] macintosh: smu: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/macintosh/smu.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index b2b78a53e532..c66fcb746123 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -1111,17 +1111,17 @@ static void smu_user_cmd_done(struct smu_cmd *cmd, void *misc)
 }
 
 
-static ssize_t smu_write(struct file *file, const char __user *buf,
-			 size_t count, loff_t *ppos)
+static ssize_t smu_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct smu_private *pp = file->private_data;
+	struct smu_private *pp = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	unsigned long flags;
 	struct smu_user_cmd_hdr hdr;
 	int rc = 0;
 
 	if (pp->busy)
 		return -EBUSY;
-	else if (copy_from_user(&hdr, buf, sizeof(hdr)))
+	else if (!copy_from_iter_full(&hdr, sizeof(hdr), from))
 		return -EFAULT;
 	else if (hdr.cmdtype == SMU_CMDTYPE_WANTS_EVENTS) {
 		pp->mode = smu_file_events;
@@ -1150,7 +1150,7 @@ static ssize_t smu_write(struct file *file, const char __user *buf,
 	pp->cmd.status = 1;
 	spin_unlock_irqrestore(&pp->lock, flags);
 
-	if (copy_from_user(pp->buffer, buf + sizeof(hdr), hdr.data_len)) {
+	if (!copy_from_iter_full(pp->buffer, hdr.data_len, from)) {
 		pp->busy = 0;
 		return -EFAULT;
 	}
@@ -1168,10 +1168,10 @@ static ssize_t smu_write(struct file *file, const char __user *buf,
 	return count;
 }
 
-
-static ssize_t smu_read_command(struct file *file, struct smu_private *pp,
-				char __user *buf, size_t count)
+static ssize_t smu_read_command(struct smu_private *pp, struct kiocb *iocb,
+				struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	DECLARE_WAITQUEUE(wait, current);
 	struct smu_user_reply_hdr hdr;
 	unsigned long flags;
@@ -1183,7 +1183,7 @@ static ssize_t smu_read_command(struct file *file, struct smu_private *pp,
 		return -EOVERFLOW;
 	spin_lock_irqsave(&pp->lock, flags);
 	if (pp->cmd.status == 1) {
-		if (file->f_flags & O_NONBLOCK) {
+		if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 			spin_unlock_irqrestore(&pp->lock, flags);
 			return -EAGAIN;
 		}
@@ -1214,35 +1214,31 @@ static ssize_t smu_read_command(struct file *file, struct smu_private *pp,
 	rc = size;
 	hdr.status = pp->cmd.status;
 	hdr.reply_len = pp->cmd.reply_len;
-	if (copy_to_user(buf, &hdr, sizeof(hdr)))
+	if (!copy_to_iter_full(&hdr, sizeof(hdr), to))
 		return -EFAULT;
 	size -= sizeof(hdr);
-	if (size && copy_to_user(buf + sizeof(hdr), pp->buffer, size))
+	if (size && !copy_to_iter_full(pp->buffer, size, to))
 		return -EFAULT;
 	pp->busy = 0;
 
 	return rc;
 }
 
-
-static ssize_t smu_read_events(struct file *file, struct smu_private *pp,
-			       char __user *buf, size_t count)
+static ssize_t smu_read_events(void)
 {
 	/* Not implemented */
 	msleep_interruptible(1000);
 	return 0;
 }
 
-
-static ssize_t smu_read(struct file *file, char __user *buf,
-			size_t count, loff_t *ppos)
+static ssize_t smu_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct smu_private *pp = file->private_data;
+	struct smu_private *pp = iocb->ki_filp->private_data;
 
 	if (pp->mode == smu_file_commands)
-		return smu_read_command(file, pp, buf, count);
+		return smu_read_command(pp, iocb, to);
 	if (pp->mode == smu_file_events)
-		return smu_read_events(file, pp, buf, count);
+		return smu_read_events();
 
 	return -EBADFD;
 }
@@ -1315,8 +1311,8 @@ static int smu_release(struct inode *inode, struct file *file)
 
 static const struct file_operations smu_device_fops = {
 	.llseek		= no_llseek,
-	.read		= smu_read,
-	.write		= smu_write,
+	.read_iter	= smu_read,
+	.write_iter	= smu_write,
 	.poll		= smu_fpoll,
 	.open		= smu_open,
 	.release	= smu_release,
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ