[PATCH 112/437] drivers/bluetooth: convert to read/write iterators

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

drivers/bluetooth/btmrvl_debugfs.c | 57 +++++++++++------------
drivers/bluetooth/btusb.c | 20 ++++----
drivers/bluetooth/hci_vhci.c | 73 ++++++++++++++----------------
3 files changed, 70 insertions(+), 80 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_debugfs.c b/drivers/bluetooth/btmrvl_debugfs.c
index 32329a2e526f..e78343575146 100644
--- a/drivers/bluetooth/btmrvl_debugfs.c
+++ b/drivers/bluetooth/btmrvl_debugfs.c
@@ -18,13 +18,13 @@ struct btmrvl_debugfs_data {
struct dentry *status_dir;
};

-static ssize_t btmrvl_hscfgcmd_write(struct file *file,
- const char __user *ubuf, size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscfgcmd_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct btmrvl_private *priv = file->private_data;
+ struct btmrvl_private *priv = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
long result, ret;

- ret = kstrtol_from_user(ubuf, count, 10, &result);
+ ret = kstrtol_from_iter(from, count, 10, &result);
if (ret)
return ret;

@@ -38,33 +38,32 @@ static ssize_t btmrvl_hscfgcmd_write(struct file *file,
return count;
}

-static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscfgcmd_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct btmrvl_private *priv = file->private_data;
+ struct btmrvl_private *priv = iocb->ki_filp->private_data;
char buf[16];
int ret;

ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
priv->btmrvl_dev.hscfgcmd);

- return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);
}

static const struct file_operations btmrvl_hscfgcmd_fops = {
- .read = btmrvl_hscfgcmd_read,
- .write = btmrvl_hscfgcmd_write,
+ .read_iter = btmrvl_hscfgcmd_read,
+ .write_iter = btmrvl_hscfgcmd_write,
.open = simple_open,
.llseek = default_llseek,
};

-static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
- size_t count, loff_t *ppos)
+static ssize_t btmrvl_pscmd_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct btmrvl_private *priv = file->private_data;
+ struct btmrvl_private *priv = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
long result, ret;

- ret = kstrtol_from_user(ubuf, count, 10, &result);
+ ret = kstrtol_from_iter(from, count, 10, &result);
if (ret)
return ret;

@@ -79,32 +78,31 @@ static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,

}

-static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
+static ssize_t btmrvl_pscmd_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct btmrvl_private *priv = file->private_data;
+ struct btmrvl_private *priv = iocb->ki_filp->private_data;
char buf[16];
int ret;

ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);

- return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);
}

static const struct file_operations btmrvl_pscmd_fops = {
- .read = btmrvl_pscmd_read,
- .write = btmrvl_pscmd_write,
+ .read_iter = btmrvl_pscmd_read,
+ .write_iter = btmrvl_pscmd_write,
.open = simple_open,
.llseek = default_llseek,
};

-static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
- size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscmd_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct btmrvl_private *priv = file->private_data;
+ struct btmrvl_private *priv = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
long result, ret;

- ret = kstrtol_from_user(ubuf, count, 10, &result);
+ ret = kstrtol_from_iter(from, count, 10, &result);
if (ret)
return ret;

@@ -117,21 +115,20 @@ static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
return count;
}

-static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
+static ssize_t btmrvl_hscmd_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct btmrvl_private *priv = file->private_data;
+ struct btmrvl_private *priv = iocb->ki_filp->private_data;
char buf[16];
int ret;

ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);

- return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, ret, to);
}

static const struct file_operations btmrvl_hscmd_fops = {
- .read = btmrvl_hscmd_read,
- .write = btmrvl_hscmd_write,
+ .read_iter = btmrvl_hscmd_read,
+ .write_iter = btmrvl_hscmd_write,
.open = simple_open,
.llseek = default_llseek,
};
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 06e915b57283..7dbcd00ed4ed 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4161,27 +4161,25 @@ static int btusb_shutdown_qca(struct hci_dev *hdev)
return 0;
}

-static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_poll_sync_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct btusb_data *data = file->private_data;
+ struct btusb_data *data = iocb->ki_filp->private_data;
char buf[3];

buf[0] = data->poll_sync ? 'Y' : 'N';
buf[1] = '\n';
buf[2] = '\0';
- return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, 2, to);
}

-static ssize_t force_poll_sync_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_poll_sync_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct btusb_data *data = file->private_data;
+ struct btusb_data *data = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
bool enable;
int err;

- err = kstrtobool_from_user(user_buf, count, &enable);
+ err = kstrtobool_from_iter(from, count, &enable);
if (err)
return err;

@@ -4199,8 +4197,8 @@ static ssize_t force_poll_sync_write(struct file *file,

static const struct file_operations force_poll_sync_fops = {
.open = simple_open,
- .read = force_poll_sync_read,
- .write = force_poll_sync_write,
+ .read_iter = force_poll_sync_read,
+ .write_iter = force_poll_sync_write,
.llseek = default_llseek,
};

diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 572d68d52965..0d310a7d78f4 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -109,16 +109,15 @@ static bool vhci_wakeup(struct hci_dev *hdev)
return data->wakeup;
}

