diff mbox series

[RFC,v4,01/11] Bluetooth: Add support hdev to allocate private data

Message ID 20210727235127.173149-2-hj.tedd.an@gmail.com (mailing list archive)
State Superseded
Headers show
Series Bluetooth: btintel: Refactoring setup routines | expand

Commit Message

Tedd Ho-Jeong An July 27, 2021, 11:51 p.m. UTC
From: Tedd Ho-Jeong An <tedd.an@intel.com>

This patch adds support hdev to allocate extra size for private data.
The size of private data is specified in the hdev_alloc_size(priv_size)
and the allocated buffer can be accessed with hci_get_priv(hdev).

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
---
 drivers/bluetooth/bfusb.c        |  2 +-
 drivers/bluetooth/bluecard_cs.c  |  2 +-
 drivers/bluetooth/bpa10x.c       |  2 +-
 drivers/bluetooth/bt3c_cs.c      |  2 +-
 drivers/bluetooth/btmrvl_main.c  |  2 +-
 drivers/bluetooth/btmtksdio.c    |  2 +-
 drivers/bluetooth/btmtkuart.c    |  2 +-
 drivers/bluetooth/btqcomsmd.c    |  2 +-
 drivers/bluetooth/btrsi.c        |  2 +-
 drivers/bluetooth/btsdio.c       |  2 +-
 drivers/bluetooth/btusb.c        |  2 +-
 drivers/bluetooth/dtl1_cs.c      |  2 +-
 drivers/bluetooth/hci_ldisc.c    |  2 +-
 drivers/bluetooth/hci_serdev.c   |  2 +-
 drivers/bluetooth/hci_vhci.c     |  2 +-
 drivers/bluetooth/virtio_bt.c    |  2 +-
 include/net/bluetooth/hci_core.h |  7 ++++++-
 net/bluetooth/hci_core.c         | 11 +++++++++--
 18 files changed, 31 insertions(+), 19 deletions(-)

Comments

Luiz Augusto von Dentz July 28, 2021, 12:41 a.m. UTC | #1
Hi Tedd,

