Skip to content

Commit

Permalink
Bluetooth: Move handling of HCI_RUNNING flag into core
Browse files Browse the repository at this point in the history
Setting and clearing of HCI_RUNNING flag in each and every driver is
just duplicating the same code all over the place. So instead of having
the driver do it in their hdev->open and hdev->close callbacks, set it
globally in the core transport handling.

Signed-off-by: Marcel Holtmann <[email protected]>
Signed-off-by: Johan Hedberg <[email protected]>
  • Loading branch information
holtmann authored and Johan Hedberg committed Oct 5, 2015
1 parent 73d0d3c commit e9ca8bf
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 82 deletions.
8 changes: 0 additions & 8 deletions drivers/bluetooth/bfusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,12 @@ static int bfusb_open(struct hci_dev *hdev)

BT_DBG("hdev %p bfusb %p", hdev, data);

if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
return 0;

write_lock_irqsave(&data->lock, flags);

err = bfusb_rx_submit(data, NULL);
if (!err) {
for (i = 1; i < BFUSB_MAX_BULK_RX; i++)
bfusb_rx_submit(data, NULL);
} else {
clear_bit(HCI_RUNNING, &hdev->flags);
}

write_unlock_irqrestore(&data->lock, flags);
Expand All @@ -458,9 +453,6 @@ static int bfusb_close(struct hci_dev *hdev)

BT_DBG("hdev %p bfusb %p", hdev, data);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

write_lock_irqsave(&data->lock, flags);
write_unlock_irqrestore(&data->lock, flags);

Expand Down
6 changes: 0 additions & 6 deletions drivers/bluetooth/bluecard_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,6 @@ static int bluecard_hci_open(struct hci_dev *hdev)
if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);

if (test_and_set_bit(HCI_RUNNING, &(hdev->flags)))
return 0;

if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
unsigned int iobase = info->p_dev->resource[0]->start;

Expand All @@ -646,9 +643,6 @@ static int bluecard_hci_close(struct hci_dev *hdev)
{
struct bluecard_info *info = hci_get_drvdata(hdev);

if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
return 0;

bluecard_hci_flush(hdev);

if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
Expand Down
8 changes: 0 additions & 8 deletions drivers/bluetooth/bpa10x.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ static int bpa10x_open(struct hci_dev *hdev)

BT_DBG("%s", hdev->name);

if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
return 0;

err = bpa10x_submit_intr_urb(hdev);
if (err < 0)
goto error;
Expand All @@ -320,8 +317,6 @@ static int bpa10x_open(struct hci_dev *hdev)
error:
usb_kill_anchored_urbs(&data->rx_anchor);

clear_bit(HCI_RUNNING, &hdev->flags);

return err;
}

Expand All @@ -331,9 +326,6 @@ static int bpa10x_close(struct hci_dev *hdev)

BT_DBG("%s", hdev->name);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

usb_kill_anchored_urbs(&data->rx_anchor);

return 0;
Expand Down
6 changes: 0 additions & 6 deletions drivers/bluetooth/bt3c_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ static void bt3c_receive(struct bt3c_info *info)
/* Unknown packet */
BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
info->hdev->stat.err_rx++;
clear_bit(HCI_RUNNING, &(info->hdev->flags));

kfree_skb(info->rx_skb);
info->rx_skb = NULL;
Expand Down Expand Up @@ -395,17 +394,12 @@ static int bt3c_hci_flush(struct hci_dev *hdev)

static int bt3c_hci_open(struct hci_dev *hdev)
{
set_bit(HCI_RUNNING, &(hdev->flags));

return 0;
}


