提交 3bf5e97d 编写于 作者: A Andy Shevchenko 提交者: Marcel Holtmann

Bluetooth: Re-use kstrtobool_from_user()

Re-use kstrtobool_from_user() instead of open coded variant.
Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
上级 9960521c
...@@ -76,19 +76,15 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf, ...@@ -76,19 +76,15 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
{ {
struct hci_dev *hdev = file->private_data; struct hci_dev *hdev = file->private_data;
struct sk_buff *skb; struct sk_buff *skb;
char buf[32];
size_t buf_size = min(count, (sizeof(buf)-1));
bool enable; bool enable;
int err;
if (!test_bit(HCI_UP, &hdev->flags)) if (!test_bit(HCI_UP, &hdev->flags))
return -ENETDOWN; return -ENETDOWN;
if (copy_from_user(buf, user_buf, buf_size)) err = kstrtobool_from_user(user_buf, count, &enable);
return -EFAULT; if (err)
return err;
buf[buf_size] = '\0';
if (strtobool(buf, &enable))
return -EINVAL;
if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE)) if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE))
return -EALREADY; return -EALREADY;
...@@ -135,17 +131,12 @@ static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf, ...@@ -135,17 +131,12 @@ static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct hci_dev *hdev = file->private_data; struct hci_dev *hdev = file->private_data;
char buf[32];
size_t buf_size = min(count, (sizeof(buf)-1));
bool enable; bool enable;
int err; int err;
if (copy_from_user(buf, user_buf, buf_size)) err = kstrtobool_from_user(user_buf, count, &enable);
return -EFAULT; if (err)
return err;
buf[buf_size] = '\0';
if (strtobool(buf, &enable))
return -EINVAL;
/* When the diagnostic flags are not persistent and the transport /* When the diagnostic flags are not persistent and the transport
* is not active or in user channel operation, then there is no need * is not active or in user channel operation, then there is no need
......
...@@ -47,19 +47,15 @@ static ssize_t __name ## _write(struct file *file, \ ...@@ -47,19 +47,15 @@ static ssize_t __name ## _write(struct file *file, \
size_t count, loff_t *ppos) \ size_t count, loff_t *ppos) \
{ \ { \
struct hci_dev *hdev = file->private_data; \ struct hci_dev *hdev = file->private_data; \
char buf[32]; \
size_t buf_size = min(count, (sizeof(buf) - 1)); \
bool enable; \ bool enable; \
int err; \
\ \
if (test_bit(HCI_UP, &hdev->flags)) \ if (test_bit(HCI_UP, &hdev->flags)) \
return -EBUSY; \ return -EBUSY; \
\ \
if (copy_from_user(buf, user_buf, buf_size)) \ err = kstrtobool_from_user(user_buf, count, &enable); \
return -EFAULT; \ if (err) \
\ return err; \
buf[buf_size] = '\0'; \
if (strtobool(buf, &enable)) \
return -EINVAL; \
\ \
if (enable == test_bit(__quirk, &hdev->quirks)) \ if (enable == test_bit(__quirk, &hdev->quirks)) \
return -EALREADY; \ return -EALREADY; \
...@@ -658,19 +654,15 @@ static ssize_t force_static_address_write(struct file *file, ...@@ -658,19 +654,15 @@ static ssize_t force_static_address_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct hci_dev *hdev = file->private_data; struct hci_dev *hdev = file->private_data;
char buf[32];
size_t buf_size = min(count, (sizeof(buf)-1));
bool enable; bool enable;
int err;
if (test_bit(HCI_UP, &hdev->flags)) if (test_bit(HCI_UP, &hdev->flags))
return -EBUSY; return -EBUSY;
if (copy_from_user(buf, user_buf, buf_size)) err = kstrtobool_from_user(user_buf, count, &enable);
return -EFAULT; if (err)
return err;
buf[buf_size] = '\0';
if (strtobool(buf, &enable))
return -EINVAL;
if (enable == hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR)) if (enable == hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR))
return -EALREADY; return -EALREADY;
......
...@@ -3315,16 +3315,12 @@ static ssize_t force_bredr_smp_write(struct file *file, ...@@ -3315,16 +3315,12 @@ static ssize_t force_bredr_smp_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct hci_dev *hdev = file->private_data; struct hci_dev *hdev = file->private_data;
char buf[32];
size_t buf_size = min(count, (sizeof(buf)-1));
bool enable; bool enable;
int err;
if (copy_from_user(buf, user_buf, buf_size)) err = kstrtobool_from_user(user_buf, count, &enable);
return -EFAULT; if (err)
return err;
buf[buf_size] = '\0';
if (strtobool(buf, &enable))
return -EINVAL;
if (enable == hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP)) if (enable == hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP))
return -EALREADY; return -EALREADY;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册