kfree(cmd);
}
-static int mgmt_pending_add(struct sock *sk, u16 opcode, int index,
- void *data, u16 len)
+static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
+ u16 index, void *data, u16 len)
{
struct pending_cmd *cmd;
cmd = kmalloc(sizeof(*cmd), GFP_ATOMIC);
if (!cmd)
- return -ENOMEM;
+ return NULL;
cmd->opcode = opcode;
cmd->index = index;
cmd->cmd = kmalloc(len, GFP_ATOMIC);
if (!cmd->cmd) {
kfree(cmd);
- return -ENOMEM;
+ return NULL;
}
memcpy(cmd->cmd, data, len);
list_add(&cmd->list, &cmd_list);
- return 0;
+ return cmd;
}
static void mgmt_pending_foreach(u16 opcode, int index,
{
struct mgmt_mode *cp;
struct hci_dev *hdev;
+ struct pending_cmd *cmd;
u16 dev_id;
- int ret, up;
+ int err, up;
cp = (void *) data;
dev_id = get_unaligned_le16(&cp->index);
up = test_bit(HCI_UP, &hdev->flags);
if ((cp->val && up) || (!cp->val && !up)) {
- ret = cmd_status(sk, MGMT_OP_SET_POWERED, EALREADY);
+ err = cmd_status(sk, MGMT_OP_SET_POWERED, EALREADY);
goto failed;
}
if (mgmt_pending_find(MGMT_OP_SET_POWERED, dev_id)) {
- ret = cmd_status(sk, MGMT_OP_SET_POWERED, EBUSY);
+ err = cmd_status(sk, MGMT_OP_SET_POWERED, EBUSY);
goto failed;
}
- ret = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, dev_id, data, len);
- if (ret < 0)
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, dev_id, data, len);
+ if (!cmd) {
+ err = -ENOMEM;
goto failed;
+ }
if (cp->val)
queue_work(hdev->workqueue, &hdev->power_on);
else
queue_work(hdev->workqueue, &hdev->power_off);
- ret = 0;
+ err = 0;
failed:
hci_dev_unlock_bh(hdev);
hci_dev_put(hdev);
- return ret;
+ return err;
}
static int set_discoverable(struct sock *sk, unsigned char *data, u16 len)
{
struct mgmt_mode *cp;
struct hci_dev *hdev;
+ struct pending_cmd *cmd;
u16 dev_id;
u8 scan;
int err;
goto failed;
}
- err = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, dev_id, data, len);
- if (err < 0)
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, dev_id, data, len);
+ if (!cmd) {
+ err = -ENOMEM;
goto failed;
+ }
scan = SCAN_PAGE;
{
struct mgmt_mode *cp;
struct hci_dev *hdev;
+ struct pending_cmd *cmd;
u16 dev_id;
u8 scan;
int err;
goto failed;
}
- err = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, dev_id, data, len);
- if (err < 0)
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, dev_id, data, len);
+ if (!cmd) {
+ err = -ENOMEM;
goto failed;
+ }
if (cp->val)
scan = SCAN_PAGE;
struct hci_dev *hdev;
struct mgmt_cp_disconnect *cp;
struct hci_cp_disconnect dc;
+ struct pending_cmd *cmd;
struct hci_conn *conn;
u16 dev_id;
int err;
goto failed;
}
- err = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, dev_id, data, len);
- if (err < 0)
+ cmd = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, dev_id, data, len);
+ if (!cmd) {
+ err = -ENOMEM;
goto failed;
+ }
put_unaligned_le16(conn->handle, &dc.handle);
dc.reason = 0x13; /* Remote User Terminated Connection */
struct hci_dev *hdev;
struct mgmt_cp_pin_code_reply *cp;
struct hci_cp_pin_code_reply reply;
+ struct pending_cmd *cmd;
u16 dev_id;
int err;
goto failed;
}
- err = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, dev_id, data, len);
- if (err < 0)
+ cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, dev_id, data, len);
+ if (!cmd) {
+ err = -ENOMEM;
goto failed;
+ }
bacpy(&reply.bdaddr, &cp->bdaddr);
reply.pin_len = cp->pin_len;
{
struct hci_dev *hdev;
struct mgmt_cp_pin_code_neg_reply *cp;
+ struct pending_cmd *cmd;
u16 dev_id;
int err;
goto failed;
}
- err = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, dev_id,
+ cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, dev_id,
data, len);
- if (err < 0)
+ if (!cmd) {
+ err = -ENOMEM;
goto failed;
+ }
err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, sizeof(bdaddr_t),
&cp->bdaddr);