Bluetooth: Use memdup_user in le_auto_conn_write()
authorAndre Guedes <andre.guedes@openbossa.org>
Mon, 24 Mar 2014 19:08:48 +0000 (16:08 -0300)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 26 Mar 2014 16:31:34 +0000 (09:31 -0700)
This patch does a small code simplification replacing the tipical
kmalloc-copy_from_user sequence by memdup_user() helper.

Cc: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/hci_core.c

index 1c6ffaa8902f5e9fe32a86f2a19cf9073d6f0dae..bfc6f810554e21f08997ef7dbd9e6b4f99ea29bc 100644 (file)
@@ -955,14 +955,9 @@ static ssize_t le_auto_conn_write(struct file *file, const char __user *data,
        if (count < 3)
                return -EINVAL;
 
-       buf = kzalloc(count, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       if (copy_from_user(buf, data, count)) {
-               err = -EFAULT;
-               goto done;
-       }
+       buf = memdup_user(data, count);
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
 
        if (memcmp(buf, "add", 3) == 0) {
                n = sscanf(&buf[4], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu %hhu",