Bluetooth: Move handling of HCI_RUNNING flag into core
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 <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
73d0d3c867
commit
e9ca8bf157
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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))) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -470,9 +470,6 @@ 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;
|
||||
|
@ -480,8 +477,6 @@ static int btmrvl_close(struct hci_dev *hdev)
|
|||
|
||||
static int btmrvl_open(struct hci_dev *hdev)
|
||||
{
|
||||
set_bit(HCI_RUNNING, &hdev->flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -965,7 +962,6 @@ done:
|
|||
|
||||
failed:
|
||||
clear_bit(BTUSB_INTR_RUNNING, &data->flags);
|
||||
clear_bit(HCI_RUNNING, &hdev->flags);
|
||||
usb_autopm_put_interface(data->intf);
|
||||
return err;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -215,7 +209,6 @@ done:
|
|||
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]);
|
||||
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -55,8 +55,6 @@ struct vhci_data {
|
|||
|
||||
static int vhci_open_dev(struct hci_dev *hdev)
|
||||
{
|
||||
set_bit(HCI_RUNNING, &hdev->flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -64,9 +62,6 @@ 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;
|
||||
|
|
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue