[PATCH 060/437] ASoC: Intel: convert to read/write iterators

Jens Axboe
2024-04-11T15:33:24Z

sound/soc/intel/avs/debugfs.c | 69 +++++++++++++++--------------
sound/soc/intel/avs/pcm.c | 9 ++--
sound/soc/intel/skylake/skl-debug.c | 19 ++++----
3 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/sound/soc/intel/avs/debugfs.c b/sound/soc/intel/avs/debugfs.c
index 4dfbff0ce508..ebab29e5e2bd 100644
--- a/sound/soc/intel/avs/debugfs.c
+++ b/sound/soc/intel/avs/debugfs.c
@@ -48,9 +48,9 @@ void avs_dump_fw_log_wakeup(struct avs_dev *adev, const void __iomem *src, unsig
wake_up(&adev->trace_waitq);
}

-static ssize_t fw_regs_read(struct file *file, char __user *to, size_t count, loff_t *ppos)
+static ssize_t fw_regs_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct avs_dev *adev = file->private_data;
+ struct avs_dev *adev = iocb->ki_filp->private_data;
char *buf;
int ret;

@@ -60,20 +60,20 @@ static ssize_t fw_regs_read(struct file *file, char __user *to, size_t count, lo

memcpy_fromio(buf, avs_sram_addr(adev, AVS_FW_REGS_WINDOW), AVS_FW_REGS_SIZE);

- ret = simple_read_from_buffer(to, count, ppos, buf, AVS_FW_REGS_SIZE);
+ ret = simple_copy_to_iter(buf, &iocb->ki_pos, AVS_FW_REGS_SIZE, to);
kfree(buf);
return ret;
}

static const struct file_operations fw_regs_fops = {
.open = simple_open,
- .read = fw_regs_read,
+ .read_iter = fw_regs_read,
.llseek = no_llseek,
};

-static ssize_t debug_window_read(struct file *file, char __user *to, size_t count, loff_t *ppos)
+static ssize_t debug_window_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct avs_dev *adev = file->private_data;
+ struct avs_dev *adev = iocb->ki_filp->private_data;
size_t size;
char *buf;
int ret;
@@ -85,27 +85,27 @@ static ssize_t debug_window_read(struct file *file, char __user *to, size_t coun

memcpy_fromio(buf, avs_sram_addr(adev, AVS_DEBUG_WINDOW), size);

- ret = simple_read_from_buffer(to, count, ppos, buf, size);
+ ret = simple_copy_to_iter(buf, &iocb->ki_pos, size, to);
kfree(buf);
return ret;
}

static const struct file_operations debug_window_fops = {
.open = simple_open,
- .read = debug_window_read,
+ .read_iter = debug_window_read,
.llseek = no_llseek,
};

-static ssize_t probe_points_read(struct file *file, char __user *to, size_t count, loff_t *ppos)
+static ssize_t probe_points_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct avs_dev *adev = file->private_data;
+ struct avs_dev *adev = iocb->ki_filp->private_data;
struct avs_probe_point_desc *desc;
size_t num_desc, len = 0;
char *buf;
int i, ret;

/* Prevent chaining, send and dump IPC value just once. */
- if (*ppos)
+ if (iocb->ki_pos)
return 0;

buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
@@ -127,7 +127,7 @@ static ssize_t probe_points_read(struct file *file, char __user *to, size_t coun
len += ret;
}

- ret = simple_read_from_buffer(to, count, ppos, buf, len);
+ ret = simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
free_desc:
kfree(desc);
exit:
@@ -135,16 +135,16 @@ static ssize_t probe_points_read(struct file *file, char __user *to, size_t coun
return ret;
}

-static ssize_t probe_points_write(struct file *file, const char __user *from, size_t count,
- loff_t *ppos)
+static ssize_t probe_points_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct avs_dev *adev = file->private_data;
+ struct avs_dev *adev = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct avs_probe_point_desc *desc;
u32 *array, num_elems;
size_t bytes;
int ret;

- ret = parse_int_array_user(from, count, (int **)&array);
+ ret = parse_int_array_iter(from, (int **)&array);
if (ret < 0)
return ret;

