[PATCH 051/437] Bluetooth: convert to read/write iterators

Jens Axboe
2024-04-11T15:33:09Z

net/bluetooth/6lowpan.c | 12 ++-
net/bluetooth/hci_debugfs.c | 150 ++++++++++++++++--------------------
net/bluetooth/selftest.c | 9 +--
net/bluetooth/smp.c | 9 +--
4 files changed, 80 insertions(+), 100 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 27520a8a486f..74e8ce90f12b 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -1079,19 +1079,17 @@ static int lowpan_enable_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(lowpan_enable_fops, lowpan_enable_get,
lowpan_enable_set, "%llu\n");

-static ssize_t lowpan_control_write(struct file *fp,
- const char __user *user_buffer,
- size_t count,
- loff_t *position)
+static ssize_t lowpan_control_write(struct kiocb *iocb, struct iov_iter *from)
{
char buf[32];
+ size_t count = iov_iter_count(from);
size_t buf_size = min(count, sizeof(buf) - 1);
int ret;
bdaddr_t addr;
u8 addr_type;
struct l2cap_conn *conn = NULL;

- if (copy_from_user(buf, user_buffer, buf_size))
+ if (!copy_to_iter_full(buf, buf_size, from))
return -EFAULT;

buf[buf_size] = '\0';
@@ -1173,8 +1171,8 @@ static int lowpan_control_open(struct inode *inode, struct file *file)

static const struct file_operations lowpan_control_fops = {
.open = lowpan_control_open,
- .read = seq_read,
- .write = lowpan_control_write,
+ .read_iter = seq_read_iter,
+ .write_iter = lowpan_control_write,
.llseek = seq_lseek,
.release = single_release,
};
diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c
index ce3ff2fa72e5..736c265e3ddf 100644
--- a/net/bluetooth/hci_debugfs.c
+++ b/net/bluetooth/hci_debugfs.c
@@ -32,31 +32,28 @@
#include "hci_debugfs.h"

#define DEFINE_QUIRK_ATTRIBUTE(__name, __quirk) \
-static ssize_t __name ## _read(struct file *file, \
- char __user *user_buf, \
- size_t count, loff_t *ppos) \
+static ssize_t __name ## _read(struct kiocb *iocb, struct iov_iter *to) \
{ \
- struct hci_dev *hdev = file->private_data; \
+ struct hci_dev *hdev = iocb->ki_filp->private_data; \
char buf[3]; \
\
buf[0] = test_bit(__quirk, &hdev->quirks) ? '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 __name ## _write(struct file *file, \
- const char __user *user_buf, \
- size_t count, loff_t *ppos) \
+static ssize_t __name ## _write(struct kiocb *iocb, struct iov_iter *from) \
{ \
- struct hci_dev *hdev = file->private_data; \
+ struct hci_dev *hdev = iocb->ki_filp->private_data; \
+ size_t count = iov_iter_count(from); \
bool enable; \
int err; \
\
if (test_bit(HCI_UP, &hdev->flags)) \
return -EBUSY; \
\
- err = kstrtobool_from_user(user_buf, count, &enable); \
+ err = kstrtobool_from_iter(from, count, &enable); \
if (err) \
return err; \
\
@@ -70,8 +67,8 @@ static ssize_t __name ## _write(struct file *file, \
\
static const struct file_operations __name ## _fops = { \
.open = simple_open, \
- .read = __name ## _read, \
- .write = __name ## _write, \
+ .read_iter = __name ## _read, \
+ .write_iter = __name ## _write, \
.llseek = default_llseek, \
} \

@@ -274,39 +271,37 @@ static int conn_info_max_age_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
conn_info_max_age_set, "%llu\n");

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

buf[0] = hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS) ? '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 const struct file_operations use_debug_keys_fops = {
.open = simple_open,
- .read = use_debug_keys_read,
+ .read_iter = use_debug_keys_read,
.llseek = default_llseek,
};

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

buf[0] = hci_dev_test_flag(hdev, HCI_SC_ONLY) ? '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 const struct file_operations sc_only_mode_fops = {
.open = simple_open,
- .read = sc_only_mode_read,
+ .read_iter = sc_only_mode_read,
.llseek = default_llseek,
};

@@ -428,21 +423,20 @@ static int voice_setting_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(voice_setting_fops, voice_setting_get,
NULL, "0x%4.4llx\n");

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

buf[0] = hdev->ssp_debug_mode ? '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 const struct file_operations ssp_debug_mode_fops = {
.open = simple_open,
- .read = ssp_debug_mode_read,
+ .read_iter = ssp_debug_mode_read,
.llseek = default_llseek,
};

@@ -500,28 +494,25 @@ static int auto_accept_delay_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
auto_accept_delay_set, "%llu\n");

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

buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP) ? '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_bredr_smp_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_bredr_smp_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct hci_dev *hdev = file->private_data;
+ struct hci_dev *hdev = 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;

