summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2018-05-29 09:33:48 -0400
committerMarcel Holtmann <marcel@holtmann.org>2018-05-30 02:16:04 -0400
commit3bf5e97d7bbd175248da02efca2b265d13fb6041 (patch)
treec52acb227090112c167fc5ceff3c5a3fb1d32d7d /net
parent9960521c44a5d828f29636ceac0600603ecbddbf (diff)
Bluetooth: Re-use kstrtobool_from_user()
Re-use kstrtobool_from_user() instead of open coded variant. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_core.c23
-rw-r--r--net/bluetooth/hci_debugfs.c24
-rw-r--r--net/bluetooth/smp.c12
3 files changed, 19 insertions, 40 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index b0ee9edaae35..1dec33790198 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -76,19 +76,15 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
76{ 76{
77 struct hci_dev *hdev = file->private_data; 77 struct hci_dev *hdev = file->private_data;
78 struct sk_buff *skb; 78 struct sk_buff *skb;
79 char buf[32];
80 size_t buf_size = min(count, (sizeof(buf)-1));
81 bool enable; 79 bool enable;
80 int err;
82 81
83 if (!test_bit(HCI_UP, &hdev->flags)) 82 if (!test_bit(HCI_UP, &hdev->flags))
84 return -ENETDOWN; 83 return -ENETDOWN;
85 84
86 if (copy_from_user(buf, user_buf, buf_size)) 85 err = kstrtobool_from_user(user_buf, count, &enable);
87 return -EFAULT; 86 if (err)
88 87 return err;
89 buf[buf_size] = '\0';
90 if (strtobool(buf, &enable))
91 return -EINVAL;
92 88
93 if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE)) 89 if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE))
94 return -EALREADY; 90 return -EALREADY;
@@ -135,17 +131,12 @@ static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf,
135 size_t count, loff_t *ppos) 131 size_t count, loff_t *ppos)
136{ 132{
137 struct hci_dev *hdev = file->private_data; 133 struct hci_dev *hdev = file->private_data;
138 char buf[32];
139 size_t buf_size = min(count, (sizeof(buf)-1));
140 bool enable; 134 bool enable;
141 int err; 135 int err;
142 136
143 if (copy_from_user(buf, user_buf, buf_size)) 137 err = kstrtobool_from_user(user_buf, count, &enable);
144 return -EFAULT; 138 if (err)
145 139 return err;
146 buf[buf_size] = '\0';
147 if (strtobool(buf, &enable))
148 return -EINVAL;
149 140
150 /* When the diagnostic flags are not persistent and the transport 141 /* When the diagnostic flags are not persistent and the transport
151 * is not active or in user channel operation, then there is no need 142 * is not active or in user channel operation, then there is no need
diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c
index 418b76e557b0..0d8ab5b3c177 100644
--- a/net/bluetooth/hci_debugfs.c
+++ b/net/bluetooth/hci_debugfs.c
@@ -47,19 +47,15 @@ static ssize_t __name ## _write(struct file *file, \
47 size_t count, loff_t *ppos) \ 47 size_t count, loff_t *ppos) \
48{ \ 48{ \
49 struct hci_dev *hdev = file->private_data; \ 49 struct hci_dev *hdev = file->private_data; \
50 char buf[32]; \
51 size_t buf_size = min(count, (sizeof(buf) - 1)); \
52 bool enable; \ 50 bool enable; \
51 int err; \
53 \ 52 \
54 if (test_bit(HCI_UP, &hdev->flags)) \ 53 if (test_bit(HCI_UP, &hdev->flags)) \
55 return -EBUSY; \ 54 return -EBUSY; \
56 \ 55 \
57 if (copy_from_user(buf, user_buf, buf_size)) \ 56 err = kstrtobool_from_user(user_buf, count, &enable); \
58 return -EFAULT; \ 57 if (err) \
59 \ 58 return err; \
60 buf[buf_size] = '\0'; \
61 if (strtobool(buf, &enable)) \
62 return -EINVAL; \
63 \ 59 \
64 if (enable == test_bit(__quirk, &hdev->quirks)) \ 60 if (enable == test_bit(__quirk, &hdev->quirks)) \
65 return -EALREADY; \ 61 return -EALREADY; \
@@ -658,19 +654,15 @@ static ssize_t force_static_address_write(struct file *file,
658 size_t count, loff_t *ppos) 654 size_t count, loff_t *ppos)
659{ 655{
660 struct hci_dev *hdev = file->private_data; 656 struct hci_dev *hdev = file->private_data;
661 char buf[32];
662 size_t buf_size = min(count, (sizeof(buf)-1));
663 bool enable; 657 bool enable;
658 int err;
664 659
665 if (test_bit(HCI_UP, &hdev->flags)) 660 if (test_bit(HCI_UP, &hdev->flags))
666 return -EBUSY; 661 return -EBUSY;
667 662
668 if (copy_from_user(buf, user_buf, buf_size)) 663 err = kstrtobool_from_user(user_buf, count, &enable);
669 return -EFAULT; 664 if (err)
670 665 return err;
671 buf[buf_size] = '\0';
672 if (strtobool(buf, &enable))
673 return -EINVAL;
674 666
675 if (enable == hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR)) 667 if (enable == hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR))
676 return -EALREADY; 668 return -EALREADY;
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index a2ddae2f37d7..ae91e2d40056 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -3315,16 +3315,12 @@ static ssize_t force_bredr_smp_write(struct file *file,
3315 size_t count, loff_t *ppos) 3315 size_t count, loff_t *ppos)
3316{ 3316{
3317 struct hci_dev *hdev = file->private_data; 3317 struct hci_dev *hdev = file->private_data;
3318 char buf[32];
3319 size_t buf_size = min(count, (sizeof(buf)-1));
3320 bool enable; 3318 bool enable;
3319 int err;
3321 3320
3322 if (copy_from_user(buf, user_buf, buf_size)) 3321 err = kstrtobool_from_user(user_buf, count, &enable);
3323 return -EFAULT; 3322 if (err)
3324 3323 return err;
3325 buf[buf_size] = '\0';
3326 if (strtobool(buf, &enable))
3327 return -EINVAL;
3328 3324
3329 if (enable == hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP)) 3325 if (enable == hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP))
3330 return -EALREADY; 3326 return -EALREADY;