Bluetooth: Fix HCIUARTGETDEVICE ioctl when UART is not registered
[pandora-kernel.git] / drivers / bluetooth / hci_ldisc.c
index e00f8f5..dc487b5 100644 (file)
@@ -431,6 +431,9 @@ static int hci_uart_register_dev(struct hci_uart *hu)
        if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags))
                set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
 
+       if (test_bit(HCI_UART_EXT_CONFIG, &hu->hdev_flags))
+               set_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks);
+
        if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags))
                set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
 
@@ -477,6 +480,22 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
        return 0;
 }
 
+static int hci_uart_set_flags(struct hci_uart *hu, unsigned long flags)
+{
+       unsigned long valid_flags = BIT(HCI_UART_RAW_DEVICE) |
+                                   BIT(HCI_UART_RESET_ON_INIT) |
+                                   BIT(HCI_UART_CREATE_AMP) |
+                                   BIT(HCI_UART_INIT_PENDING) |
+                                   BIT(HCI_UART_EXT_CONFIG);
+
+       if ((flags & ~valid_flags))
+               return -EINVAL;
+
+       hu->hdev_flags = flags;
+
+       return 0;
+}
+
 /* hci_uart_tty_ioctl()
  *
  *    Process IOCTL system call for the tty device.
@@ -520,14 +539,16 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
                return -EUNATCH;
 
        case HCIUARTGETDEVICE:
-               if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
+               if (test_bit(HCI_UART_REGISTERED, &hu->flags))
                        return hu->hdev->id;
                return -EUNATCH;
 
        case HCIUARTSETFLAGS:
                if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
                        return -EBUSY;
-               hu->hdev_flags = arg;
+               err = hci_uart_set_flags(hu, arg);
+               if (err)
+                       return err;
                break;
 
        case HCIUARTGETFLAGS: