[PATCH 212/437] misc: bcm_vk: convert to iterators
From: Jens Axboe
Date: Thu Apr 11 2024 - 12:27:15 EST
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
drivers/misc/bcm-vk/bcm_vk.h | 6 ++----
drivers/misc/bcm-vk/bcm_vk_dev.c | 4 ++--
drivers/misc/bcm-vk/bcm_vk_msg.c | 23 ++++++++++-------------
3 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/drivers/misc/bcm-vk/bcm_vk.h b/drivers/misc/bcm-vk/bcm_vk.h
index 386884c2a263..efc91635fa42 100644
--- a/drivers/misc/bcm-vk/bcm_vk.h
+++ b/drivers/misc/bcm-vk/bcm_vk.h
@@ -487,10 +487,8 @@ static inline bool bcm_vk_msgq_marker_valid(struct bcm_vk *vk)
}
int bcm_vk_open(struct inode *inode, struct file *p_file);
-ssize_t bcm_vk_read(struct file *p_file, char __user *buf, size_t count,
- loff_t *f_pos);
-ssize_t bcm_vk_write(struct file *p_file, const char __user *buf,
- size_t count, loff_t *f_pos);
+ssize_t bcm_vk_read(struct kiocb *iocb, struct iov_iter *to);
+ssize_t bcm_vk_write(struct kiocb *iocb, struct iov_iter *from);
__poll_t bcm_vk_poll(struct file *p_file, struct poll_table_struct *wait);
int bcm_vk_release(struct inode *inode, struct file *p_file);
void bcm_vk_release_data(struct kref *kref);
diff --git a/drivers/misc/bcm-vk/bcm_vk_dev.c b/drivers/misc/bcm-vk/bcm_vk_dev.c
index d4a96137728d..1fadb7b2dec1 100644
--- a/drivers/misc/bcm-vk/bcm_vk_dev.c
+++ b/drivers/misc/bcm-vk/bcm_vk_dev.c
@@ -1258,8 +1258,8 @@ static long bcm_vk_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
static const struct file_operations bcm_vk_fops = {
.owner = THIS_MODULE,
.open = bcm_vk_open,
- .read = bcm_vk_read,
- .write = bcm_vk_write,
+ .read_iter = bcm_vk_read,
+ .write_iter = bcm_vk_write,
.poll = bcm_vk_poll,
.release = bcm_vk_release,
.mmap = bcm_vk_mmap,
diff --git a/drivers/misc/bcm-vk/bcm_vk_msg.c b/drivers/misc/bcm-vk/bcm_vk_msg.c
index 1f42d1d5a630..31418a677ecd 100644
--- a/drivers/misc/bcm-vk/bcm_vk_msg.c
+++ b/drivers/misc/bcm-vk/bcm_vk_msg.c
@@ -13,6 +13,7 @@
#include <linux/sizes.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
+#include <linux/uio.h>
#include "bcm_vk.h"
#include "bcm_vk_msg.h"
@@ -998,18 +999,16 @@ int bcm_vk_open(struct inode *inode, struct file *p_file)
return rc;
}
-ssize_t bcm_vk_read(struct file *p_file,
- char __user *buf,
- size_t count,
- loff_t *f_pos)
+ssize_t bcm_vk_read(struct kiocb *iocb, struct iov_iter *to)
{
ssize_t rc = -ENOMSG;
- struct bcm_vk_ctx *ctx = p_file->private_data;
+ struct bcm_vk_ctx *ctx = iocb->ki_filp->private_data;
struct bcm_vk *vk = container_of(ctx->miscdev, struct bcm_vk,
miscdev);
struct device *dev = &vk->pdev->dev;
struct bcm_vk_msg_chan *chan = &vk->to_h_msg_chan;
struct bcm_vk_wkent *entry = NULL, *iter;
+ size_t count = iov_iter_count(to);
u32 q_num;
u32 rsp_length;
@@ -1047,7 +1046,7 @@ ssize_t bcm_vk_read(struct file *p_file,
/* retrieve the passed down msg_id */
set_msg_id(&entry->to_h_msg[0], entry->usr_msg_id);
rsp_length = entry->to_h_blks * VK_MSGQ_BLK_SIZE;
- if (copy_to_user(buf, entry->to_h_msg, rsp_length) == 0)
+ if (!copy_to_iter_full(entry->to_h_msg, rsp_length, to))
rc = rsp_length;
bcm_vk_free_wkent(dev, entry);
@@ -1060,7 +1059,7 @@ ssize_t bcm_vk_read(struct file *p_file,
*/
set_msg_id(&tmp_msg, entry->usr_msg_id);
tmp_msg.size = entry->to_h_blks - 1;
- if (copy_to_user(buf, &tmp_msg, VK_MSGQ_BLK_SIZE) != 0) {
+ if (!copy_to_iter_full(&tmp_msg, VK_MSGQ_BLK_SIZE, to)) {
dev_err(dev, "Error return 1st block in -EMSGSIZE\n");
rc = -EFAULT;
}
@@ -1068,17 +1067,15 @@ ssize_t bcm_vk_read(struct file *p_file,
return rc;
}
-ssize_t bcm_vk_write(struct file *p_file,
- const char __user *buf,
- size_t count,
- loff_t *f_pos)
+ssize_t bcm_vk_write(struct kiocb *iocb, struct iov_iter *from)
{
ssize_t rc;
- struct bcm_vk_ctx *ctx = p_file->private_data;
+ struct bcm_vk_ctx *ctx = iocb->ki_filp->private_data;
struct bcm_vk *vk = container_of(ctx->miscdev, struct bcm_vk,
miscdev);
struct bcm_vk_msgq __iomem *msgq;
struct device *dev = &vk->pdev->dev;
+ size_t count = iov_iter_count(from);
struct bcm_vk_wkent *entry;
u32 sgl_extra_blks;
u32 q_num;
@@ -1107,7 +1104,7 @@ ssize_t bcm_vk_write(struct file *p_file,
}
/* now copy msg from user space, and then formulate the work entry */
- if (copy_from_user(&entry->to_v_msg[0], buf, count)) {
+ if (!copy_from_iter_full(&entry->to_v_msg[0], count, from)) {
rc = -EFAULT;
goto write_free_ent;
}
--
2.43.0