Commit 64061607eab7cb146115927cb596de123c542d45

Authored by Bing Zhao
Committed by Marcel Holtmann
1 parent 903c843773

Bluetooth: Separate btmrvl_register_hdev() from btmrvl_add_card()

Move btmrvl hdev registration code out of btmrvl_add_card().
New function btmrvl_register_hdev() is added.

Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

Showing 3 changed files with 50 additions and 33 deletions Side-by-side Diff

drivers/bluetooth/btmrvl_drv.h
... ... @@ -126,6 +126,7 @@
126 126  
127 127 /* Prototype of global function */
128 128  
  129 +int btmrvl_register_hdev(struct btmrvl_private *priv);
129 130 struct btmrvl_private *btmrvl_add_card(void *card);
130 131 int btmrvl_remove_card(struct btmrvl_private *priv);
131 132  
drivers/bluetooth/btmrvl_main.c
... ... @@ -524,47 +524,20 @@
524 524 return 0;
525 525 }
526 526  
527   -struct btmrvl_private *btmrvl_add_card(void *card)
  527 +int btmrvl_register_hdev(struct btmrvl_private *priv)
528 528 {
529 529 struct hci_dev *hdev = NULL;
530   - struct btmrvl_private *priv;
531 530 int ret;
532 531  
533   - priv = kzalloc(sizeof(*priv), GFP_KERNEL);
534   - if (!priv) {
535   - BT_ERR("Can not allocate priv");
536   - goto err_priv;
537   - }
538   -
539   - priv->adapter = kzalloc(sizeof(*priv->adapter), GFP_KERNEL);
540   - if (!priv->adapter) {
541   - BT_ERR("Allocate buffer for btmrvl_adapter failed!");
542   - goto err_adapter;
543   - }
544   -
545   - btmrvl_init_adapter(priv);
546   -
547 532 hdev = hci_alloc_dev();
548 533 if (!hdev) {
549 534 BT_ERR("Can not allocate HCI device");
550 535 goto err_hdev;
551 536 }
552 537  
553   - BT_DBG("Starting kthread...");
554   - priv->main_thread.priv = priv;
555   - spin_lock_init(&priv->driver_lock);
556   -
557   - init_waitqueue_head(&priv->main_thread.wait_q);
558   - priv->main_thread.task = kthread_run(btmrvl_service_main_thread,
559   - &priv->main_thread, "btmrvl_main_service");
560   -
561 538 priv->btmrvl_dev.hcidev = hdev;
562   - priv->btmrvl_dev.card = card;
563   -
564 539 hdev->driver_data = priv;
565 540  
566   - priv->btmrvl_dev.tx_dnld_rdy = true;
567   -
568 541 hdev->bus = HCI_SDIO;
569 542 hdev->open = btmrvl_open;
570 543 hdev->close = btmrvl_close;
... ... @@ -574,6 +547,8 @@
574 547 hdev->ioctl = btmrvl_ioctl;
575 548 hdev->owner = THIS_MODULE;
576 549  
  550 + btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);
  551 +
577 552 ret = hci_register_dev(hdev);
578 553 if (ret < 0) {
579 554 BT_ERR("Can not register HCI device");
580 555  
581 556  
582 557  
... ... @@ -584,16 +559,52 @@
584 559 btmrvl_debugfs_init(hdev);
585 560 #endif
586 561  
587   - return priv;
  562 + return 0;
588 563  
589 564 err_hci_register_dev:
590   - /* Stop the thread servicing the interrupts */
591   - kthread_stop(priv->main_thread.task);
592   -
593 565 hci_free_dev(hdev);
594 566  
595 567 err_hdev:
  568 + /* Stop the thread servicing the interrupts */
  569 + kthread_stop(priv->main_thread.task);
  570 +
596 571 btmrvl_free_adapter(priv);
  572 + kfree(priv);
  573 +
  574 + return -ENOMEM;
  575 +}
  576 +EXPORT_SYMBOL_GPL(btmrvl_register_hdev);
  577 +
  578 +struct btmrvl_private *btmrvl_add_card(void *card)
  579 +{
  580 + struct btmrvl_private *priv;
  581 +
  582 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  583 + if (!priv) {
  584 + BT_ERR("Can not allocate priv");
  585 + goto err_priv;
  586 + }
  587 +
  588 + priv->adapter = kzalloc(sizeof(*priv->adapter), GFP_KERNEL);
  589 + if (!priv->adapter) {
  590 + BT_ERR("Allocate buffer for btmrvl_adapter failed!");
  591 + goto err_adapter;
  592 + }
  593 +
  594 + btmrvl_init_adapter(priv);
  595 +
  596 + BT_DBG("Starting kthread...");
  597 + priv->main_thread.priv = priv;
  598 + spin_lock_init(&priv->driver_lock);
  599 +
  600 + init_waitqueue_head(&priv->main_thread.wait_q);
  601 + priv->main_thread.task = kthread_run(btmrvl_service_main_thread,
  602 + &priv->main_thread, "btmrvl_main_service");
  603 +
  604 + priv->btmrvl_dev.card = card;
  605 + priv->btmrvl_dev.tx_dnld_rdy = true;
  606 +
  607 + return priv;
597 608  
598 609 err_adapter:
599 610 kfree(priv);
drivers/bluetooth/btmrvl_sdio.c
... ... @@ -931,7 +931,12 @@
931 931 priv->hw_host_to_card = btmrvl_sdio_host_to_card;
932 932 priv->hw_wakeup_firmware = btmrvl_sdio_wakeup_fw;
933 933  
934   - btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);
  934 + if (btmrvl_register_hdev(priv)) {
  935 + BT_ERR("Register hdev failed!");
  936 + ret = -ENODEV;
  937 + goto disable_host_int;
  938 + }
  939 +
935 940 priv->btmrvl_dev.psmode = 1;
936 941 btmrvl_enable_ps(priv);
937 942