[PATCH 108/437] crypto: qat: convert to read/write iterators

Jens Axboe
2024-04-11T15:34:45Z

.../intel/qat/qat_common/adf_cnv_dbgfs.c | 10 ++--
.../intel/qat/qat_common/adf_fw_counters.c | 2 +-
.../qat/qat_common/adf_heartbeat_dbgfs.c | 60 +++++++++----------
.../intel/qat/qat_common/adf_pm_dbgfs.c | 3 +-
.../intel/qat/qat_common/adf_tl_debugfs.c | 18 +++---
5 files changed, 44 insertions(+), 49 deletions(-)

diff --git a/drivers/crypto/intel/qat/qat_common/adf_cnv_dbgfs.c b/drivers/crypto/intel/qat/qat_common/adf_cnv_dbgfs.c
index 627953a72d47..3c6b7d0b2e9d 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_cnv_dbgfs.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_cnv_dbgfs.c
@@ -255,23 +255,21 @@ static int qat_cnv_errors_file_release(struct inode *inode, struct file *file)
static const struct file_operations qat_cnv_fops = {
.owner = THIS_MODULE,
.open = qat_cnv_errors_file_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = qat_cnv_errors_file_release,
};

-static ssize_t no_comp_file_read(struct file *f, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t no_comp_file_read(struct kiocb *iocb, struct iov_iter *to)
{
char *file_msg = "No engine configured for comp\n";

- return simple_read_from_buffer(buf, count, pos, file_msg,
- strlen(file_msg));
+ return simple_copy_to_iter(file_msg, &iocb->ki_pos, strlen(file_msg), to);
}

static const struct file_operations qat_cnv_no_comp_fops = {
.owner = THIS_MODULE,
- .read = no_comp_file_read,
+ .read_iter = no_comp_file_read,
};

void adf_cnv_dbgfs_add(struct adf_accel_dev *accel_dev)
diff --git a/drivers/crypto/intel/qat/qat_common/adf_fw_counters.c b/drivers/crypto/intel/qat/qat_common/adf_fw_counters.c
index 98fb7ccfed9f..f654d698efe9 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_fw_counters.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_fw_counters.c
@@ -224,7 +224,7 @@ static int qat_fw_counters_file_release(struct inode *inode, struct file *file)
static const struct file_operations qat_fw_counters_fops = {
.owner = THIS_MODULE,
.open = qat_fw_counters_file_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = qat_fw_counters_file_release,
};
diff --git a/drivers/crypto/intel/qat/qat_common/adf_heartbeat_dbgfs.c b/drivers/crypto/intel/qat/qat_common/adf_heartbeat_dbgfs.c
index cccdff24b48d..16f4dfdbb434 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_heartbeat_dbgfs.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_heartbeat_dbgfs.c
@@ -19,30 +19,28 @@
#define HB_STATUS_MAX_STRLEN 4
#define HB_STATS_MAX_STRLEN 16

-static ssize_t adf_hb_stats_read(struct file *file, char __user *user_buffer,
- size_t count, loff_t *ppos)
+static ssize_t adf_hb_stats_read(struct kiocb *iocb, struct iov_iter *to)
{
char buf[HB_STATS_MAX_STRLEN];
unsigned int *value;
int len;

- if (*ppos > 0)
+ if (iocb->ki_pos > 0)
return 0;

- value = file->private_data;
+ value = iocb->ki_filp->private_data;
len = scnprintf(buf, sizeof(buf), "%u\n", *value);

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

static const struct file_operations adf_hb_stats_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .read = adf_hb_stats_read,
+ .read_iter = adf_hb_stats_read,
};

-static ssize_t adf_hb_status_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t adf_hb_status_read(struct kiocb *iocb, struct iov_iter *to)
{
enum adf_device_heartbeat_status hb_status;
char ret_str[HB_STATUS_MAX_STRLEN];
@@ -50,10 +48,10 @@ static ssize_t adf_hb_status_read(struct file *file, char __user *user_buf,
int ret_code;
size_t len;

- if (*ppos > 0)
+ if (iocb->ki_pos > 0)
return 0;

- accel_dev = file->private_data;
+ accel_dev = iocb->ki_filp->private_data;
ret_code = HB_OK;

adf_heartbeat_status(accel_dev, &hb_status);
@@ -63,52 +61,50 @@ static ssize_t adf_hb_status_read(struct file *file, char __user *user_buf,

len = scnprintf(ret_str, sizeof(ret_str), "%d\n", ret_code);

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

static const struct file_operations adf_hb_status_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .read = adf_hb_status_read,
+ .read_iter = adf_hb_status_read,
};

-static ssize_t adf_hb_cfg_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t adf_hb_cfg_read(struct kiocb *iocb, struct iov_iter *to)
{
char timer_str[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
struct adf_accel_dev *accel_dev;
unsigned int timer_ms;
int len;

- if (*ppos > 0)
+ if (iocb->ki_pos > 0)
return 0;

- accel_dev = file->private_data;
+ accel_dev = iocb->ki_filp->private_data;
timer_ms = accel_dev->heartbeat->hb_timer;
len = scnprintf(timer_str, sizeof(timer_str), "%u\n", timer_ms);

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

-static ssize_t adf_hb_cfg_write(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t adf_hb_cfg_write(struct kiocb *iocb, struct iov_iter *from)
{
char input_str[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = { };
+ size_t count = iov_iter_count(from);
struct adf_accel_dev *accel_dev;
int ret, written_chars;
unsigned int timer_ms;
u32 ticks;

- accel_dev = file->private_data;
+ accel_dev = iocb->ki_filp->private_data;
timer_ms = ADF_CFG_HB_TIMER_DEFAULT_MS;

/* last byte left as string termination */
if (count > sizeof(input_str) - 1)
return -EINVAL;

- written_chars = simple_write_to_buffer(input_str, sizeof(input_str) - 1,
- ppos, user_buf, count);
+ written_chars = simple_copy_from_iter(input_str, &iocb->ki_pos,
+ sizeof(input_str) - 1, from);
if (written_chars > 0) {
ret = kstrtouint(input_str, 10, &timer_ms);
if (ret) {
@@ -151,23 +147,23 @@ static ssize_t adf_hb_cfg_write(struct file *file, const char __user *user_buf,
static const struct file_operations adf_hb_cfg_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .read = adf_hb_cfg_read,
- .write = adf_hb_cfg_write,
+ .read_iter = adf_hb_cfg_read,
+ .write_iter = adf_hb_cfg_write,
};

-static ssize_t adf_hb_error_inject_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t adf_hb_error_inject_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct adf_accel_dev *accel_dev = file->private_data;
+ struct adf_accel_dev *accel_dev = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
char buf[3];
int ret;

/* last byte left as string termination */
- if (*ppos != 0 || count != 2)
+ if (iocb->ki_pos != 0 || count != 2)
return -EINVAL;

- if (copy_from_user(buf, user_buf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;
buf[count] = '\0';

@@ -190,7 +186,7 @@ static ssize_t adf_hb_error_inject_write(struct file *file,
static const struct file_operations adf_hb_error_inject_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .write = adf_hb_error_inject_write,
+ .write_iter = adf_hb_error_inject_write,
};

void adf_heartbeat_dbgfs_add(struct adf_accel_dev *accel_dev)
diff --git a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs.c b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs.c
index f0a13c190196..95105baa68d0 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs.c
@@ -18,10 +18,11 @@ static ssize_t pm_status_read(struct file *f, char __user *buf, size_t count,

return count;
}
+FOPS_READ_ITER_HELPER(pm_status_read);

static const struct file_operations pm_status_fops = {
.owner = THIS_MODULE,
- .read = pm_status_read,
+ .read_iter = pm_status_read_iter,
};

void adf_pm_dbgfs_add(struct adf_accel_dev *accel_dev)
diff --git a/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c b/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c
index c8241f5a0a26..d3704f41c406 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c
@@ -413,10 +413,10 @@ static int tl_control_show(struct seq_file *s, void *unused)
return 0;
}

-static ssize_t tl_control_write(struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
+static ssize_t tl_control_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *seq_f = file->private_data;
+ struct seq_file *seq_f = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct adf_accel_dev *accel_dev;
struct adf_telemetry *telemetry;
struct adf_tl_hw_data *tl_data;
@@ -434,7 +434,7 @@ static ssize_t tl_control_write(struct file *file, const char __user *userbuf,

mutex_lock(&telemetry->wr_lock);

- ret = kstrtou32_from_user(userbuf, count, 10, &input);
+ ret = kstrtou32_from_iter(from, count, 10, &input);
if (ret)
goto unlock_and_exit;

@@ -627,10 +627,10 @@ static int tl_rp_data_show(struct seq_file *s, void *unused)
return tl_print_rp_data(accel_dev, s, rp_regs_index);
}

-static ssize_t tl_rp_data_write(struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
+static ssize_t tl_rp_data_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *seq_f = file->private_data;
+ struct seq_file *seq_f = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct adf_accel_dev *accel_dev;
struct adf_telemetry *telemetry;
unsigned int new_rp_num;
@@ -647,13 +647,13 @@ static ssize_t tl_rp_data_write(struct file *file, const char __user *userbuf,

mutex_lock(&telemetry->wr_lock);

- ret = get_rp_index_from_file(file, &rp_regs_index, max_rp);
+ ret = get_rp_index_from_file(iocb->ki_filp, &rp_regs_index, max_rp);
if (ret) {
dev_dbg(&GET_DEV(accel_dev), "invalid RP data file name\n");
goto unlock_and_exit;
}

- ret = kstrtou32_from_user(userbuf, count, 10, &new_rp_num);
+ ret = kstrtou32_from_iter(from, count, 10, &new_rp_num);
if (ret)
goto unlock_and_exit;

--
2.43.0