[PATCH 297/437] drivers/net/wireless/mediatek: convert to read/write iterators

Jens Axboe
2024-04-11T15:39:52Z

.../wireless/mediatek/mt76/mt7615/debugfs.c | 20 ++++---
.../wireless/mediatek/mt76/mt7915/debugfs.c | 52 +++++++++----------
.../wireless/mediatek/mt76/mt7996/debugfs.c | 33 ++++++------
3 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c
index 2a6d317db5e0..d645550bab86 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c
@@ -436,11 +436,9 @@ mt7615_rf_reg_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(fops_rf_reg, mt7615_rf_reg_get, mt7615_rf_reg_set,
"0x%08llx\n");

-static ssize_t
-mt7615_ext_mac_addr_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
+static ssize_t mt7615_ext_mac_addr_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct mt7615_dev *dev = file->private_data;
+ struct mt7615_dev *dev = iocb->ki_filp->private_data;
u32 len = 32 * ((ETH_ALEN * 3) + 4) + 1;
u8 addr[ETH_ALEN];
char *buf;
@@ -464,17 +462,17 @@ mt7615_ext_mac_addr_read(struct file *file, char __user *userbuf,
ofs += snprintf(buf + ofs, len - ofs, "%d=%pM\n", i, addr);
}

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

kfree(buf);
return ofs;
}