On Tue, Jul 27, 2021 at 4:53 PM Tedd Ho-Jeong An <hj.tedd.an@gmail.com> wrote:
>
> From: Tedd Ho-Jeong An <tedd.an@intel.com>
>
> This patch adds support hdev to allocate extra size for private data.
> The size of private data is specified in the hdev_alloc_size(priv_size)
> and the allocated buffer can be accessed with hci_get_priv(hdev).
>
> Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
> ---
>  drivers/bluetooth/bfusb.c        |  2 +-
>  drivers/bluetooth/bluecard_cs.c  |  2 +-
>  drivers/bluetooth/bpa10x.c       |  2 +-
>  drivers/bluetooth/bt3c_cs.c      |  2 +-
>  drivers/bluetooth/btmrvl_main.c  |  2 +-
>  drivers/bluetooth/btmtksdio.c    |  2 +-
>  drivers/bluetooth/btmtkuart.c    |  2 +-
>  drivers/bluetooth/btqcomsmd.c    |  2 +-
>  drivers/bluetooth/btrsi.c        |  2 +-
>  drivers/bluetooth/btsdio.c       |  2 +-
>  drivers/bluetooth/btusb.c        |  2 +-
>  drivers/bluetooth/dtl1_cs.c      |  2 +-
>  drivers/bluetooth/hci_ldisc.c    |  2 +-
>  drivers/bluetooth/hci_serdev.c   |  2 +-
>  drivers/bluetooth/hci_vhci.c     |  2 +-
>  drivers/bluetooth/virtio_bt.c    |  2 +-
>  include/net/bluetooth/hci_core.h |  7 ++++++-
>  net/bluetooth/hci_core.c         | 11 +++++++++--
>  18 files changed, 31 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
> index 5a321b4076aa..430e230999fa 100644
> --- a/drivers/bluetooth/bfusb.c
> +++ b/drivers/bluetooth/bfusb.c
> @@ -651,7 +651,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
>         release_firmware(firmware);
>
>         /* Initialize and register HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Can't allocate HCI device");
>                 goto done;
> diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
> index 36eabf61717f..d62b878aff7e 100644
> --- a/drivers/bluetooth/bluecard_cs.c
> +++ b/drivers/bluetooth/bluecard_cs.c
> @@ -694,7 +694,7 @@ static int bluecard_open(struct bluecard_info *info)
>         info->rx_skb = NULL;
>
>         /* Initialize HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Can't allocate HCI device");
>                 return -ENOMEM;
> diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
> index 1fa58c059cbf..bd670352a336 100644
> --- a/drivers/bluetooth/bpa10x.c
> +++ b/drivers/bluetooth/bpa10x.c
> @@ -380,7 +380,7 @@ static int bpa10x_probe(struct usb_interface *intf,
>         init_usb_anchor(&data->tx_anchor);
>         init_usb_anchor(&data->rx_anchor);
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev)
>                 return -ENOMEM;
>
> diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
> index 54713833951a..cd135a736688 100644
> --- a/drivers/bluetooth/bt3c_cs.c
> +++ b/drivers/bluetooth/bt3c_cs.c
> @@ -550,7 +550,7 @@ static int bt3c_open(struct bt3c_info *info)
>         info->rx_skb = NULL;
>
>         /* Initialize HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Can't allocate HCI device");
>                 return -ENOMEM;
> diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
> index 8b9d78ce6bb2..0157fa4ce528 100644
> --- a/drivers/bluetooth/btmrvl_main.c
> +++ b/drivers/bluetooth/btmrvl_main.c
> @@ -680,7 +680,7 @@ int btmrvl_register_hdev(struct btmrvl_private *priv)
>         struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
>         int ret;
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Can not allocate HCI device");
>                 goto err_hdev;
> diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
> index 9872ef18f9fe..b48aec25c09d 100644
> --- a/drivers/bluetooth/btmtksdio.c
> +++ b/drivers/bluetooth/btmtksdio.c
> @@ -959,7 +959,7 @@ static int btmtksdio_probe(struct sdio_func *func,
>         skb_queue_head_init(&bdev->txq);
>
>         /* Initialize and register HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 dev_err(&func->dev, "Can't allocate HCI device\n");
>                 return -ENOMEM;
> diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
> index e9d91d7c0db4..96ee364507c5 100644
> --- a/drivers/bluetooth/btmtkuart.c
> +++ b/drivers/bluetooth/btmtkuart.c
> @@ -987,7 +987,7 @@ static int btmtkuart_probe(struct serdev_device *serdev)
>         skb_queue_head_init(&bdev->txq);
>
>         /* Initialize and register HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 dev_err(&serdev->dev, "Can't allocate HCI device\n");
>                 return -ENOMEM;
> diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c
> index 2acb719e596f..47aaffceb8c1 100644
> --- a/drivers/bluetooth/btqcomsmd.c
> +++ b/drivers/bluetooth/btqcomsmd.c
> @@ -147,7 +147,7 @@ static int btqcomsmd_probe(struct platform_device *pdev)
>                 goto destroy_acl_channel;
>         }
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 ret = -ENOMEM;
>                 goto destroy_cmd_channel;
> diff --git a/drivers/bluetooth/btrsi.c b/drivers/bluetooth/btrsi.c
> index 8646b6dd11e9..2f8d186e4807 100644
> --- a/drivers/bluetooth/btrsi.c
> +++ b/drivers/bluetooth/btrsi.c
> @@ -121,7 +121,7 @@ static int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops)
>         ops->set_bt_context(priv, h_adapter);
>         h_adapter->proto_ops = ops;
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Failed to alloc HCI device");
>                 goto err;
> diff --git a/drivers/bluetooth/btsdio.c b/drivers/bluetooth/btsdio.c
> index 199e8f7d426d..69d2a26ed5db 100644
> --- a/drivers/bluetooth/btsdio.c
> +++ b/drivers/bluetooth/btsdio.c
> @@ -310,7 +310,7 @@ static int btsdio_probe(struct sdio_func *func,
>
>         skb_queue_head_init(&data->txq);
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev)
>                 return -ENOMEM;
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 1876a960b3dc..baf0934657d8 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -4575,7 +4575,7 @@ static int btusb_probe(struct usb_interface *intf,
>                 data->recv_bulk = btusb_recv_bulk;
>         }
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev)
>                 return -ENOMEM;
>
> diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
> index 2adfe4fade76..f06c8151f0ea 100644
> --- a/drivers/bluetooth/dtl1_cs.c
> +++ b/drivers/bluetooth/dtl1_cs.c
> @@ -449,7 +449,7 @@ static int dtl1_open(struct dtl1_info *info)
>         set_bit(XMIT_WAITING, &(info->tx_state));
>
>         /* Initialize HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Can't allocate HCI device");
>                 return -ENOMEM;
> diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
> index 5ed2cfa7da1d..89eb9d7685ae 100644
> --- a/drivers/bluetooth/hci_ldisc.c
> +++ b/drivers/bluetooth/hci_ldisc.c
> @@ -627,7 +627,7 @@ static int hci_uart_register_dev(struct hci_uart *hu)
>         BT_DBG("");
>
>         /* Initialize and register HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Can't allocate HCI device");
>                 return -ENOMEM;
> diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
> index 3b00d82d36cf..327fa2ecc5e7 100644
> --- a/drivers/bluetooth/hci_serdev.c
> +++ b/drivers/bluetooth/hci_serdev.c
> @@ -313,7 +313,7 @@ int hci_uart_register_device(struct hci_uart *hu,
>         set_bit(HCI_UART_PROTO_READY, &hu->flags);
>
>         /* Initialize and register HCI device */
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 BT_ERR("Can't allocate HCI device");
>                 err = -ENOMEM;
> diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
> index 8ab26dec5f6e..5486aa3945da 100644
> --- a/drivers/bluetooth/hci_vhci.c
> +++ b/drivers/bluetooth/hci_vhci.c
> @@ -96,7 +96,7 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
>         if (!skb)
>                 return -ENOMEM;
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 kfree_skb(skb);
>                 return -ENOMEM;
> diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
> index 57908ce4fae8..28576ec4860e 100644
> --- a/drivers/bluetooth/virtio_bt.c
> +++ b/drivers/bluetooth/virtio_bt.c
> @@ -283,7 +283,7 @@ static int virtbt_probe(struct virtio_device *vdev)
>         if (err)
>                 return err;
>
> -       hdev = hci_alloc_dev();
> +       hdev = hci_alloc_dev(0);
>         if (!hdev) {
>                 err = -ENOMEM;
>                 goto failed;
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index a53e94459ecd..5c689c5dc089 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -1223,10 +1223,15 @@ static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
>         dev_set_drvdata(&hdev->dev, data);
>  }
>
> +static inline void *hci_get_priv(struct hci_dev *hdev)
> +{
> +       return (char *)hdev + sizeof(*hdev);
> +}
> +
>  struct hci_dev *hci_dev_get(int index);
>  struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
>
> -struct hci_dev *hci_alloc_dev(void);
> +struct hci_dev *hci_alloc_dev(int sizeof_priv);