@@ -168,21 +168,22 @@ static ssize_t probe_points_write(struct file *file, const char __user *from, si

static const struct file_operations probe_points_fops = {
.open = simple_open,
- .read = probe_points_read,
- .write = probe_points_write,
+ .read_iter = probe_points_read,
+ .write_iter = probe_points_write,
.llseek = no_llseek,
};

-static ssize_t probe_points_disconnect_write(struct file *file, const char __user *from,
- size_t count, loff_t *ppos)
+static ssize_t probe_points_disconnect_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct avs_dev *adev = file->private_data;
+ struct avs_dev *adev = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
union avs_probe_point_id *id;
u32 *array, num_elems;
size_t bytes;
int ret;

- ret = parse_int_array_user(from, count, (int **)&array);
+ ret = parse_int_array_iter(from, (int **)&array);
if (ret < 0)
return ret;

@@ -206,7 +207,7 @@ static ssize_t probe_points_disconnect_write(struct file *file, const char __use

static const struct file_operations probe_points_disconnect_fops = {
.open = simple_open,
- .write = probe_points_disconnect_write,
+ .write_iter = probe_points_disconnect_write,
.llseek = default_llseek,
};

@@ -230,6 +231,7 @@ static ssize_t strace_read(struct file *file, char __user *to, size_t count, lof
*ppos += copied;
return copied;
}
+FOPS_READ_ITER_HELPER(strace_read);

static int strace_open(struct inode *inode, struct file *file)
{
@@ -279,7 +281,7 @@ static int strace_release(struct inode *inode, struct file *file)

static const struct file_operations strace_fops = {
.llseek = default_llseek,
- .read = strace_read,
+ .read_iter = strace_read_iter,
.open = strace_open,
.release = strace_release,
};
@@ -351,26 +353,25 @@ static int disable_logs(struct avs_dev *adev, u32 resource_mask)
return ret;
}

-static ssize_t trace_control_read(struct file *file, char __user *to, size_t count, loff_t *ppos)
+static ssize_t trace_control_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct avs_dev *adev = file->private_data;
+ struct avs_dev *adev = iocb->ki_filp->private_data;
char buf[64];
int len;

len = snprintf(buf, sizeof(buf), "0x%08x\n", adev->logged_resources);
-
- return simple_read_from_buffer(to, count, ppos, buf, len);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
}

-static ssize_t trace_control_write(struct file *file, const char __user *from, size_t count,
- loff_t *ppos)
+static ssize_t trace_control_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct avs_dev *adev = file->private_data;
+ struct avs_dev *adev = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
u32 *array, num_elems;
u32 resource_mask;
int ret;

- ret = parse_int_array_user(from, count, (int **)&array);
+ ret = parse_int_array_iter(from, (int **)&array);
if (ret < 0)
return ret;

@@ -403,8 +404,8 @@ static ssize_t trace_control_write(struct file *file, const char __user *from, s

static const struct file_operations trace_control_fops = {
.llseek = default_llseek,
- .read = trace_control_read,
- .write = trace_control_write,
+ .read_iter = trace_control_read,
+ .write_iter = trace_control_write,
.open = simple_open,
};

diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c
index 2cafbc392cdb..631cb410fdfe 100644
--- a/sound/soc/intel/avs/pcm.c
+++ b/sound/soc/intel/avs/pcm.c
@@ -792,10 +792,9 @@ const struct snd_soc_dai_ops avs_dai_fe_ops = {
.trigger = avs_dai_fe_trigger,
};

-static ssize_t topology_name_read(struct file *file, char __user *user_buf, size_t count,
- loff_t *ppos)
+static ssize_t topology_name_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct snd_soc_component *component = file->private_data;
+ struct snd_soc_component *component = iocb->ki_filp->private_data;
struct snd_soc_card *card = component->card;
struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev);
char buf[64];
@@ -804,12 +803,12 @@ static ssize_t topology_name_read(struct file *file, char __user *user_buf, size
len = scnprintf(buf, sizeof(buf), "%s/%s\n", component->driver->topology_name_prefix,
mach->tplg_filename);

- return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
}

static const struct file_operations topology_name_fops = {
.open = simple_open,
- .read = topology_name_read,
+ .read_iter = topology_name_read,
.llseek = default_llseek,
};

diff --git a/sound/soc/intel/skylake/skl-debug.c b/sound/soc/intel/skylake/skl-debug.c
index a15aa2ffa681..a1715364729d 100644
--- a/sound/soc/intel/skylake/skl-debug.c
+++ b/sound/soc/intel/skylake/skl-debug.c
@@ -64,10 +64,9 @@ static ssize_t skl_print_fmt(struct skl_module_fmt *fmt, char *buf,
fmt->ch_map);
}

-static ssize_t module_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t module_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct skl_module_cfg *mconfig = file->private_data;
+ struct skl_module_cfg *mconfig = iocb->ki_filp->private_data;
struct skl_module *module = mconfig->module;
struct skl_module_res *res = &module->resources[mconfig->res_idx];
char *buf;
@@ -149,7 +148,7 @@ static ssize_t module_read(struct file *file, char __user *user_buf,
mconfig->dma_id, mconfig->mem_pages, mconfig->m_state,
mconfig->m_type);

- ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+ ret = simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);

kfree(buf);
return ret;
@@ -157,7 +156,7 @@ static ssize_t module_read(struct file *file, char __user *user_buf,

static const struct file_operations mcfg_fops = {
.open = simple_open,
- .read = module_read,
+ .read_iter = module_read,
.llseek = default_llseek,
};

@@ -170,10 +169,9 @@ void skl_debug_init_module(struct skl_debug *d,
&mcfg_fops);
}

-static ssize_t fw_softreg_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t fw_softreg_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct skl_debug *d = file->private_data;
+ struct skl_debug *d = iocb->ki_filp->private_data;
struct sst_dsp *sst = d->skl->dsp;
size_t w0_stat_sz = sst->addr.w0_stat_sz;
void __iomem *in_base = sst->mailbox.in_base;
@@ -203,15 +201,14 @@ static ssize_t fw_softreg_read(struct file *file, char __user *user_buf,
tmp[ret++] = '\n';
}

- ret = simple_read_from_buffer(user_buf, count, ppos, tmp, ret);
+ ret = simple_copy_to_iter(tmp, &iocb->ki_pos, ret, to);
kfree(tmp);
-
return ret;
}

static const struct file_operations soft_regs_ctrl_fops = {
.open = simple_open,
- .read = fw_softreg_read,
+ .read_iter = fw_softreg_read,
.llseek = default_llseek,
};

--
2.43.0