static ssize_t
-mt7615_ext_mac_addr_write(struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
+mt7615_ext_mac_addr_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct mt7615_dev *dev = file->private_data;
+ struct mt7615_dev *dev = iocb->ki_filp->private_data;;
+ size_t count = iov_iter_count(from);
unsigned long idx = 0;
u8 addr[ETH_ALEN];
char buf[32];
@@ -483,7 +481,7 @@ mt7615_ext_mac_addr_write(struct file *file, const char __user *userbuf,
if (count > sizeof(buf))
return -EINVAL;

- if (copy_from_user(buf, userbuf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;

buf[sizeof(buf) - 1] = '\0';
@@ -526,8 +524,8 @@ mt7615_ext_mac_addr_write(struct file *file, const char __user *userbuf,
static const struct file_operations fops_ext_mac_addr = {
.open = simple_open,
.llseek = generic_file_llseek,
- .read = mt7615_ext_mac_addr_read,
- .write = mt7615_ext_mac_addr_write,
+ .read_iter = mt7615_ext_mac_addr_read,
+ .write_iter = mt7615_ext_mac_addr_write,
.owner = THIS_MODULE,
};

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
index 6c3696c8c700..66ffdd915bc5 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
@@ -46,10 +46,10 @@ DEFINE_DEBUGFS_ATTRIBUTE(fops_implicit_txbf, mt7915_implicit_txbf_get,

/* test knob of system error recovery */
static ssize_t
-mt7915_sys_recovery_set(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+mt7915_sys_recovery_set(struct kiocb *iocb, struct iov_iter *from)
{
- struct mt7915_phy *phy = file->private_data;
+ struct mt7915_phy *phy = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct mt7915_dev *dev = phy->dev;
bool band = phy->mt76->band_idx;
char buf[16];
@@ -59,7 +59,7 @@ mt7915_sys_recovery_set(struct file *file, const char __user *user_buf,
if (count >= sizeof(buf))
return -EINVAL;

- if (copy_from_user(buf, user_buf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;

if (count && buf[count - 1] == '\n')
@@ -121,11 +121,9 @@ mt7915_sys_recovery_set(struct file *file, const char __user *user_buf,
return ret ? ret : count;
}

-static ssize_t
-mt7915_sys_recovery_get(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t mt7915_sys_recovery_get(struct kiocb *iocb, struct iov_iter *to)
{
- struct mt7915_phy *phy = file->private_data;
+ struct mt7915_phy *phy = iocb->ki_filp->private_data;
struct mt7915_dev *dev = phy->dev;
char *buff;
int desc = 0;
@@ -196,14 +194,14 @@ mt7915_sys_recovery_get(struct file *file, char __user *user_buf,
dev->recovery.wm_reset_count,
dev->recovery.wa_reset_count);

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

static const struct file_operations mt7915_sys_recovery_ops = {
- .write = mt7915_sys_recovery_set,
- .read = mt7915_sys_recovery_get,
+ .write_iter = mt7915_sys_recovery_set,
+ .read_iter = mt7915_sys_recovery_get,
.open = simple_open,
.llseek = default_llseek,
};
@@ -968,11 +966,9 @@ DEFINE_SHOW_ATTRIBUTE(mt7915_xmit_queues);
} \
})

-static ssize_t
-mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t mt7915_rate_txpower_get(struct kiocb *iocb, struct iov_iter *to)
{
- struct mt7915_phy *phy = file->private_data;
+ struct mt7915_phy *phy = iocb->ki_filp->private_data;
struct mt7915_dev *dev = phy->dev;
s8 txpwr[MT7915_SKU_RATE_NUM];
static const size_t sz = 2048;
@@ -1038,7 +1034,7 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
len += scnprintf(buf + len, sz - len, "\nTx power (bbp) : %6ld\n",
mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER));

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

out:
kfree(buf);
@@ -1046,10 +1042,10 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
}

static ssize_t
-mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+mt7915_rate_txpower_set(struct kiocb *iocb, struct iov_iter *from)
{
- struct mt7915_phy *phy = file->private_data;
+ struct mt7915_phy *phy = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct mt7915_dev *dev = phy->dev;
struct mt76_phy *mphy = phy->mt76;
struct mt7915_mcu_txpower_sku req = {
@@ -1064,7 +1060,7 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
if (count >= sizeof(buf))
return -EINVAL;

- if (copy_from_user(buf, user_buf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;

if (count && buf[count - 1] == '\n')
@@ -1139,8 +1135,8 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
}

static const struct file_operations mt7915_rate_txpower_fops = {
- .write = mt7915_rate_txpower_set,
- .read = mt7915_rate_txpower_get,
+ .write_iter = mt7915_rate_txpower_set,
+ .read_iter = mt7915_rate_txpower_get,
.open = simple_open,
.owner = THIS_MODULE,
.llseek = default_llseek,
@@ -1311,13 +1307,13 @@ bool mt7915_debugfs_rx_log(struct mt7915_dev *dev, const void *data, int len)
#ifdef CONFIG_MAC80211_DEBUGFS
/** per-station debugfs **/

-static ssize_t mt7915_sta_fixed_rate_set(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t mt7915_sta_fixed_rate_set(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct ieee80211_sta *sta = file->private_data;
+ struct ieee80211_sta *sta = iocb->ki_filp->private_data;
struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
struct mt7915_dev *dev = msta->vif->phy->dev;
+ size_t count = iov_iter_count(from);
struct ieee80211_vif *vif;
struct sta_phy phy = {};
char buf[100];
@@ -1328,7 +1324,7 @@ static ssize_t mt7915_sta_fixed_rate_set(struct file *file,
if (count >= sizeof(buf))
return -EINVAL;

- if (copy_from_user(buf, user_buf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;

if (count && buf[count - 1] == '\n')
@@ -1371,7 +1367,7 @@ static ssize_t mt7915_sta_fixed_rate_set(struct file *file,
}

static const struct file_operations fops_fixed_rate = {
- .write = mt7915_sta_fixed_rate_set,
+ .write_iter = mt7915_sta_fixed_rate_set,
.open = simple_open,
.owner = THIS_MODULE,
.llseek = default_llseek,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c
index 9bd953586b04..afd8a6623b9c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c
@@ -47,11 +47,10 @@ DEFINE_DEBUGFS_ATTRIBUTE(fops_implicit_txbf, mt7996_implicit_txbf_get,
mt7996_implicit_txbf_set, "%lld\n");

/* test knob of system error recovery */
-static ssize_t
-mt7996_sys_recovery_set(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t mt7996_sys_recovery_set(struct kiocb *iocb, struct iov_iter *from)
{
- struct mt7996_phy *phy = file->private_data;
+ struct mt7996_phy *phy = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct mt7996_dev *dev = phy->dev;
bool band = phy->mt76->band_idx;
char buf[16];
@@ -61,7 +60,7 @@ mt7996_sys_recovery_set(struct file *file, const char __user *user_buf,
if (count >= sizeof(buf))
return -EINVAL;

- if (copy_from_user(buf, user_buf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;

if (count && buf[count - 1] == '\n')
@@ -122,11 +121,9 @@ mt7996_sys_recovery_set(struct file *file, const char __user *user_buf,
return ret ? ret : count;
}

-static ssize_t
-mt7996_sys_recovery_get(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t mt7996_sys_recovery_get(struct kiocb *iocb, struct iov_iter *to)
{
- struct mt7996_phy *phy = file->private_data;
+ struct mt7996_phy *phy = iocb->ki_filp->private_data;
struct mt7996_dev *dev = phy->dev;
char *buff;
int desc = 0;
@@ -205,14 +202,14 @@ mt7996_sys_recovery_get(struct file *file, char __user *user_buf,
dev->recovery.wm_reset_count,
dev->recovery.wa_reset_count);

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

static const struct file_operations mt7996_sys_recovery_ops = {
- .write = mt7996_sys_recovery_set,
- .read = mt7996_sys_recovery_get,
+ .write_iter = mt7996_sys_recovery_set,
+ .read_iter = mt7996_sys_recovery_get,
.open = simple_open,
.llseek = default_llseek,
};
@@ -886,15 +883,15 @@ bool mt7996_debugfs_rx_log(struct mt7996_dev *dev, const void *data, int len)
#ifdef CONFIG_MAC80211_DEBUGFS
/** per-station debugfs **/

-static ssize_t mt7996_sta_fixed_rate_set(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t mt7996_sta_fixed_rate_set(struct kiocb *iocb,
+ struct iov_iter *from)
{
#define SHORT_PREAMBLE 0
#define LONG_PREAMBLE 1
- struct ieee80211_sta *sta = file->private_data;
+ struct ieee80211_sta *sta = iocb->ki_filp->private_data;
struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
struct mt7996_dev *dev = msta->vif->phy->dev;
+ size_t count = iov_iter_count(from);
struct ra_rate phy = {};
char buf[100];
int ret;
@@ -903,7 +900,7 @@ static ssize_t mt7996_sta_fixed_rate_set(struct file *file,
if (count >= sizeof(buf))
return -EINVAL;

- if (copy_from_user(buf, user_buf, count))
+ if (!copy_from_iter_full(buf, count, from))
return -EFAULT;

if (count && buf[count - 1] == '\n')
@@ -944,7 +941,7 @@ static ssize_t mt7996_sta_fixed_rate_set(struct file *file,
}

static const struct file_operations fops_fixed_rate = {
- .write = mt7996_sta_fixed_rate_set,
+ .write_iter = mt7996_sta_fixed_rate_set,
.open = simple_open,
.owner = THIS_MODULE,
.llseek = default_llseek,
--
2.43.0