Just a minor suggestion here, we could perhaps have an alternative
version of hci_alloc_dev e.g hci_alloc_dev_priv so we don't need to
touch all the drivers like you did above.

>  void hci_free_dev(struct hci_dev *hdev);
>  int hci_register_dev(struct hci_dev *hdev);
>  void hci_unregister_dev(struct hci_dev *hdev);
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 2560ed2f144d..66b72c7efa3d 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -3751,11 +3751,18 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action,
>  }
>
>  /* Alloc HCI device */
> -struct hci_dev *hci_alloc_dev(void)
> +struct hci_dev *hci_alloc_dev(int sizeof_priv)
>  {
>         struct hci_dev *hdev;
> +       unsigned int alloc_size;
>
> -       hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
> +       alloc_size = sizeof(*hdev);
> +       if (sizeof_priv) {
> +               /* Fixme: May need ALIGN-ment? */
> +               alloc_size += sizeof_priv;
> +       }
> +
> +       hdev = kzalloc(alloc_size, GFP_KERNEL);
>         if (!hdev)
>                 return NULL;
>
> --
> 2.26.3
>
bluez.test.bot@gmail.com July 28, 2021, 2:11 a.m. UTC | #2
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=522353

---Test result---

Test Summary:
CheckPatch                    FAIL      12.15 seconds
GitLint                       FAIL      0.64 seconds
BuildKernel                   PASS      684.63 seconds
TestRunner: Setup             PASS      447.49 seconds
TestRunner: l2cap-tester      PASS      3.19 seconds
TestRunner: bnep-tester       PASS      2.25 seconds
TestRunner: mgmt-tester       PASS      35.20 seconds
TestRunner: rfcomm-tester     PASS      2.51 seconds
TestRunner: sco-tester        PASS      2.45 seconds
TestRunner: smp-tester        FAIL      2.55 seconds
TestRunner: userchan-tester   PASS      2.27 seconds

Details
##############################
Test: CheckPatch - FAIL - 12.15 seconds
Run checkpatch.pl script with rule in .checkpatch.conf
Bluetooth: btintel: Fix the legacy bootloader returns tlv based version
ERROR: space required before the open parenthesis '('
#37: FILE: drivers/bluetooth/btintel.c:2267:
+	switch(INTEL_HW_VARIANT(ver_tlv.cnvi_bt)) {

total: 1 errors, 0 warnings, 34 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] Bluetooth: btintel: Fix the legacy bootloader returns tlv" has style problems, please review.

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - FAIL - 0.64 seconds
Run gitlint with rule in .gitlint
Bluetooth: btintel: Fix the first HCI command not work with ROM device.
1: T3 Title has trailing punctuation (.): "Bluetooth: btintel: Fix the first HCI command not work with ROM device."


##############################
Test: BuildKernel - PASS - 684.63 seconds
Build Kernel with minimal configuration supports Bluetooth


##############################
Test: TestRunner: Setup - PASS - 447.49 seconds
Setup environment for running Test Runner


##############################
Test: TestRunner: l2cap-tester - PASS - 3.19 seconds
Run test-runner with l2cap-tester
Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: bnep-tester - PASS - 2.25 seconds
Run test-runner with bnep-tester
Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: mgmt-tester - PASS - 35.20 seconds
Run test-runner with mgmt-tester
Total: 448, Passed: 445 (99.3%), Failed: 0, Not Run: 3

##############################
Test: TestRunner: rfcomm-tester - PASS - 2.51 seconds
Run test-runner with rfcomm-tester
Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: sco-tester - PASS - 2.45 seconds
Run test-runner with sco-tester
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: smp-tester - FAIL - 2.55 seconds
Run test-runner with smp-tester
Total: 8, Passed: 7 (87.5%), Failed: 1, Not Run: 0

Failed Test Cases
SMP Client - SC Request 2                            Failed       0.032 seconds

##############################
Test: TestRunner: userchan-tester - PASS - 2.27 seconds
Run test-runner with userchan-tester
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0



---
Regards,
Linux Bluetooth
Marcel Holtmann July 29, 2021, 11:39 a.m. UTC | #3
Hi Luiz,

>> This patch adds support hdev to allocate extra size for private data.
>> The size of private data is specified in the hdev_alloc_size(priv_size)
>> and the allocated buffer can be accessed with hci_get_priv(hdev).
>> 
>> Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
>> ---
>> drivers/bluetooth/bfusb.c        |  2 +-
>> drivers/bluetooth/bluecard_cs.c  |  2 +-
>> drivers/bluetooth/bpa10x.c       |  2 +-
>> drivers/bluetooth/bt3c_cs.c      |  2 +-
>> drivers/bluetooth/btmrvl_main.c  |  2 +-
>> drivers/bluetooth/btmtksdio.c    |  2 +-
>> drivers/bluetooth/btmtkuart.c    |  2 +-
>> drivers/bluetooth/btqcomsmd.c    |  2 +-
>> drivers/bluetooth/btrsi.c        |  2 +-
>> drivers/bluetooth/btsdio.c       |  2 +-
>> drivers/bluetooth/btusb.c        |  2 +-
>> drivers/bluetooth/dtl1_cs.c      |  2 +-
>> drivers/bluetooth/hci_ldisc.c    |  2 +-
>> drivers/bluetooth/hci_serdev.c   |  2 +-
>> drivers/bluetooth/hci_vhci.c     |  2 +-
>> drivers/bluetooth/virtio_bt.c    |  2 +-
>> include/net/bluetooth/hci_core.h |  7 ++++++-
>> net/bluetooth/hci_core.c         | 11 +++++++++--
>> 18 files changed, 31 insertions(+), 19 deletions(-)
>> 
>> diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
>> index 5a321b4076aa..430e230999fa 100644
>> --- a/drivers/bluetooth/bfusb.c
>> +++ b/drivers/bluetooth/bfusb.c
>> @@ -651,7 +651,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
>>        release_firmware(firmware);
>> 
>>        /* Initialize and register HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Can't allocate HCI device");
>>                goto done;
>> diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
>> index 36eabf61717f..d62b878aff7e 100644
>> --- a/drivers/bluetooth/bluecard_cs.c
>> +++ b/drivers/bluetooth/bluecard_cs.c
>> @@ -694,7 +694,7 @@ static int bluecard_open(struct bluecard_info *info)
>>        info->rx_skb = NULL;
>> 
>>        /* Initialize HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Can't allocate HCI device");
>>                return -ENOMEM;
>> diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
>> index 1fa58c059cbf..bd670352a336 100644
>> --- a/drivers/bluetooth/bpa10x.c
>> +++ b/drivers/bluetooth/bpa10x.c
>> @@ -380,7 +380,7 @@ static int bpa10x_probe(struct usb_interface *intf,
>>        init_usb_anchor(&data->tx_anchor);
>>        init_usb_anchor(&data->rx_anchor);
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev)
>>                return -ENOMEM;
>> 
>> diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
>> index 54713833951a..cd135a736688 100644
>> --- a/drivers/bluetooth/bt3c_cs.c
>> +++ b/drivers/bluetooth/bt3c_cs.c
>> @@ -550,7 +550,7 @@ static int bt3c_open(struct bt3c_info *info)
>>        info->rx_skb = NULL;
>> 
>>        /* Initialize HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Can't allocate HCI device");
>>                return -ENOMEM;
>> diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
>> index 8b9d78ce6bb2..0157fa4ce528 100644
>> --- a/drivers/bluetooth/btmrvl_main.c
>> +++ b/drivers/bluetooth/btmrvl_main.c
>> @@ -680,7 +680,7 @@ int btmrvl_register_hdev(struct btmrvl_private *priv)
>>        struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
>>        int ret;
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Can not allocate HCI device");
>>                goto err_hdev;
>> diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
>> index 9872ef18f9fe..b48aec25c09d 100644
>> --- a/drivers/bluetooth/btmtksdio.c
>> +++ b/drivers/bluetooth/btmtksdio.c
>> @@ -959,7 +959,7 @@ static int btmtksdio_probe(struct sdio_func *func,
>>        skb_queue_head_init(&bdev->txq);
>> 
>>        /* Initialize and register HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                dev_err(&func->dev, "Can't allocate HCI device\n");
>>                return -ENOMEM;
>> diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
>> index e9d91d7c0db4..96ee364507c5 100644
>> --- a/drivers/bluetooth/btmtkuart.c
>> +++ b/drivers/bluetooth/btmtkuart.c
>> @@ -987,7 +987,7 @@ static int btmtkuart_probe(struct serdev_device *serdev)
>>        skb_queue_head_init(&bdev->txq);
>> 
>>        /* Initialize and register HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                dev_err(&serdev->dev, "Can't allocate HCI device\n");
>>                return -ENOMEM;
>> diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c
>> index 2acb719e596f..47aaffceb8c1 100644
>> --- a/drivers/bluetooth/btqcomsmd.c
>> +++ b/drivers/bluetooth/btqcomsmd.c
>> @@ -147,7 +147,7 @@ static int btqcomsmd_probe(struct platform_device *pdev)
>>                goto destroy_acl_channel;
>>        }
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                ret = -ENOMEM;
>>                goto destroy_cmd_channel;
>> diff --git a/drivers/bluetooth/btrsi.c b/drivers/bluetooth/btrsi.c
>> index 8646b6dd11e9..2f8d186e4807 100644
>> --- a/drivers/bluetooth/btrsi.c
>> +++ b/drivers/bluetooth/btrsi.c
>> @@ -121,7 +121,7 @@ static int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops)
>>        ops->set_bt_context(priv, h_adapter);
>>        h_adapter->proto_ops = ops;
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Failed to alloc HCI device");
>>                goto err;
>> diff --git a/drivers/bluetooth/btsdio.c b/drivers/bluetooth/btsdio.c
>> index 199e8f7d426d..69d2a26ed5db 100644
>> --- a/drivers/bluetooth/btsdio.c
>> +++ b/drivers/bluetooth/btsdio.c
>> @@ -310,7 +310,7 @@ static int btsdio_probe(struct sdio_func *func,
>> 
>>        skb_queue_head_init(&data->txq);
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev)
>>                return -ENOMEM;
>> 
>> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
>> index 1876a960b3dc..baf0934657d8 100644
>> --- a/drivers/bluetooth/btusb.c
>> +++ b/drivers/bluetooth/btusb.c
>> @@ -4575,7 +4575,7 @@ static int btusb_probe(struct usb_interface *intf,
>>                data->recv_bulk = btusb_recv_bulk;
>>        }
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev)
>>                return -ENOMEM;
>> 
>> diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
>> index 2adfe4fade76..f06c8151f0ea 100644
>> --- a/drivers/bluetooth/dtl1_cs.c
>> +++ b/drivers/bluetooth/dtl1_cs.c
>> @@ -449,7 +449,7 @@ static int dtl1_open(struct dtl1_info *info)
>>        set_bit(XMIT_WAITING, &(info->tx_state));
>> 
>>        /* Initialize HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Can't allocate HCI device");
>>                return -ENOMEM;
>> diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
>> index 5ed2cfa7da1d..89eb9d7685ae 100644
>> --- a/drivers/bluetooth/hci_ldisc.c
>> +++ b/drivers/bluetooth/hci_ldisc.c
>> @@ -627,7 +627,7 @@ static int hci_uart_register_dev(struct hci_uart *hu)
>>        BT_DBG("");
>> 
>>        /* Initialize and register HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Can't allocate HCI device");
>>                return -ENOMEM;
>> diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
>> index 3b00d82d36cf..327fa2ecc5e7 100644
>> --- a/drivers/bluetooth/hci_serdev.c
>> +++ b/drivers/bluetooth/hci_serdev.c
>> @@ -313,7 +313,7 @@ int hci_uart_register_device(struct hci_uart *hu,
>>        set_bit(HCI_UART_PROTO_READY, &hu->flags);
>> 
>>        /* Initialize and register HCI device */
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                BT_ERR("Can't allocate HCI device");
>>                err = -ENOMEM;
>> diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
>> index 8ab26dec5f6e..5486aa3945da 100644
>> --- a/drivers/bluetooth/hci_vhci.c
>> +++ b/drivers/bluetooth/hci_vhci.c
>> @@ -96,7 +96,7 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
>>        if (!skb)
>>                return -ENOMEM;
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                kfree_skb(skb);
>>                return -ENOMEM;
>> diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
>> index 57908ce4fae8..28576ec4860e 100644
>> --- a/drivers/bluetooth/virtio_bt.c
>> +++ b/drivers/bluetooth/virtio_bt.c
>> @@ -283,7 +283,7 @@ static int virtbt_probe(struct virtio_device *vdev)
>>        if (err)
>>                return err;
>> 
>> -       hdev = hci_alloc_dev();
>> +       hdev = hci_alloc_dev(0);
>>        if (!hdev) {
>>                err = -ENOMEM;
>>                goto failed;
>> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
>> index a53e94459ecd..5c689c5dc089 100644
>> --- a/include/net/bluetooth/hci_core.h
>> +++ b/include/net/bluetooth/hci_core.h
>> @@ -1223,10 +1223,15 @@ static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
>>        dev_set_drvdata(&hdev->dev, data);
>> }
>> 
>> +static inline void *hci_get_priv(struct hci_dev *hdev)
>> +{
>> +       return (char *)hdev + sizeof(*hdev);
>> +}
>> +
>> struct hci_dev *hci_dev_get(int index);
>> struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
>> 
>> -struct hci_dev *hci_alloc_dev(void);
>> +struct hci_dev *hci_alloc_dev(int sizeof_priv);
> 
> Just a minor suggestion here, we could perhaps have an alternative
> version of hci_alloc_dev e.g hci_alloc_dev_priv so we don't need to
> touch all the drivers like you did above.

I agree. Lets do hci_alloc_dev_priv first and we can decide to touch all drivers later on.

Regards

Marcel
diff mbox series

Patch

diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 5a321b4076aa..430e230999fa 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -651,7 +651,7 @@  static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
 	release_firmware(firmware);
 
 	/* Initialize and register HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Can't allocate HCI device");
 		goto done;
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 36eabf61717f..d62b878aff7e 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -694,7 +694,7 @@  static int bluecard_open(struct bluecard_info *info)
 	info->rx_skb = NULL;
 
 	/* Initialize HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Can't allocate HCI device");
 		return -ENOMEM;
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
index 1fa58c059cbf..bd670352a336 100644
--- a/drivers/bluetooth/bpa10x.c
+++ b/drivers/bluetooth/bpa10x.c
@@ -380,7 +380,7 @@  static int bpa10x_probe(struct usb_interface *intf,
 	init_usb_anchor(&data->tx_anchor);
 	init_usb_anchor(&data->rx_anchor);
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev)
 		return -ENOMEM;
 
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 54713833951a..cd135a736688 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -550,7 +550,7 @@  static int bt3c_open(struct bt3c_info *info)
 	info->rx_skb = NULL;
 
 	/* Initialize HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Can't allocate HCI device");
 		return -ENOMEM;
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 8b9d78ce6bb2..0157fa4ce528 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -680,7 +680,7 @@  int btmrvl_register_hdev(struct btmrvl_private *priv)
 	struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
 	int ret;
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Can not allocate HCI device");
 		goto err_hdev;
diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
index 9872ef18f9fe..b48aec25c09d 100644
--- a/drivers/bluetooth/btmtksdio.c
+++ b/drivers/bluetooth/btmtksdio.c
@@ -959,7 +959,7 @@  static int btmtksdio_probe(struct sdio_func *func,
 	skb_queue_head_init(&bdev->txq);
 
 	/* Initialize and register HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		dev_err(&func->dev, "Can't allocate HCI device\n");
 		return -ENOMEM;
diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
index e9d91d7c0db4..96ee364507c5 100644
--- a/drivers/bluetooth/btmtkuart.c
+++ b/drivers/bluetooth/btmtkuart.c
@@ -987,7 +987,7 @@  static int btmtkuart_probe(struct serdev_device *serdev)
 	skb_queue_head_init(&bdev->txq);
 
 	/* Initialize and register HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		dev_err(&serdev->dev, "Can't allocate HCI device\n");
 		return -ENOMEM;
diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c
index 2acb719e596f..47aaffceb8c1 100644
--- a/drivers/bluetooth/btqcomsmd.c
+++ b/drivers/bluetooth/btqcomsmd.c
@@ -147,7 +147,7 @@  static int btqcomsmd_probe(struct platform_device *pdev)
 		goto destroy_acl_channel;
 	}
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		ret = -ENOMEM;
 		goto destroy_cmd_channel;
diff --git a/drivers/bluetooth/btrsi.c b/drivers/bluetooth/btrsi.c
index 8646b6dd11e9..2f8d186e4807 100644
--- a/drivers/bluetooth/btrsi.c
+++ b/drivers/bluetooth/btrsi.c
@@ -121,7 +121,7 @@  static int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops)
 	ops->set_bt_context(priv, h_adapter);
 	h_adapter->proto_ops = ops;
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Failed to alloc HCI device");
 		goto err;
diff --git a/drivers/bluetooth/btsdio.c b/drivers/bluetooth/btsdio.c
index 199e8f7d426d..69d2a26ed5db 100644
--- a/drivers/bluetooth/btsdio.c
+++ b/drivers/bluetooth/btsdio.c
@@ -310,7 +310,7 @@  static int btsdio_probe(struct sdio_func *func,
 
 	skb_queue_head_init(&data->txq);
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev)
 		return -ENOMEM;
 
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 1876a960b3dc..baf0934657d8 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4575,7 +4575,7 @@  static int btusb_probe(struct usb_interface *intf,
 		data->recv_bulk = btusb_recv_bulk;
 	}
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev)
 		return -ENOMEM;
 
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 2adfe4fade76..f06c8151f0ea 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -449,7 +449,7 @@  static int dtl1_open(struct dtl1_info *info)
 	set_bit(XMIT_WAITING, &(info->tx_state));
 
 	/* Initialize HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Can't allocate HCI device");
 		return -ENOMEM;
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 5ed2cfa7da1d..89eb9d7685ae 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -627,7 +627,7 @@  static int hci_uart_register_dev(struct hci_uart *hu)
 	BT_DBG("");
 
 	/* Initialize and register HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Can't allocate HCI device");
 		return -ENOMEM;
diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index 3b00d82d36cf..327fa2ecc5e7 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -313,7 +313,7 @@  int hci_uart_register_device(struct hci_uart *hu,
 	set_bit(HCI_UART_PROTO_READY, &hu->flags);
 
 	/* Initialize and register HCI device */
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		BT_ERR("Can't allocate HCI device");
 		err = -ENOMEM;
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 8ab26dec5f6e..5486aa3945da 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -96,7 +96,7 @@  static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 	if (!skb)
 		return -ENOMEM;
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		kfree_skb(skb);
 		return -ENOMEM;
diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index 57908ce4fae8..28576ec4860e 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -283,7 +283,7 @@  static int virtbt_probe(struct virtio_device *vdev)
 	if (err)
 		return err;
 
-	hdev = hci_alloc_dev();
+	hdev = hci_alloc_dev(0);
 	if (!hdev) {
 		err = -ENOMEM;
 		goto failed;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index a53e94459ecd..5c689c5dc089 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1223,10 +1223,15 @@  static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
 	dev_set_drvdata(&hdev->dev, data);
 }
 
+static inline void *hci_get_priv(struct hci_dev *hdev)
+{
+	return (char *)hdev + sizeof(*hdev);
+}
+
 struct hci_dev *hci_dev_get(int index);
 struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
 
-struct hci_dev *hci_alloc_dev(void);
+struct hci_dev *hci_alloc_dev(int sizeof_priv);
 void hci_free_dev(struct hci_dev *hdev);
 int hci_register_dev(struct hci_dev *hdev);
 void hci_unregister_dev(struct hci_dev *hdev);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 2560ed2f144d..66b72c7efa3d 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3751,11 +3751,18 @@  static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action,
 }
 
 /* Alloc HCI device */
-struct hci_dev *hci_alloc_dev(void)
+struct hci_dev *hci_alloc_dev(int sizeof_priv)
 {
 	struct hci_dev *hdev;
+	unsigned int alloc_size;
 
-	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
+	alloc_size = sizeof(*hdev);
+	if (sizeof_priv) {
+		/* Fixme: May need ALIGN-ment? */
+		alloc_size += sizeof_priv;
+	}
+
+	hdev = kzalloc(alloc_size, GFP_KERNEL);
 	if (!hdev)
 		return NULL;