[PATCH 122/437] drivers/pci: convert to read/write iterators
From: Jens Axboe
Date: Thu Apr 11 2024 - 12:07:46 EST
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
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(-)
diff --git a/drivers/pci/pcie/aer_inject.c b/drivers/pci/pcie/aer_inject.c
index 2dab275d252f..869abe6a82ab 100644
--- a/drivers/pci/pcie/aer_inject.c
+++ b/drivers/pci/pcie/aer_inject.c
@@ -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,
};
diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index 5a4adf6c04cf..db6f578e854c 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -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,
diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c
index 78748e8d2dba..a5051fae9bcb 100644
--- a/drivers/pci/vgaarb.c
+++ b/drivers/pci/vgaarb.c
@@ -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,
--
2.43.0