Skip to content

Commit

Permalink
Bluetooth: Introduce hci_dev_test_and_set_flag helper macro
Browse files Browse the repository at this point in the history
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: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
  • Loading branch information
Marcel Holtmann authored and Johan Hedberg committed Mar 13, 2015
1 parent a69d892 commit 238be78
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
1 change: 1 addition & 0 deletions include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_change_flag(hdev, nr) test_and_change_bit((nr), &(hdev)->dev_flags)

Expand Down
8 changes: 4 additions & 4 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

if ((scan & SCAN_PAGE))
conn_changed = !test_and_set_bit(HCI_CONNECTABLE,
&hdev->dev_flags);
conn_changed = !hci_dev_test_and_set_flag(hdev,
HCI_CONNECTABLE);
else
conn_changed = hci_dev_test_and_clear_flag(hdev,
HCI_CONNECTABLE);

if ((scan & SCAN_INQUIRY)) {
discov_changed = !test_and_set_bit(HCI_DISCOVERABLE,
&hdev->dev_flags);
discov_changed = !hci_dev_test_and_set_flag(hdev,
HCI_DISCOVERABLE);
} else {
hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
discov_changed = hci_dev_test_and_clear_flag(hdev,
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
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;
hci_dev_put(hdev);
goto done;
Expand Down
46 changes: 20 additions & 26 deletions net/bluetooth/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ static void rpa_expired(struct work_struct *work)

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;

INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off);
Expand Down Expand Up @@ -1579,8 +1579,7 @@ static void set_discoverable_complete(struct hci_dev *hdev, u8 status,

cp = cmd->param;
if (cp->val) {
changed = !test_and_set_bit(HCI_DISCOVERABLE,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev, HCI_DISCOVERABLE);

if (hdev->discov_timeout > 0) {
int to = msecs_to_jiffies(hdev->discov_timeout * 1000);
Expand Down Expand Up @@ -1836,8 +1835,8 @@ static void set_connectable_complete(struct hci_dev *hdev, u8 status,

cp = cmd->param;
if (cp->val) {
conn_changed = !test_and_set_bit(HCI_CONNECTABLE,
&hdev->dev_flags);
conn_changed = !hci_dev_test_and_set_flag(hdev,
HCI_CONNECTABLE);
discov_changed = false;
} else {
conn_changed = hci_dev_test_and_clear_flag(hdev,
Expand Down Expand Up @@ -2004,7 +2003,7 @@ static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data,
hci_dev_lock(hdev);

if (cp->val)
changed = !test_and_set_bit(HCI_BONDABLE, &hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE);
else
changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE);

Expand Down Expand Up @@ -2116,8 +2115,8 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
bool changed;

if (cp->val) {
changed = !test_and_set_bit(HCI_SSP_ENABLED,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev,
HCI_SSP_ENABLED);
} else {
changed = hci_dev_test_and_clear_flag(hdev,
HCI_SSP_ENABLED);
Expand Down Expand Up @@ -2204,7 +2203,7 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
}

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 {
if (hdev_is_powered(hdev)) {
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
Expand Down Expand Up @@ -2487,7 +2486,7 @@ static bool enable_service_cache(struct hci_dev *hdev)
if (!hdev_is_powered(hdev))
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,
CACHE_TIMEOUT);
return true;
Expand Down Expand Up @@ -2714,8 +2713,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
hci_link_keys_clear(hdev);

if (cp->debug_keys)
changed = !test_and_set_bit(HCI_KEEP_DEBUG_KEYS,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS);
else
changed = hci_dev_test_and_clear_flag(hdev,
HCI_KEEP_DEBUG_KEYS);
Expand Down Expand Up @@ -4463,8 +4461,7 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
bool changed;

if (cp->val) {
changed = !test_and_set_bit(HCI_ADVERTISING,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING);
if (cp->val == 0x02)
hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
else
Expand Down Expand Up @@ -4940,8 +4937,8 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
bool changed;

if (cp->val) {
changed = !test_and_set_bit(HCI_SC_ENABLED,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev,
HCI_SC_ENABLED);
if (cp->val == 0x02)
hci_dev_set_flag(hdev, HCI_SC_ONLY);
else
Expand Down Expand Up @@ -5011,15 +5008,14 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev,
hci_dev_lock(hdev);

if (cp->val)
changed = !test_and_set_bit(HCI_KEEP_DEBUG_KEYS,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS);
else
changed = hci_dev_test_and_clear_flag(hdev,
HCI_KEEP_DEBUG_KEYS);

if (cp->val == 0x02)
use_changed = !test_and_set_bit(HCI_USE_DEBUG_KEYS,
&hdev->dev_flags);
use_changed = !hci_dev_test_and_set_flag(hdev,
HCI_USE_DEBUG_KEYS);
else
use_changed = hci_dev_test_and_clear_flag(hdev,
HCI_USE_DEBUG_KEYS);
Expand Down Expand Up @@ -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);

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));
hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
} else {
Expand Down Expand Up @@ -6082,8 +6078,7 @@ static int set_external_config(struct sock *sk, struct hci_dev *hdev,
hci_dev_lock(hdev);

if (cp->config)
changed = !test_and_set_bit(HCI_EXT_CONFIGURED,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED);
else
changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED);

Expand Down Expand Up @@ -7090,8 +7085,7 @@ void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status)
}

if (test_bit(HCI_AUTH, &hdev->flags))
changed = !test_and_set_bit(HCI_LINK_SECURITY,
&hdev->dev_flags);
changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY);
else
changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY);

Expand Down Expand Up @@ -7141,7 +7135,7 @@ void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
}

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 {
changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED);
if (!changed)
Expand Down

0 comments on commit 238be78

Please sign in to comment.