[PATCH 310/437] wifi: rtw89: convert debugfs helpers to read/write iterators

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


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
drivers/net/wireless/realtek/rtw89/debug.c | 155 ++++++++++-----------
1 file changed, 74 insertions(+), 81 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/debug.c b/drivers/net/wireless/realtek/rtw89/debug.c
index affffc4092ba..20d8774f151a 100644
--- a/drivers/net/wireless/realtek/rtw89/debug.c
+++ b/drivers/net/wireless/realtek/rtw89/debug.c
@@ -24,8 +24,7 @@ MODULE_PARM_DESC(debug_mask, "Debugging mask");
struct rtw89_debugfs_priv {
struct rtw89_dev *rtwdev;
int (*cb_read)(struct seq_file *m, void *v);
- ssize_t (*cb_write)(struct file *filp, const char __user *buffer,
- size_t count, loff_t *loff);
+ ssize_t (*cb_write)(struct kiocb *, struct iov_iter *);
union {
u32 cb_data;
struct {
@@ -75,23 +74,21 @@ static int rtw89_debugfs_single_show(struct seq_file *m, void *v)
return debugfs_priv->cb_read(m, v);
}

-static ssize_t rtw89_debugfs_single_write(struct file *filp,
- const char __user *buffer,
- size_t count, loff_t *loff)
+static ssize_t rtw89_debugfs_single_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
+ struct rtw89_debugfs_priv *debugfs_priv = iocb->ki_filp->private_data;

- return debugfs_priv->cb_write(filp, buffer, count, loff);
+ return debugfs_priv->cb_write(iocb, from);
}

-static ssize_t rtw89_debugfs_seq_file_write(struct file *filp,
- const char __user *buffer,
- size_t count, loff_t *loff)
+static ssize_t rtw89_debugfs_seq_file_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
+ struct seq_file *seqpriv = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = seqpriv->private;

- return debugfs_priv->cb_write(filp, buffer, count, loff);
+ return debugfs_priv->cb_write(iocb, from);
}

static int rtw89_debugfs_single_open(struct inode *inode, struct file *filp)
@@ -107,7 +104,7 @@ static int rtw89_debugfs_close(struct inode *inode, struct file *filp)
static const struct file_operations file_ops_single_r = {
.owner = THIS_MODULE,
.open = rtw89_debugfs_single_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = single_release,
};
@@ -116,33 +113,32 @@ static const struct file_operations file_ops_common_rw = {
.owner = THIS_MODULE,
.open = rtw89_debugfs_single_open,
.release = single_release,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
- .write = rtw89_debugfs_seq_file_write,
+ .write_iter = rtw89_debugfs_seq_file_write,
};

static const struct file_operations file_ops_single_w = {
.owner = THIS_MODULE,
- .write = rtw89_debugfs_single_write,
+ .write_iter = rtw89_debugfs_single_write,
.open = simple_open,
.release = rtw89_debugfs_close,
};

