Skip to content

Commit

Permalink
Bluetooth: Pass full hci_dev struct to mgmt callbacks
Browse files Browse the repository at this point in the history
The current global pending command list in mgmt.c is racy. Possibly the
simplest way to fix it is to have per-hci dev lists instead of a global
one (all commands that need a pending struct are hci_dev specific).
This way the list can be protected using the already existing per-hci
dev lock. To enable this refactoring the first thing that needs to be
done is to ensure that the mgmt functions have access to the hci_dev
struct (instead of just the dev id).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
  • Loading branch information
Johan Hedberg authored and Gustavo F. Padovan committed Nov 9, 2011
1 parent 4c659c3 commit 744cf19
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 168 deletions.
61 changes: 33 additions & 28 deletions include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,36 +905,41 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb,

/* Management interface */
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
int mgmt_index_added(u16 index);
int mgmt_index_removed(u16 index);
int mgmt_powered(u16 index, u8 powered);
int mgmt_discoverable(u16 index, u8 discoverable);
int mgmt_connectable(u16 index, u8 connectable);
int mgmt_write_scan_failed(u16 index, u8 scan, u8 status);
int mgmt_new_link_key(u16 index, struct link_key *key, u8 persistent);
int mgmt_connected(u16 index, bdaddr_t *bdaddr, u8 type);
int mgmt_disconnected(u16 index, bdaddr_t *bdaddr, u8 type);
int mgmt_disconnect_failed(u16 index);
int mgmt_connect_failed(u16 index, bdaddr_t *bdaddr, u8 type, u8 status);
int mgmt_pin_code_request(u16 index, bdaddr_t *bdaddr, u8 secure);
int mgmt_pin_code_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status);
int mgmt_pin_code_neg_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status);
int mgmt_user_confirm_request(u16 index, bdaddr_t *bdaddr, __le32 value,
u8 confirm_hint);
int mgmt_user_confirm_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status);
int mgmt_user_confirm_neg_reply_complete(u16 index, bdaddr_t *bdaddr,
int mgmt_index_added(struct hci_dev *hdev);
int mgmt_index_removed(struct hci_dev *hdev);
int mgmt_powered(struct hci_dev *hdev, u8 powered);
int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
u8 persistent);
int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
int mgmt_disconnect_failed(struct hci_dev *hdev);
int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type,
u8 status);
int mgmt_auth_failed(u16 index, bdaddr_t *bdaddr, u8 status);
int mgmt_set_local_name_complete(u16 index, u8 *name, u8 status);
int mgmt_read_local_oob_data_reply_complete(u16 index, u8 *hash, u8 *randomizer,
int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
u8 status);
int mgmt_device_found(u16 index, bdaddr_t *bdaddr, u8 type, u8 *dev_class,
s8 rssi, u8 *eir);
int mgmt_remote_name(u16 index, bdaddr_t *bdaddr, u8 *name);
int mgmt_inquiry_failed(u16 index, u8 status);
int mgmt_discovering(u16 index, u8 discovering);
int mgmt_device_blocked(u16 index, bdaddr_t *bdaddr);
int mgmt_device_unblocked(u16 index, bdaddr_t *bdaddr);
int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
u8 status);
int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
__le32 value, u8 confirm_hint);
int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
u8 status);
int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev,
bdaddr_t *bdaddr, u8 status);
int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
u8 *randomizer, u8 status);
int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type,
u8 *dev_class, s8 rssi, u8 *eir);
int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *name);
int mgmt_inquiry_failed(struct hci_dev *hdev, u8 status);
int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr);
int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr);

/* HCI info for socket */
#define hci_pi(sk) ((struct hci_pinfo *) sk)
Expand Down
16 changes: 8 additions & 8 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ int hci_dev_open(__u16 dev)
set_bit(HCI_UP, &hdev->flags);
hci_notify(hdev, HCI_DEV_UP);
if (!test_bit(HCI_SETUP, &hdev->flags))
mgmt_powered(hdev->id, 1);
mgmt_powered(hdev, 1);
} else {
/* Init failed, cleanup */
tasklet_kill(&hdev->rx_task);
Expand Down Expand Up @@ -642,7 +642,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
* and no tasks are scheduled. */
hdev->close(hdev);

mgmt_powered(hdev->id, 0);
mgmt_powered(hdev, 0);

/* Clear flags */
hdev->flags = 0;
Expand Down Expand Up @@ -947,7 +947,7 @@ static void hci_power_on(struct work_struct *work)
msecs_to_jiffies(AUTO_OFF_TIMEOUT));

if (test_and_clear_bit(HCI_SETUP, &hdev->flags))
mgmt_index_added(hdev->id);
mgmt_index_added(hdev);
}

static void hci_power_off(struct work_struct *work)
Expand Down Expand Up @@ -1140,7 +1140,7 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,

persistent = hci_persistent_key(hdev, conn, type, old_key_type);

mgmt_new_link_key(hdev->id, key, persistent);
mgmt_new_link_key(hdev, key, persistent);

if (!persistent) {
list_del(&key->list);
Expand Down Expand Up @@ -1183,7 +1183,7 @@ int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr,
memcpy(id->rand, rand, sizeof(id->rand));

if (new_key)
mgmt_new_link_key(hdev->id, key, old_key_type);
mgmt_new_link_key(hdev, key, old_key_type);

return 0;
}
Expand Down Expand Up @@ -1324,7 +1324,7 @@ int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr)

list_add(&entry->list, &hdev->blacklist);

return mgmt_device_blocked(hdev->id, bdaddr);
return mgmt_device_blocked(hdev, bdaddr);
}

int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr)
Expand All @@ -1343,7 +1343,7 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr)
list_del(&entry->list);
kfree(entry);

return mgmt_device_unblocked(hdev->id, bdaddr);
return mgmt_device_unblocked(hdev, bdaddr);
}

static void hci_clear_adv_cache(unsigned long arg)
Expand Down Expand Up @@ -1560,7 +1560,7 @@ void hci_unregister_dev(struct hci_dev *hdev)

if (!test_bit(HCI_INIT, &hdev->flags) &&
!test_bit(HCI_SETUP, &hdev->flags))
mgmt_index_removed(hdev->id);
mgmt_index_removed(hdev);

hci_notify(hdev, HCI_DEV_UNREG);

Expand Down
Loading

0 comments on commit 744cf19

Please sign in to comment.