-static ssize_t force_suspend_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_suspend_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct vhci_data *data = file->private_data;
+ struct vhci_data *data = iocb->ki_filp->private_data;
char buf[3];

buf[0] = data->suspended ? 'Y' : 'N';
buf[1] = '\n';
buf[2] = '\0';
- return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, 2, to);
}

static void vhci_suspend_work(struct work_struct *work)
@@ -132,15 +131,14 @@ static void vhci_suspend_work(struct work_struct *work)
hci_resume_dev(data->hdev);
}

-static ssize_t force_suspend_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_suspend_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct vhci_data *data = file->private_data;
+ struct vhci_data *data = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
bool enable;
int err;

- err = kstrtobool_from_user(user_buf, count, &enable);
+ err = kstrtobool_from_iter(from, count, &enable);
if (err)
return err;

@@ -156,32 +154,30 @@ static ssize_t force_suspend_write(struct file *file,

static const struct file_operations force_suspend_fops = {
.open = simple_open,
- .read = force_suspend_read,
- .write = force_suspend_write,
+ .read_iter = force_suspend_read,
+ .write_iter = force_suspend_write,
.llseek = default_llseek,
};

-static ssize_t force_wakeup_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_wakeup_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct vhci_data *data = file->private_data;
+ struct vhci_data *data = iocb->ki_filp->private_data;
char buf[3];

buf[0] = data->wakeup ? 'Y' : 'N';
buf[1] = '\n';
buf[2] = '\0';
- return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, 2, to);
}

-static ssize_t force_wakeup_write(struct file *file,
- const char __user *user_buf, size_t count,
- loff_t *ppos)
+static ssize_t force_wakeup_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct vhci_data *data = file->private_data;
+ struct vhci_data *data = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
bool enable;
int err;

- err = kstrtobool_from_user(user_buf, count, &enable);
+ err = kstrtobool_from_iter(from, count, &enable);
if (err)
return err;

@@ -195,8 +191,8 @@ static ssize_t force_wakeup_write(struct file *file,

static const struct file_operations force_wakeup_fops = {
.open = simple_open,
- .read = force_wakeup_read,
- .write = force_wakeup_write,
+ .read_iter = force_wakeup_read,
+ .write_iter = force_wakeup_write,
.llseek = default_llseek,
};

@@ -227,27 +223,25 @@ static int msft_opcode_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(msft_opcode_fops, msft_opcode_get, msft_opcode_set,
"%llu\n");

-static ssize_t aosp_capable_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t aosp_capable_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct vhci_data *vhci = file->private_data;
+ struct vhci_data *vhci = iocb->ki_filp->private_data;
char buf[3];

buf[0] = vhci->aosp_capable ? 'Y' : 'N';
buf[1] = '\n';
buf[2] = '\0';
- return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, 2, to);
}

-static ssize_t aosp_capable_write(struct file *file,
- const char __user *user_buf, size_t count,
- loff_t *ppos)
+static ssize_t aosp_capable_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct vhci_data *vhci = file->private_data;
+ struct vhci_data *vhci = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
bool enable;
int err;

- err = kstrtobool_from_user(user_buf, count, &enable);
+ err = kstrtobool_from_iter(from, count, &enable);
if (err)
return err;

@@ -264,8 +258,8 @@ static ssize_t aosp_capable_write(struct file *file,

static const struct file_operations aosp_capable_fops = {
.open = simple_open,
- .read = aosp_capable_read,
- .write = aosp_capable_write,
+ .read_iter = aosp_capable_read,
+ .write_iter = aosp_capable_write,
.llseek = default_llseek,
};

@@ -320,10 +314,10 @@ static inline void force_devcd_timeout(struct hci_dev *hdev,
#endif
}

-static ssize_t force_devcd_write(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_devcd_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct vhci_data *data = file->private_data;
+ struct vhci_data *data = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct hci_dev *hdev = data->hdev;
struct sk_buff *skb = NULL;
struct devcoredump_test_data dump_data;
@@ -334,7 +328,7 @@ static ssize_t force_devcd_write(struct file *file, const char __user *user_buf,
count > sizeof(dump_data))
return -EINVAL;

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

data_size = count - offsetof(struct devcoredump_test_data, data);
@@ -377,7 +371,7 @@ static ssize_t force_devcd_write(struct file *file, const char __user *user_buf,

static const struct file_operations force_devcoredump_fops = {
.open = simple_open,
- .write = force_devcd_write,
+ .write_iter = force_devcd_write,
};

static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
@@ -608,6 +602,7 @@ static ssize_t vhci_read(struct file *file,

return ret;
}
+FOPS_READ_ITER_HELPER(vhci_read);

static ssize_t vhci_write(struct kiocb *iocb, struct iov_iter *from)
{
@@ -684,7 +679,7 @@ static int vhci_release(struct inode *inode, struct file *file)

static const struct file_operations vhci_fops = {
.owner = THIS_MODULE,
- .read = vhci_read,
+ .read_iter = vhci_read_iter,
.write_iter = vhci_write,
.poll = vhci_poll,
.open = vhci_open,
--
2.43.0