Commit 238be788 authored by Marcel Holtmann's avatar Marcel Holtmann Committed by Johan Hedberg

Bluetooth: Introduce hci_dev_test_and_set_flag helper macro

Instead of manually coding test_and_set_bit on hdev->dev_flags all the
time, use hci_dev_test_and_set_flag helper macro.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent a69d8927
...@@ -507,6 +507,7 @@ extern struct mutex hci_cb_list_lock; ...@@ -507,6 +507,7 @@ extern struct mutex hci_cb_list_lock;
#define hci_dev_change_flag(hdev, nr) change_bit((nr), &(hdev)->dev_flags) #define hci_dev_change_flag(hdev, nr) change_bit((nr), &(hdev)->dev_flags)
#define hci_dev_test_flag(hdev, nr) test_bit((nr), &(hdev)->dev_flags) #define hci_dev_test_flag(hdev, nr) test_bit((nr), &(hdev)->dev_flags)
#define hci_dev_test_and_set_flag(hdev, nr) test_and_set_bit((nr), &(hdev)->dev_flags)
#define hci_dev_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), &(hdev)->dev_flags) #define hci_dev_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), &(hdev)->dev_flags)
#define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), &(hdev)->dev_flags) #define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), &(hdev)->dev_flags)
......
...@@ -1836,15 +1836,15 @@ static void hci_update_scan_state(struct hci_dev *hdev, u8 scan) ...@@ -1836,15 +1836,15 @@ static void hci_update_scan_state(struct hci_dev *hdev, u8 scan)
BT_DBG("%s scan 0x%02x", hdev->name, scan); BT_DBG("%s scan 0x%02x", hdev->name, scan);
if ((scan & SCAN_PAGE)) if ((scan & SCAN_PAGE))
conn_changed = !test_and_set_bit(HCI_CONNECTABLE, conn_changed = !hci_dev_test_and_set_flag(hdev,
&hdev->dev_flags); HCI_CONNECTABLE);
else else
conn_changed = hci_dev_test_and_clear_flag(hdev, conn_changed = hci_dev_test_and_clear_flag(hdev,
HCI_CONNECTABLE); HCI_CONNECTABLE);
if ((scan & SCAN_INQUIRY)) { if ((scan & SCAN_INQUIRY)) {
discov_changed = !test_and_set_bit(HCI_DISCOVERABLE, discov_changed = !hci_dev_test_and_set_flag(hdev,
&hdev->dev_flags); HCI_DISCOVERABLE);
} else { } else {
hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
discov_changed = hci_dev_test_and_clear_flag(hdev, discov_changed = hci_dev_test_and_clear_flag(hdev,
......
...@@ -720,7 +720,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -720,7 +720,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
goto done; goto done;
} }
if (test_and_set_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) { if (hci_dev_test_and_set_flag(hdev, HCI_USER_CHANNEL)) {
err = -EUSERS; err = -EUSERS;
hci_dev_put(hdev); hci_dev_put(hdev);
goto done; goto done;
......
...@@ -1178,7 +1178,7 @@ static void rpa_expired(struct work_struct *work) ...@@ -1178,7 +1178,7 @@ static void rpa_expired(struct work_struct *work)
static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev)
{ {
if (test_and_set_bit(HCI_MGMT, &hdev->dev_flags)) if (hci_dev_test_and_set_flag(hdev, HCI_MGMT))
return; return;
INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off);
...@@ -1579,8 +1579,7 @@ static void set_discoverable_complete(struct hci_dev *hdev, u8 status, ...@@ -1579,8 +1579,7 @@ static void set_discoverable_complete(struct hci_dev *hdev, u8 status,
cp = cmd->param; cp = cmd->param;
if (cp->val) { if (cp->val) {
changed = !test_and_set_bit(HCI_DISCOVERABLE, changed = !hci_dev_test_and_set_flag(hdev, HCI_DISCOVERABLE);
&hdev->dev_flags);
if (hdev->discov_timeout > 0) { if (hdev->discov_timeout > 0) {
int to = msecs_to_jiffies(hdev->discov_timeout * 1000); int to = msecs_to_jiffies(hdev->discov_timeout * 1000);
...@@ -1836,8 +1835,8 @@ static void set_connectable_complete(struct hci_dev *hdev, u8 status, ...@@ -1836,8 +1835,8 @@ static void set_connectable_complete(struct hci_dev *hdev, u8 status,
cp = cmd->param; cp = cmd->param;
if (cp->val) { if (cp->val) {
conn_changed = !test_and_set_bit(HCI_CONNECTABLE, conn_changed = !hci_dev_test_and_set_flag(hdev,
&hdev->dev_flags); HCI_CONNECTABLE);
discov_changed = false; discov_changed = false;
} else { } else {
conn_changed = hci_dev_test_and_clear_flag(hdev, conn_changed = hci_dev_test_and_clear_flag(hdev,
...@@ -2004,7 +2003,7 @@ static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -2004,7 +2003,7 @@ static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data,
hci_dev_lock(hdev); hci_dev_lock(hdev);
if (cp->val) if (cp->val)
changed = !test_and_set_bit(HCI_BONDABLE, &hdev->dev_flags); changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE);
else else
changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE);
...@@ -2116,8 +2115,8 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) ...@@ -2116,8 +2115,8 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
bool changed; bool changed;
if (cp->val) { if (cp->val) {
changed = !test_and_set_bit(HCI_SSP_ENABLED, changed = !hci_dev_test_and_set_flag(hdev,
&hdev->dev_flags); HCI_SSP_ENABLED);
} else { } else {
changed = hci_dev_test_and_clear_flag(hdev, changed = hci_dev_test_and_clear_flag(hdev,
HCI_SSP_ENABLED); HCI_SSP_ENABLED);
...@@ -2204,7 +2203,7 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) ...@@ -2204,7 +2203,7 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
} }
if (cp->val) { if (cp->val) {
changed = !test_and_set_bit(HCI_HS_ENABLED, &hdev->dev_flags); changed = !hci_dev_test_and_set_flag(hdev, HCI_HS_ENABLED);
} else { } else {
if (hdev_is_powered(hdev)) { if (hdev_is_powered(hdev)) {
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
...@@ -2487,7 +2486,7 @@ static bool enable_service_cache(struct hci_dev *hdev) ...@@ -2487,7 +2486,7 @@ static bool enable_service_cache(struct hci_dev *hdev)
if (!hdev_is_powered(hdev)) if (!hdev_is_powered(hdev))
return false; return false;
if (!test_and_set_bit(HCI_SERVICE_CACHE, &hdev->dev_flags)) { if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) {
queue_delayed_work(hdev->workqueue, &hdev->service_cache, queue_delayed_work(hdev->workqueue, &hdev->service_cache,
CACHE_TIMEOUT); CACHE_TIMEOUT);
return true; return true;
...@@ -2714,8 +2713,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -2714,8 +2713,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
hci_link_keys_clear(hdev); hci_link_keys_clear(hdev);
if (cp->debug_keys) if (cp->debug_keys)
changed = !test_and_set_bit(HCI_KEEP_DEBUG_KEYS, changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS);
&hdev->dev_flags);
else else
changed = hci_dev_test_and_clear_flag(hdev, changed = hci_dev_test_and_clear_flag(hdev,
HCI_KEEP_DEBUG_KEYS); HCI_KEEP_DEBUG_KEYS);
...@@ -4463,8 +4461,7 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -4463,8 +4461,7 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
bool changed; bool changed;
if (cp->val) { if (cp->val) {
changed = !test_and_set_bit(HCI_ADVERTISING, changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING);
&hdev->dev_flags);
if (cp->val == 0x02) if (cp->val == 0x02)
hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
else else
...@@ -4940,8 +4937,8 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, ...@@ -4940,8 +4937,8 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
bool changed; bool changed;
if (cp->val) { if (cp->val) {
changed = !test_and_set_bit(HCI_SC_ENABLED, changed = !hci_dev_test_and_set_flag(hdev,
&hdev->dev_flags); HCI_SC_ENABLED);
if (cp->val == 0x02) if (cp->val == 0x02)
hci_dev_set_flag(hdev, HCI_SC_ONLY); hci_dev_set_flag(hdev, HCI_SC_ONLY);
else else
...@@ -5011,15 +5008,14 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, ...@@ -5011,15 +5008,14 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev,
hci_dev_lock(hdev); hci_dev_lock(hdev);
if (cp->val) if (cp->val)
changed = !test_and_set_bit(HCI_KEEP_DEBUG_KEYS, changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS);
&hdev->dev_flags);
else else
changed = hci_dev_test_and_clear_flag(hdev, changed = hci_dev_test_and_clear_flag(hdev,
HCI_KEEP_DEBUG_KEYS); HCI_KEEP_DEBUG_KEYS);
if (cp->val == 0x02) if (cp->val == 0x02)
use_changed = !test_and_set_bit(HCI_USE_DEBUG_KEYS, use_changed = !hci_dev_test_and_set_flag(hdev,
&hdev->dev_flags); HCI_USE_DEBUG_KEYS);
else else
use_changed = hci_dev_test_and_clear_flag(hdev, use_changed = hci_dev_test_and_clear_flag(hdev,
HCI_USE_DEBUG_KEYS); HCI_USE_DEBUG_KEYS);
...@@ -5072,7 +5068,7 @@ static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, ...@@ -5072,7 +5068,7 @@ static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data,
hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); hci_dev_set_flag(hdev, HCI_RPA_RESOLVING);
if (cp->privacy) { if (cp->privacy) {
changed = !test_and_set_bit(HCI_PRIVACY, &hdev->dev_flags); changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY);
memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); memcpy(hdev->irk, cp->irk, sizeof(hdev->irk));
hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
} else { } else {
...@@ -6082,8 +6078,7 @@ static int set_external_config(struct sock *sk, struct hci_dev *hdev, ...@@ -6082,8 +6078,7 @@ static int set_external_config(struct sock *sk, struct hci_dev *hdev,
hci_dev_lock(hdev); hci_dev_lock(hdev);
if (cp->config) if (cp->config)
changed = !test_and_set_bit(HCI_EXT_CONFIGURED, changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED);
&hdev->dev_flags);
else else
changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED);
...@@ -7090,8 +7085,7 @@ void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) ...@@ -7090,8 +7085,7 @@ void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status)
} }
if (test_bit(HCI_AUTH, &hdev->flags)) if (test_bit(HCI_AUTH, &hdev->flags))
changed = !test_and_set_bit(HCI_LINK_SECURITY, changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY);
&hdev->dev_flags);
else else
changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY);
...@@ -7141,7 +7135,7 @@ void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status) ...@@ -7141,7 +7135,7 @@ void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
} }
if (enable) { if (enable) {
changed = !test_and_set_bit(HCI_SSP_ENABLED, &hdev->dev_flags); changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED);
} else { } else {
changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED);
if (!changed) if (!changed)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment