[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-377-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:18:36 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 376/437] drivers/fsi: convert to read/write iterators
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
drivers/fsi/fsi-core.c | 28 ++++++++++++++--------------
drivers/fsi/fsi-occ.c | 20 ++++++++++----------
drivers/fsi/fsi-sbefifo.c | 6 ++++--
drivers/fsi/fsi-scom.c | 24 ++++++++++++------------
drivers/fsi/i2cr-scom.c | 23 ++++++++++++-----------
5 files changed, 52 insertions(+), 49 deletions(-)
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 097d5a780264..ce68c470d30e 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -657,12 +657,12 @@ static struct device_node *fsi_slave_find_of_node(struct fsi_master *master,
return NULL;
}
-static ssize_t cfam_read(struct file *filep, char __user *buf, size_t count,
- loff_t *offset)
+static ssize_t cfam_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct fsi_slave *slave = filep->private_data;
+ struct fsi_slave *slave = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(to);
size_t total_len, read_len;
- loff_t off = *offset;
+ loff_t off = iocb->ki_pos;
ssize_t rc;
if (off < 0)
@@ -680,7 +680,7 @@ static ssize_t cfam_read(struct file *filep, char __user *buf, size_t count,
rc = fsi_slave_read(slave, off, &data, read_len);
if (rc)
goto fail;
- rc = copy_to_user(buf + total_len, &data, read_len);
+ rc = !copy_to_iter_full(&data, read_len, to);
if (rc) {
rc = -EFAULT;
goto fail;
@@ -689,16 +689,16 @@ static ssize_t cfam_read(struct file *filep, char __user *buf, size_t count,
}
rc = count;
fail:
- *offset = off;
+ iocb->ki_pos = off;
return rc;
}
-static ssize_t cfam_write(struct file *filep, const char __user *buf,
- size_t count, loff_t *offset)
+static ssize_t cfam_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct fsi_slave *slave = filep->private_data;
+ struct fsi_slave *slave = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
size_t total_len, write_len;
- loff_t off = *offset;
+ loff_t off = iocb->ki_pos;
ssize_t rc;
@@ -714,7 +714,7 @@ static ssize_t cfam_write(struct file *filep, const char __user *buf,
write_len = min_t(size_t, count, 4);
write_len -= off & 0x3;
- rc = copy_from_user(&data, buf + total_len, write_len);
+ rc = !copy_from_iter_full(&data, write_len, from);
if (rc) {
rc = -EFAULT;
goto fail;
@@ -726,7 +726,7 @@ static ssize_t cfam_write(struct file *filep, const char __user *buf,
}
rc = count;
fail:
- *offset = off;
+ iocb->ki_pos = off;
return rc;
}
@@ -758,8 +758,8 @@ static const struct file_operations cfam_fops = {
.owner = THIS_MODULE,
.open = cfam_open,
.llseek = cfam_llseek,
- .read = cfam_read,
- .write = cfam_write,
+ .read_iter = cfam_read,
+ .write_iter = cfam_write,
};
static ssize_t send_term_store(struct device *dev,
diff --git a/drivers/fsi/fsi-occ.c b/drivers/fsi/fsi-occ.c
index da35ca9e84a6..1145df7dbec8 100644
--- a/drivers/fsi/fsi-occ.c
+++ b/drivers/fsi/fsi-occ.c
@@ -104,10 +104,10 @@ static int occ_open(struct inode *inode, struct file *file)
return 0;
}
-static ssize_t occ_read(struct file *file, char __user *buf, size_t len,
- loff_t *offset)
+static ssize_t occ_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct occ_client *client = file->private_data;
+ struct occ_client *client = iocb->ki_filp->private_data;
+ size_t len = iov_iter_count(to);
ssize_t rc = 0;
if (!client)
@@ -126,7 +126,7 @@ static ssize_t occ_read(struct file *file, char __user *buf, size_t len,
/* Grab how much data we have to read */
rc = min(len, client->data_size - client->read_offset);
- if (copy_to_user(buf, client->buffer + client->read_offset, rc))
+ if (!copy_to_iter_full(client->buffer + client->read_offset, rc, to))
rc = -EFAULT;
else
client->read_offset += rc;
@@ -137,10 +137,10 @@ static ssize_t occ_read(struct file *file, char __user *buf, size_t len,
return rc;
}
-static ssize_t occ_write(struct file *file, const char __user *buf,
- size_t len, loff_t *offset)
+static ssize_t occ_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct occ_client *client = file->private_data;
+ struct occ_client *client = iocb->ki_filp->private_data;
+ size_t len = iov_iter_count(from);
size_t rlen, data_length;
ssize_t rc;
u8 *cmd;
@@ -163,7 +163,7 @@ static ssize_t occ_write(struct file *file, const char __user *buf,
* bytes 1-2: data length (msb first)
* bytes 3-n: data
*/
- if (copy_from_user(&cmd[1], buf, len)) {
+ if (!copy_from_iter_full(&cmd[1], len, from)) {
rc = -EFAULT;
goto done;
}
@@ -209,8 +209,8 @@ static int occ_release(struct inode *inode, struct file *file)
static const struct file_operations occ_fops = {
.owner = THIS_MODULE,
.open = occ_open,
- .read = occ_read,
- .write = occ_write,
+ .read_iter = occ_read,
+ .write_iter = occ_write,
.release = occ_release,
};
diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c
index 0a98517f3959..0fe2e4730b4b 100644
--- a/drivers/fsi/fsi-sbefifo.c
+++ b/drivers/fsi/fsi-sbefifo.c
@@ -864,6 +864,7 @@ static ssize_t sbefifo_user_read(struct file *file, char __user *buf,
mutex_unlock(&user->file_lock);
return rc;
}
+FOPS_READ_ITER_HELPER(sbefifo_user_read);
static ssize_t sbefifo_user_write(struct file *file, const char __user *buf,
size_t len, loff_t *offset)
@@ -927,6 +928,7 @@ static ssize_t sbefifo_user_write(struct file *file, const char __user *buf,
/* And that's it, we'll issue the command on a read */
return rc;
}
+FOPS_WRITE_ITER_HELPER(sbefifo_user_write);
static int sbefifo_user_release(struct inode *inode, struct file *file)
{
@@ -1004,8 +1006,8 @@ static long sbefifo_user_ioctl(struct file *file, unsigned int cmd, unsigned lon
static const struct file_operations sbefifo_fops = {
.owner = THIS_MODULE,
.open = sbefifo_user_open,
- .read = sbefifo_user_read,
- .write = sbefifo_user_write,
+ .read_iter = sbefifo_user_read_iter,
+ .write_iter = sbefifo_user_write_iter,
.release = sbefifo_user_release,
.unlocked_ioctl = sbefifo_user_ioctl,
};
diff --git a/drivers/fsi/fsi-scom.c b/drivers/fsi/fsi-scom.c
index 61dbda9dbe2b..1e8e5dcdfb39 100644
--- a/drivers/fsi/fsi-scom.c
+++ b/drivers/fsi/fsi-scom.c
@@ -310,11 +310,11 @@ static int get_scom(struct scom_device *scom, uint64_t *value,
>> SCOM_STATUS_PIB_RESP_SHIFT);
}
-static ssize_t scom_read(struct file *filep, char __user *buf, size_t len,
- loff_t *offset)
+static ssize_t scom_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct scom_device *scom = filep->private_data;
+ struct scom_device *scom = iocb->ki_filp->private_data;
struct device *dev = &scom->fsi_dev->dev;
+ size_t len = iov_iter_count(to);
uint64_t val;
int rc;
@@ -325,32 +325,32 @@ static ssize_t scom_read(struct file *filep, char __user *buf, size_t len,
if (scom->dead)
rc = -ENODEV;
else
- rc = get_scom(scom, &val, *offset);
+ rc = get_scom(scom, &val, iocb->ki_pos);
mutex_unlock(&scom->lock);
if (rc) {
dev_dbg(dev, "get_scom fail:%d\n", rc);
return rc;
}
- rc = copy_to_user(buf, &val, len);
+ rc = !copy_to_iter_full(&val, len, to);
if (rc)
dev_dbg(dev, "copy to user failed:%d\n", rc);
return rc ? rc : len;
}
-static ssize_t scom_write(struct file *filep, const char __user *buf,
- size_t len, loff_t *offset)
+static ssize_t scom_write(struct kiocb *iocb, struct iov_iter *from)
{
int rc;
- struct scom_device *scom = filep->private_data;
+ struct scom_device *scom = iocb->ki_filp->private_data;
struct device *dev = &scom->fsi_dev->dev;
+ size_t len = iov_iter_count(from);
uint64_t val;
if (len != sizeof(uint64_t))
return -EINVAL;
- rc = copy_from_user(&val, buf, len);
+ rc = !copy_from_iter_full(&val, len, from);
if (rc) {
dev_dbg(dev, "copy from user failed:%d\n", rc);
return -EINVAL;
@@ -360,7 +360,7 @@ static ssize_t scom_write(struct file *filep, const char __user *buf,
if (scom->dead)
rc = -ENODEV;
else
- rc = put_scom(scom, val, *offset);
+ rc = put_scom(scom, val, iocb->ki_pos);
mutex_unlock(&scom->lock);
if (rc) {
dev_dbg(dev, "put_scom failed with:%d\n", rc);
@@ -514,8 +514,8 @@ static const struct file_operations scom_fops = {
.owner = THIS_MODULE,
.open = scom_open,
.llseek = scom_llseek,
- .read = scom_read,
- .write = scom_write,
+ .read_iter = scom_read,
+ .write_iter = scom_write,
.unlocked_ioctl = scom_ioctl,
};
diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c
index cb7e02213032..e4b3a8310775 100644
--- a/drivers/fsi/i2cr-scom.c
+++ b/drivers/fsi/i2cr-scom.c
@@ -32,41 +32,42 @@ static loff_t i2cr_scom_llseek(struct file *file, loff_t offset, int whence)
return offset;
}
-static ssize_t i2cr_scom_read(struct file *filep, char __user *buf, size_t len, loff_t *offset)
+static ssize_t i2cr_scom_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct i2cr_scom *scom = filep->private_data;
+ struct i2cr_scom *scom = iocb->ki_filp->private_data;
+ size_t len = iov_iter_count(to);
u64 data;
int ret;
if (len != sizeof(data))
return -EINVAL;
- ret = fsi_master_i2cr_read(scom->i2cr, (u32)*offset, &data);
+ ret = fsi_master_i2cr_read(scom->i2cr, (u32)iocb->ki_pos, &data);
if (ret)
return ret;
- ret = copy_to_user(buf, &data, len);
+ ret = !copy_to_iter_full(&data, len, to);
if (ret)
return ret;
return len;
}
-static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_t len,
- loff_t *offset)
+static ssize_t i2cr_scom_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct i2cr_scom *scom = filep->private_data;
+ struct i2cr_scom *scom = iocb->ki_filp->private_data;
+ size_t len = iov_iter_count(from);
u64 data;
int ret;
if (len != sizeof(data))
return -EINVAL;
- ret = copy_from_user(&data, buf, len);
+ ret = !copy_from_iter(&data, len, from);
if (ret)
return ret;
- ret = fsi_master_i2cr_write(scom->i2cr, (u32)*offset, data);
+ ret = fsi_master_i2cr_write(scom->i2cr, (u32)iocb->ki_pos, data);
if (ret)
return ret;
@@ -77,8 +78,8 @@ static const struct file_operations i2cr_scom_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.llseek = i2cr_scom_llseek,
- .read = i2cr_scom_read,
- .write = i2cr_scom_write,
+ .read_iter = i2cr_scom_read,
+ .write_iter = i2cr_scom_write,
};
static int i2cr_scom_probe(struct device *dev)
--
2.43.0
Powered by blists - more mailing lists