static int bt3c_hci_close(struct hci_dev *hdev)
{
if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
return 0;

bt3c_hci_flush(hdev);

return 0;
Expand Down
5 changes: 0 additions & 5 deletions drivers/bluetooth/btmrvl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,13 @@ static int btmrvl_close(struct hci_dev *hdev)
{
struct btmrvl_private *priv = hci_get_drvdata(hdev);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

skb_queue_purge(&priv->adapter->tx_queue);

return 0;
}

static int btmrvl_open(struct hci_dev *hdev)
{
set_bit(HCI_RUNNING, &hdev->flags);

return 0;
}

Expand Down
11 changes: 1 addition & 10 deletions drivers/bluetooth/btsdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,15 @@ static int btsdio_open(struct hci_dev *hdev)

BT_DBG("%s", hdev->name);

if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
return 0;

sdio_claim_host(data->func);

err = sdio_enable_func(data->func);
if (err < 0) {
clear_bit(HCI_RUNNING, &hdev->flags);
if (err < 0)
goto release;
}

err = sdio_claim_irq(data->func, btsdio_interrupt);
if (err < 0) {
sdio_disable_func(data->func);
clear_bit(HCI_RUNNING, &hdev->flags);
goto release;
}

Expand All @@ -229,9 +223,6 @@ static int btsdio_close(struct hci_dev *hdev)

BT_DBG("%s", hdev->name);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

sdio_claim_host(data->func);

sdio_writeb(data->func, 0x00, REG_EN_INTRD, NULL);
Expand Down
6 changes: 0 additions & 6 deletions drivers/bluetooth/btuart_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ static void btuart_receive(struct btuart_info *info)
/* Unknown packet */
BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
info->hdev->stat.err_rx++;
clear_bit(HCI_RUNNING, &(info->hdev->flags));

kfree_skb(info->rx_skb);
info->rx_skb = NULL;
Expand Down Expand Up @@ -409,17 +408,12 @@ static int btuart_hci_flush(struct hci_dev *hdev)

static int btuart_hci_open(struct hci_dev *hdev)
{
set_bit(HCI_RUNNING, &(hdev->flags));

return 0;
}


static int btuart_hci_close(struct hci_dev *hdev)
{
if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
return 0;

btuart_hci_flush(hdev);

return 0;
Expand Down
7 changes: 0 additions & 7 deletions drivers/bluetooth/btusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,6 @@ static int btusb_open(struct hci_dev *hdev)

data->intf->needs_remote_wakeup = 1;

if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
goto done;

if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
goto done;

Expand All @@ -965,7 +962,6 @@ static int btusb_open(struct hci_dev *hdev)

failed:
clear_bit(BTUSB_INTR_RUNNING, &data->flags);
clear_bit(HCI_RUNNING, &hdev->flags);
usb_autopm_put_interface(data->intf);
return err;
}
Expand All @@ -984,9 +980,6 @@ static int btusb_close(struct hci_dev *hdev)

BT_DBG("%s", hdev->name);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

cancel_work_sync(&data->work);
cancel_work_sync(&data->waker);

Expand Down
10 changes: 0 additions & 10 deletions drivers/bluetooth/btwilink.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ static int ti_st_open(struct hci_dev *hdev)

BT_DBG("%s %p", hdev->name, hdev);

if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
return -EBUSY;

/* provide contexts for callbacks from ST */
hst = hci_get_drvdata(hdev);

Expand All @@ -181,7 +178,6 @@ static int ti_st_open(struct hci_dev *hdev)
goto done;

if (err != -EINPROGRESS) {
clear_bit(HCI_RUNNING, &hdev->flags);
BT_ERR("st_register failed %d", err);
return err;
}
Expand All @@ -195,7 +191,6 @@ static int ti_st_open(struct hci_dev *hdev)
(&hst->wait_reg_completion,
msecs_to_jiffies(BT_REGISTER_TIMEOUT));
if (!timeleft) {
clear_bit(HCI_RUNNING, &hdev->flags);
BT_ERR("Timeout(%d sec),didn't get reg "
"completion signal from ST",
BT_REGISTER_TIMEOUT / 1000);
Expand All @@ -205,7 +200,6 @@ static int ti_st_open(struct hci_dev *hdev)
/* Is ST registration callback
* called with ERROR status? */
if (hst->reg_status != 0) {
clear_bit(HCI_RUNNING, &hdev->flags);
BT_ERR("ST registration completed with invalid "
"status %d", hst->reg_status);
return -EAGAIN;
Expand All @@ -215,7 +209,6 @@ static int ti_st_open(struct hci_dev *hdev)
hst->st_write = ti_st_proto[i].write;
if (!hst->st_write) {
BT_ERR("undefined ST write function");
clear_bit(HCI_RUNNING, &hdev->flags);
for (i = 0; i < MAX_BT_CHNL_IDS; i++) {
/* Undo registration with ST */
err = st_unregister(&ti_st_proto[i]);
Expand All @@ -236,9 +229,6 @@ static int ti_st_close(struct hci_dev *hdev)
int err, i;
struct ti_st *hst = hci_get_drvdata(hdev);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

for (i = MAX_BT_CHNL_IDS-1; i >= 0; i--) {
err = st_unregister(&ti_st_proto[i]);
if (err)
Expand Down
5 changes: 0 additions & 5 deletions drivers/bluetooth/dtl1_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ static irqreturn_t dtl1_interrupt(int irq, void *dev_inst)

static int dtl1_hci_open(struct hci_dev *hdev)
{
set_bit(HCI_RUNNING, &(hdev->flags));

return 0;
}

Expand All @@ -376,9 +374,6 @@ static int dtl1_hci_flush(struct hci_dev *hdev)

static int dtl1_hci_close(struct hci_dev *hdev)
{
if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
return 0;

dtl1_hci_flush(hdev);

return 0;
Expand Down
6 changes: 0 additions & 6 deletions drivers/bluetooth/hci_ldisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ static int hci_uart_open(struct hci_dev *hdev)
BT_DBG("%s %p", hdev->name, hdev);

/* Nothing to do for UART driver */

set_bit(HCI_RUNNING, &hdev->flags);

return 0;
}

Expand Down Expand Up @@ -241,9 +238,6 @@ static int hci_uart_close(struct hci_dev *hdev)
{
BT_DBG("hdev %p", hdev);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

hci_uart_flush(hdev);
hdev->flush = NULL;
return 0;
Expand Down
5 changes: 0 additions & 5 deletions drivers/bluetooth/hci_vhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,13 @@ struct vhci_data {

static int vhci_open_dev(struct hci_dev *hdev)
{
set_bit(HCI_RUNNING, &hdev->flags);

return 0;
}

static int vhci_close_dev(struct hci_dev *hdev)
{
struct vhci_data *data = hci_get_drvdata(hdev);

if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;

skb_queue_purge(&data->readq);

return 0;
Expand Down
3 changes: 3 additions & 0 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ static int hci_dev_do_open(struct hci_dev *hdev)
goto done;
}

set_bit(HCI_RUNNING, &hdev->flags);
hci_notify(hdev, HCI_DEV_OPEN);

atomic_set(&hdev->cmd_cnt, 1);
Expand Down Expand Up @@ -1468,6 +1469,7 @@ static int hci_dev_do_open(struct hci_dev *hdev)
hdev->sent_cmd = NULL;
}

clear_bit(HCI_RUNNING, &hdev->flags);
hci_notify(hdev, HCI_DEV_CLOSE);

hdev->close(hdev);
Expand Down Expand Up @@ -1653,6 +1655,7 @@ int hci_dev_do_close(struct hci_dev *hdev)
hdev->sent_cmd = NULL;
}

clear_bit(HCI_RUNNING, &hdev->flags);
hci_notify(hdev, HCI_DEV_CLOSE);

/* After this point our queues are empty
Expand Down

0 comments on commit e9ca8bf

Please sign in to comment.