@@ -534,8 +525,8 @@ static ssize_t force_bredr_smp_write(struct file *file,

static const struct file_operations force_bredr_smp_fops = {
.open = simple_open,
- .read = force_bredr_smp_read,
- .write = force_bredr_smp_write,
+ .read_iter = force_bredr_smp_read,
+ .write_iter = force_bredr_smp_write,
.llseek = default_llseek,
};

@@ -745,31 +736,29 @@ static int static_address_show(struct seq_file *f, void *p)

DEFINE_SHOW_ATTRIBUTE(static_address);

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

buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ? '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_static_address_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_static_address_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct hci_dev *hdev = file->private_data;
+ struct hci_dev *hdev = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
bool enable;
int err;

if (hdev_is_powered(hdev))
return -EBUSY;

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

@@ -783,8 +772,8 @@ static ssize_t force_static_address_write(struct file *file,

static const struct file_operations force_static_address_fops = {
.open = simple_open,
- .read = force_static_address_read,
- .write = force_static_address_write,
+ .read_iter = force_static_address_read,
+ .write_iter = force_static_address_write,
.llseek = default_llseek,
};

@@ -1147,29 +1136,26 @@ DEFINE_DEBUGFS_ATTRIBUTE(auth_payload_timeout_fops,
auth_payload_timeout_get,
auth_payload_timeout_set, "%llu\n");

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

buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_NO_MITM) ? '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_no_mitm_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t force_no_mitm_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct hci_dev *hdev = file->private_data;
+ struct hci_dev *hdev = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
char buf[32];
size_t buf_size = min(count, (sizeof(buf) - 1));
bool enable;

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

buf[buf_size] = '\0';
@@ -1186,8 +1172,8 @@ static ssize_t force_no_mitm_write(struct file *file,

static const struct file_operations force_no_mitm_fops = {
.open = simple_open,
- .read = force_no_mitm_read,
- .write = force_no_mitm_write,
+ .read_iter = force_no_mitm_read,
+ .write_iter = force_no_mitm_write,
.llseek = default_llseek,
};

@@ -1273,22 +1259,21 @@ void hci_debugfs_create_conn(struct hci_conn *conn)
conn->debugfs = debugfs_create_dir(name, hdev->debugfs);
}

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

buf[0] = hci_dev_test_flag(hdev, HCI_DUT_MODE) ? '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 dut_mode_write(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t dut_mode_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct hci_dev *hdev = file->private_data;
+ struct hci_dev *hdev = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
struct sk_buff *skb;
bool enable;
int err;
@@ -1296,7 +1281,7 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
if (!test_bit(HCI_UP, &hdev->flags))
return -ENETDOWN;

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

@@ -1324,31 +1309,30 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,

static const struct file_operations dut_mode_fops = {
.open = simple_open,
- .read = dut_mode_read,
- .write = dut_mode_write,
+ .read_iter = dut_mode_read,
+ .write_iter = dut_mode_write,
.llseek = default_llseek,
};

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

buf[0] = hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) ? '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 vendor_diag_write(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t vendor_diag_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct hci_dev *hdev = file->private_data;
+ struct hci_dev *hdev = 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;

@@ -1380,8 +1364,8 @@ static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf,

static const struct file_operations vendor_diag_fops = {
.open = simple_open,
- .read = vendor_diag_read,
- .write = vendor_diag_write,
+ .read_iter = vendor_diag_read,
+ .write_iter = vendor_diag_write,
.llseek = default_llseek,
};

diff --git a/net/bluetooth/selftest.c b/net/bluetooth/selftest.c
index f49604d44b87..e8f3e5d63c01 100644
--- a/net/bluetooth/selftest.c
+++ b/net/bluetooth/selftest.c
@@ -183,16 +183,15 @@ static int __init test_ecdh_sample(struct crypto_kpp *tfm, const u8 priv_a[32],

static char test_ecdh_buffer[32];

-static ssize_t test_ecdh_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t test_ecdh_read(struct kiocb *iocb, struct iov_iter *to)
{
- return simple_read_from_buffer(user_buf, count, ppos, test_ecdh_buffer,
- strlen(test_ecdh_buffer));
+ return simple_copy_to_iter(test_ecdh_buffer, &iocb->ki_pos,
+ strlen(test_ecdh_buffer), to);
}

static const struct file_operations test_ecdh_fops = {
.open = simple_open,
- .read = test_ecdh_read,
+ .read_iter = test_ecdh_read,
.llseek = default_llseek,
};

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 1e7ea3a4b7ef..fcd35201712b 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -3729,16 +3729,15 @@ static int __init test_h6(struct crypto_shash *tfm_cmac)

static char test_smp_buffer[32];

-static ssize_t test_smp_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t test_smp_read(struct kiocb *iocb, struct iov_iter *to)
{
- return simple_read_from_buffer(user_buf, count, ppos, test_smp_buffer,
- strlen(test_smp_buffer));
+ return simple_copy_to_iter(test_smp_buffer, &iocb->ki_pos,
+ strlen(test_smp_buffer), to);
}

static const struct file_operations test_smp_fops = {
.open = simple_open,
- .read = test_smp_read,
+ .read_iter = test_smp_read,
.llseek = default_llseek,
};

--
2.43.0