[PATCH 075/437] kernel/power: convert to read/write iterators

From: Jens Axboe
Date: Thu Apr 11 2024 - 12:02:54 EST


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
kernel/power/qos.c | 21 ++++++++++-----------
kernel/power/user.c | 28 ++++++++++++----------------
2 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index 4244b069442e..eeea74bc639a 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -363,10 +363,9 @@ static int cpu_latency_qos_release(struct inode *inode, struct file *filp)
return 0;
}

-static ssize_t cpu_latency_qos_read(struct file *filp, char __user *buf,
- size_t count, loff_t *f_pos)
+static ssize_t cpu_latency_qos_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct pm_qos_request *req = filp->private_data;
+ struct pm_qos_request *req = iocb->ki_filp->private_data;
unsigned long flags;
s32 value;

@@ -377,33 +376,33 @@ static ssize_t cpu_latency_qos_read(struct file *filp, char __user *buf,
value = pm_qos_get_value(&cpu_latency_constraints);
spin_unlock_irqrestore(&pm_qos_lock, flags);

- return simple_read_from_buffer(buf, count, f_pos, &value, sizeof(s32));
+ return simple_copy_to_iter(&value, &iocb->ki_pos, sizeof(s32), to);
}

-static ssize_t cpu_latency_qos_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *f_pos)
+static ssize_t cpu_latency_qos_write(struct kiocb *iocb, struct iov_iter *from)
{
+ size_t count = iov_iter_count(from);
s32 value;

if (count == sizeof(s32)) {
- if (copy_from_user(&value, buf, sizeof(s32)))
+ if (!copy_from_iter_full(&value, sizeof(s32), from))
return -EFAULT;
} else {
int ret;

- ret = kstrtos32_from_user(buf, count, 16, &value);
+ ret = kstrtos32_from_iter(from, count, 16, &value);
if (ret)
return ret;
}

- cpu_latency_qos_update_request(filp->private_data, value);
+ cpu_latency_qos_update_request(iocb->ki_filp->private_data, value);

return count;
}

static const struct file_operations cpu_latency_qos_fops = {
- .write = cpu_latency_qos_write,
- .read = cpu_latency_qos_read,
+ .write_iter = cpu_latency_qos_write,
+ .read_iter = cpu_latency_qos_read,
.open = cpu_latency_qos_open,
.release = cpu_latency_qos_release,
.llseek = noop_llseek,
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 3aa41ba22129..1dcdfbf240a9 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -131,17 +131,16 @@ static int snapshot_release(struct inode *inode, struct file *filp)
return 0;
}

-static ssize_t snapshot_read(struct file *filp, char __user *buf,
- size_t count, loff_t *offp)
+static ssize_t snapshot_read(struct kiocb *iocb, struct iov_iter *to)
{
- loff_t pg_offp = *offp & ~PAGE_MASK;
+ loff_t pg_offp = iocb->ki_pos & ~PAGE_MASK;
struct snapshot_data *data;
unsigned int sleep_flags;
ssize_t res;

sleep_flags = lock_system_sleep();

- data = filp->private_data;
+ data = iocb->ki_filp->private_data;
if (!data->ready) {
res = -ENODATA;
goto Unlock;
@@ -154,10 +153,9 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
res = PAGE_SIZE - pg_offp;
}

- res = simple_read_from_buffer(buf, count, &pg_offp,
- data_of(data->handle), res);
+ res = simple_copy_to_iter(data_of(data->handle), &iocb->ki_pos, res, to);
if (res > 0)
- *offp += res;
+ iocb->ki_pos += res;

Unlock:
unlock_system_sleep(sleep_flags);
@@ -165,10 +163,9 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
return res;
}

-static ssize_t snapshot_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *offp)
+static ssize_t snapshot_write(struct kiocb *iocb, struct iov_iter *from)
{
- loff_t pg_offp = *offp & ~PAGE_MASK;
+ loff_t pg_offp = iocb->ki_pos & ~PAGE_MASK;
struct snapshot_data *data;
unsigned long sleep_flags;
ssize_t res;
@@ -180,7 +177,7 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,

sleep_flags = lock_system_sleep();

- data = filp->private_data;
+ data = iocb->ki_filp->private_data;

if (!pg_offp) {
res = snapshot_write_next(&data->handle);
@@ -195,10 +192,9 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
goto unlock;
}

- res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp,
- buf, count);
+ res = simple_copy_from_iter(data_of(data->handle), &iocb->ki_pos, res, from);
if (res > 0)
- *offp += res;
+ iocb->ki_pos += res;
unlock:
unlock_system_sleep(sleep_flags);

@@ -445,8 +441,8 @@ snapshot_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
static const struct file_operations snapshot_fops = {
.open = snapshot_open,
.release = snapshot_release,
- .read = snapshot_read,
- .write = snapshot_write,
+ .read_iter = snapshot_read,
+ .write_iter = snapshot_write,
.llseek = no_llseek,
.unlocked_ioctl = snapshot_ioctl,
#ifdef CONFIG_COMPAT
--
2.43.0