[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-330-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:17:49 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Bui Quang Minh <minhquangbui99@...il.com>,
Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 329/437] drivers/net/ethernet/mellanox/mlx5/core: convert to read/write iterators
From: Bui Quang Minh <minhquangbui99@...il.com>
Signed-off-by: Bui Quang Minh <minhquangbui99@...il.com>
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 78 ++++++++++---------
.../net/ethernet/mellanox/mlx5/core/debugfs.c | 49 ++++++------
.../net/ethernet/mellanox/mlx5/core/lib/sd.c | 13 ++--
3 files changed, 69 insertions(+), 71 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 4957412ff1f6..fecd1553fac5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -1246,13 +1246,13 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
return err ? : status;
}
-static ssize_t dbg_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t dbg_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
- struct mlx5_core_dev *dev = filp->private_data;
+ struct mlx5_core_dev *dev = iocb->ki_filp->private_data;
struct mlx5_cmd_debug *dbg = &dev->cmd.dbg;
char lbuf[3];
int err;
+ size_t count = iov_iter_count(from);
if (!dbg->in_msg || !dbg->out_msg)
return -ENOMEM;
@@ -1260,7 +1260,7 @@ static ssize_t dbg_write(struct file *filp, const char __user *buf,
if (count < sizeof(lbuf) - 1)
return -EINVAL;
- if (copy_from_user(lbuf, buf, sizeof(lbuf) - 1))
+ if (!copy_from_iter_full(lbuf, sizeof(lbuf) - 1, from))
return -EFAULT;
lbuf[sizeof(lbuf) - 1] = 0;
@@ -1274,9 +1274,9 @@ static ssize_t dbg_write(struct file *filp, const char __user *buf,
}
static const struct file_operations fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = dbg_write,
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .write_iter = dbg_write_iter,
};
static int mlx5_copy_to_msg(struct mlx5_cmd_msg *to, void *from, int size,
@@ -1435,54 +1435,56 @@ static void mlx5_free_cmd_msg(struct mlx5_core_dev *dev,
kfree(msg);
}
-static ssize_t data_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t data_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
- struct mlx5_core_dev *dev = filp->private_data;
+ struct mlx5_core_dev *dev = iocb->ki_filp->private_data;
struct mlx5_cmd_debug *dbg = &dev->cmd.dbg;
void *ptr;
+ size_t count = iov_iter_count(from);
- if (*pos != 0)
+ if (iocb->ki_pos != 0)
return -EINVAL;
kfree(dbg->in_msg);
dbg->in_msg = NULL;
dbg->inlen = 0;
- ptr = memdup_user(buf, count);
- if (IS_ERR(ptr))
- return PTR_ERR(ptr);
+ ptr = kmalloc(count, GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ if (!copy_from_iter_full(ptr, count, from))
+ return -EFAULT;
+
dbg->in_msg = ptr;
dbg->inlen = count;
- *pos = count;
+ iocb->ki_pos = count;
return count;
}
-static ssize_t data_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t data_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
- struct mlx5_core_dev *dev = filp->private_data;
+ struct mlx5_core_dev *dev = iocb->ki_filp->private_data;
struct mlx5_cmd_debug *dbg = &dev->cmd.dbg;
if (!dbg->out_msg)
return -ENOMEM;
- return simple_read_from_buffer(buf, count, pos, dbg->out_msg,
- dbg->outlen);
+ return simple_copy_to_iter(dbg->out_msg, &iocb->ki_pos,
+ dbg->outlen, to);
}
static const struct file_operations dfops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = data_write,
- .read = data_read,
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .write_iter = data_write_iter,
+ .read_iter = data_read_iter,
};
-static ssize_t outlen_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t outlen_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
- struct mlx5_core_dev *dev = filp->private_data;
+ struct mlx5_core_dev *dev = iocb->ki_filp->private_data;
struct mlx5_cmd_debug *dbg = &dev->cmd.dbg;
char outlen[8];
int err;
@@ -1491,27 +1493,27 @@ static ssize_t outlen_read(struct file *filp, char __user *buf, size_t count,
if (err < 0)
return err;
- return simple_read_from_buffer(buf, count, pos, outlen, err);
+ return simple_copy_to_iter(outlen, &iocb->ki_pos, err, to);
}
-static ssize_t outlen_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t outlen_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
- struct mlx5_core_dev *dev = filp->private_data;
+ struct mlx5_core_dev *dev = iocb->ki_filp->private_data;
struct mlx5_cmd_debug *dbg = &dev->cmd.dbg;
char outlen_str[8] = {0};
int outlen;
void *ptr;
int err;
+ size_t count = iov_iter_count(from);
- if (*pos != 0 || count > 6)
+ if (iocb->ki_pos != 0 || count > 6)
return -EINVAL;
kfree(dbg->out_msg);
dbg->out_msg = NULL;
dbg->outlen = 0;
- if (copy_from_user(outlen_str, buf, count))
+ if (!copy_from_iter_full(outlen_str, count, from))
return -EFAULT;
err = sscanf(outlen_str, "%d", &outlen);
@@ -1525,16 +1527,16 @@ static ssize_t outlen_write(struct file *filp, const char __user *buf,
dbg->out_msg = ptr;
dbg->outlen = outlen;
- *pos = count;
+ iocb->ki_pos = count;
return count;
}
static const struct file_operations olfops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = outlen_write,
- .read = outlen_read,
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .write_iter = outlen_write_iter,
+ .read_iter = outlen_read_iter,
};
static void set_wqname(struct mlx5_core_dev *dev)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
index 09652dc89115..090b5b5d0acd 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
@@ -126,48 +126,46 @@ void mlx5_eq_debugfs_cleanup(struct mlx5_core_dev *dev)
debugfs_remove_recursive(dev->priv.dbg.eq_debugfs);
}
-static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t average_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct mlx5_cmd_stats *stats;
u64 field = 0;
int ret;
char tbuf[22];
- stats = filp->private_data;
+ stats = iocb->ki_filp->private_data;
spin_lock_irq(&stats->lock);
if (stats->n)
field = div64_u64(stats->sum, stats->n);
spin_unlock_irq(&stats->lock);
ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
- return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+ return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
}
-static ssize_t average_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t average_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
struct mlx5_cmd_stats *stats;
+ size_t count = iov_iter_count(from);
- stats = filp->private_data;
+ stats = iocb->ki_filp->private_data;
spin_lock_irq(&stats->lock);
stats->sum = 0;
stats->n = 0;
spin_unlock_irq(&stats->lock);
- *pos += count;
+ iocb->ki_pos += count;
return count;
}
static const struct file_operations stats_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .read = average_read,
- .write = average_write,
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read_iter = average_read_iter,
+ .write_iter = average_write_iter,
};
-static ssize_t slots_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t slots_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct mlx5_cmd *cmd;
char tbuf[6];
@@ -175,17 +173,17 @@ static ssize_t slots_read(struct file *filp, char __user *buf, size_t count,
int field;
int ret;
- cmd = filp->private_data;
+ cmd = iocb->ki_filp->private_data;
weight = bitmap_weight(&cmd->vars.bitmask, cmd->vars.max_reg_cmds);
field = cmd->vars.max_reg_cmds - weight;
ret = snprintf(tbuf, sizeof(tbuf), "%d\n", field);
- return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+ return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
}
static const struct file_operations slots_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .read = slots_read,
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read_iter = slots_read_iter,
};
static struct mlx5_cmd_stats *
@@ -445,8 +443,7 @@ static u64 cq_read_field(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
return param;
}
-static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t dbg_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct mlx5_field_desc *desc;
struct mlx5_rsc_debug *d;
@@ -455,7 +452,7 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
u64 field;
int ret;
- desc = filp->private_data;
+ desc = iocb->ki_filp->private_data;
d = (void *)(desc - desc->i) - sizeof(*d);
switch (d->type) {
case MLX5_DBG_RSC_QP:
@@ -480,13 +477,13 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
else
ret = snprintf(tbuf, sizeof(tbuf), "0x%llx\n", field);
- return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+ return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
}
static const struct file_operations fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .read = dbg_read,
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read_iter = dbg_read_iter,
};
static int add_res_tree(struct mlx5_core_dev *dev, enum dbg_rsc_type type,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
index 5b28084e8a03..09429b069c20 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
@@ -393,24 +393,23 @@ static void sd_print_group(struct mlx5_core_dev *primary)
MLX5_CAP_GEN(pos, vhca_id));
}
-static ssize_t dev_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t dev_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct mlx5_core_dev *dev;
char tbuf[32];
int ret;
- dev = filp->private_data;
+ dev = iocb->ki_filp->private_data;
ret = snprintf(tbuf, sizeof(tbuf), "%s vhca %#x\n", pci_name(dev->pdev),
MLX5_CAP_GEN(dev, vhca_id));
- return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+ return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
}
static const struct file_operations dev_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .read = dev_read,
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read_iter = dev_read_iter,
};
int mlx5_sd_init(struct mlx5_core_dev *dev)
--
2.43.0
Powered by blists - more mailing lists