static ssize_t
-rtw89_debug_priv_read_reg_select(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_read_reg_select(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size;
u32 addr, len;
int num;

buf_size = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -207,19 +203,19 @@ static int rtw89_debug_priv_read_reg_get(struct seq_file *m, void *v)
return 0;
}

-static ssize_t rtw89_debug_priv_write_reg_set(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+static ssize_t rtw89_debug_priv_write_reg_set(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
+ struct rtw89_debugfs_priv *debugfs_priv = iocb->ki_filp->private_data;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size;
u32 addr, val, len;
int num;

buf_size = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -251,13 +247,12 @@ static ssize_t rtw89_debug_priv_write_reg_set(struct file *filp,
}

static ssize_t
-rtw89_debug_priv_read_rf_select(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_read_rf_select(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size;
u32 addr, mask;
@@ -265,7 +260,7 @@ rtw89_debug_priv_read_rf_select(struct file *filp,
int num;

buf_size = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -306,12 +301,12 @@ static int rtw89_debug_priv_read_rf_get(struct seq_file *m, void *v)
return 0;
}

-static ssize_t rtw89_debug_priv_write_rf_set(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+static ssize_t rtw89_debug_priv_write_rf_set(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
+ struct rtw89_debugfs_priv *debugfs_priv = iocb->ki_filp->private_data;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size;
u32 addr, val, mask;
@@ -319,7 +314,7 @@ static ssize_t rtw89_debug_priv_write_rf_set(struct file *filp,
int num;

buf_size = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -867,21 +862,20 @@ static int rtw89_debug_priv_txpwr_table_get(struct seq_file *m, void *v)
}

static ssize_t
-rtw89_debug_priv_mac_reg_dump_select(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_mac_reg_dump_select(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
const struct rtw89_chip_info *chip = rtwdev->chip;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size;
int sel;
int ret;

buf_size = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -984,20 +978,19 @@ static int rtw89_debug_priv_mac_reg_dump_get(struct seq_file *m, void *v)
}

static ssize_t
-rtw89_debug_priv_mac_mem_dump_select(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_mac_mem_dump_select(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size;
u32 sel, start_addr, len;
int num;

buf_size = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -1094,13 +1087,13 @@ rtw89_debug_priv_mac_mem_dump_get(struct seq_file *m, void *v)
}

static ssize_t
-rtw89_debug_priv_mac_dbg_port_dump_select(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_mac_dbg_port_dump_select(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size;
int sel, set;
@@ -1108,7 +1101,7 @@ rtw89_debug_priv_mac_dbg_port_dump_select(struct file *filp,
bool enable;

buf_size = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -3222,15 +3215,15 @@ rtw89_debug_priv_mac_dbg_port_dump_get(struct seq_file *m, void *v)
return 0;
};

-static u8 *rtw89_hex2bin_user(struct rtw89_dev *rtwdev,
- const char __user *user_buf, size_t count)
+static u8 *rtw89_hex2bin_user(struct rtw89_dev *rtwdev, struct iov_iter *from)
{
+ size_t count = iov_iter_count(from);
char *buf;
u8 *bin;
int num;
int err = 0;

- buf = memdup_user(user_buf, count);
+ buf = iterdup(from, count);
if (IS_ERR(buf))
return buf;

@@ -3253,17 +3246,17 @@ static u8 *rtw89_hex2bin_user(struct rtw89_dev *rtwdev,
return err ? ERR_PTR(err) : bin;
}

-static ssize_t rtw89_debug_priv_send_h2c_set(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+static ssize_t rtw89_debug_priv_send_h2c_set(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
+ struct rtw89_debugfs_priv *debugfs_priv = iocb->ki_filp->private_data;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
u8 *h2c;
int ret;
u16 h2c_len = count / 2;

- h2c = rtw89_hex2bin_user(rtwdev, user_buf, count);
+ h2c = rtw89_hex2bin_user(rtwdev, from);
if (IS_ERR(h2c))
return -EFAULT;

@@ -3291,17 +3284,17 @@ rtw89_debug_priv_early_h2c_get(struct seq_file *m, void *v)
}

static ssize_t
-rtw89_debug_priv_early_h2c_set(struct file *filp, const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_early_h2c_set(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
+ size_t count = iov_iter_count(from);
struct rtw89_early_h2c *early_h2c;
u8 *h2c;
u16 h2c_len = count / 2;

- h2c = rtw89_hex2bin_user(rtwdev, user_buf, count);
+ h2c = rtw89_hex2bin_user(rtwdev, from);
if (IS_ERR(h2c))
return -EFAULT;

@@ -3372,17 +3365,17 @@ enum rtw89_dbg_crash_simulation_type {
};

static ssize_t
-rtw89_debug_priv_fw_crash_set(struct file *filp, const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_fw_crash_set(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
int (*sim)(struct rtw89_dev *rtwdev);
+ size_t count = iov_iter_count(from);
u8 crash_type;
int ret;

- ret = kstrtou8_from_user(user_buf, count, 0, &crash_type);
+ ret = kstrtou8_from_iter(from, count, 0, &crash_type);
if (ret)
return -EINVAL;

@@ -3420,17 +3413,17 @@ static int rtw89_debug_priv_btc_info_get(struct seq_file *m, void *v)
return 0;
}

-static ssize_t rtw89_debug_priv_btc_manual_set(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+static ssize_t rtw89_debug_priv_btc_manual_set(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
+ struct rtw89_debugfs_priv *debugfs_priv = iocb->ki_filp->private_data;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
struct rtw89_btc *btc = &rtwdev->btc;
const struct rtw89_btc_ver *ver = btc->ver;
+ size_t count = iov_iter_count(from);
int ret;

- ret = kstrtobool_from_user(user_buf, count, &btc->manual_ctrl);
+ ret = kstrtobool_from_iter(from, count, &btc->manual_ctrl);
if (ret)
return ret;

@@ -3442,16 +3435,16 @@ static ssize_t rtw89_debug_priv_btc_manual_set(struct file *filp,
return count;
}

-static ssize_t rtw89_debug_fw_log_manual_set(struct file *filp,
- const char __user *user_buf,
- size_t count, loff_t *loff)
+static ssize_t rtw89_debug_fw_log_manual_set(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
+ struct rtw89_debugfs_priv *debugfs_priv = iocb->ki_filp->private_data;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
struct rtw89_fw_log *log = &rtwdev->fw.log;
+ size_t count = iov_iter_count(from);
bool fw_log_manual;

- if (kstrtobool_from_user(user_buf, count, &fw_log_manual))
+ if (kstrtobool_from_iter(from, count, &fw_log_manual))
goto out;

mutex_lock(&rtwdev->mutex);
@@ -3807,17 +3800,17 @@ rtw89_debug_priv_disable_dm_get(struct seq_file *m, void *v)
}

static ssize_t
-rtw89_debug_priv_disable_dm_set(struct file *filp, const char __user *user_buf,
- size_t count, loff_t *loff)
+rtw89_debug_priv_disable_dm_set(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = (struct seq_file *)filp->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
struct rtw89_hal *hal = &rtwdev->hal;
+ size_t count = iov_iter_count(from);
u32 conf;
int ret;

- ret = kstrtou32_from_user(user_buf, count, 0, &conf);
+ ret = kstrtou32_from_iter(from, count, 0, &conf);
if (ret)
return -EINVAL;

--
2.43.0