diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2014-08-08 02:32:50 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-08-14 02:49:17 -0400 |
commit | 222916e3e509f04678d0b6f13f7b17bbc8dd14b6 (patch) | |
tree | 2d843bb692f5ec91dc6848b10e69ba926dda0e03 /net/bluetooth | |
parent | 893ededeb189aa48c308116a7acd793efae5c830 (diff) |
Bluetooth: Refactor SMP (de)initialization into separate functions
As preparation for converting SMP to use the l2cap_chan infrastructure
refactor the (de)initialization into separate functions.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/hci_core.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 4a1ec259099e..1f691c50abbc 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c | |||
@@ -1764,6 +1764,34 @@ static void hci_init4_req(struct hci_request *req, unsigned long opt) | |||
1764 | } | 1764 | } |
1765 | } | 1765 | } |
1766 | 1766 | ||
1767 | static int hci_register_smp(struct hci_dev *hdev) | ||
1768 | { | ||
1769 | int err; | ||
1770 | |||
1771 | BT_DBG("%s", hdev->name); | ||
1772 | |||
1773 | hdev->tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0, | ||
1774 | CRYPTO_ALG_ASYNC); | ||
1775 | if (IS_ERR(hdev->tfm_aes)) { | ||
1776 | BT_ERR("Unable to create crypto context"); | ||
1777 | err = PTR_ERR(hdev->tfm_aes); | ||
1778 | hdev->tfm_aes = NULL; | ||
1779 | return err; | ||
1780 | } | ||
1781 | |||
1782 | return 0; | ||
1783 | } | ||
1784 | |||
1785 | static void hci_unregister_smp(struct hci_dev *hdev) | ||
1786 | { | ||
1787 | BT_DBG("%s", hdev->name); | ||
1788 | |||
1789 | if (hdev->tfm_aes) { | ||
1790 | crypto_free_blkcipher(hdev->tfm_aes); | ||
1791 | hdev->tfm_aes = NULL; | ||
1792 | } | ||
1793 | } | ||
1794 | |||
1767 | static int __hci_init(struct hci_dev *hdev) | 1795 | static int __hci_init(struct hci_dev *hdev) |
1768 | { | 1796 | { |
1769 | int err; | 1797 | int err; |
@@ -4099,18 +4127,13 @@ int hci_register_dev(struct hci_dev *hdev) | |||
4099 | 4127 | ||
4100 | dev_set_name(&hdev->dev, "%s", hdev->name); | 4128 | dev_set_name(&hdev->dev, "%s", hdev->name); |
4101 | 4129 | ||
4102 | hdev->tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0, | 4130 | error = hci_register_smp(hdev); |
4103 | CRYPTO_ALG_ASYNC); | 4131 | if (error) |
4104 | if (IS_ERR(hdev->tfm_aes)) { | ||
4105 | BT_ERR("Unable to create crypto context"); | ||
4106 | error = PTR_ERR(hdev->tfm_aes); | ||
4107 | hdev->tfm_aes = NULL; | ||
4108 | goto err_wqueue; | 4132 | goto err_wqueue; |
4109 | } | ||
4110 | 4133 | ||
4111 | error = device_add(&hdev->dev); | 4134 | error = device_add(&hdev->dev); |
4112 | if (error < 0) | 4135 | if (error < 0) |
4113 | goto err_tfm; | 4136 | goto err_smp; |
4114 | 4137 | ||
4115 | hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, | 4138 | hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, |
4116 | RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops, | 4139 | RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops, |
@@ -4152,8 +4175,8 @@ int hci_register_dev(struct hci_dev *hdev) | |||
4152 | 4175 | ||
4153 | return id; | 4176 | return id; |
4154 | 4177 | ||
4155 | err_tfm: | 4178 | err_smp: |
4156 | crypto_free_blkcipher(hdev->tfm_aes); | 4179 | hci_unregister_smp(hdev); |
4157 | err_wqueue: | 4180 | err_wqueue: |
4158 | destroy_workqueue(hdev->workqueue); | 4181 | destroy_workqueue(hdev->workqueue); |
4159 | destroy_workqueue(hdev->req_workqueue); | 4182 | destroy_workqueue(hdev->req_workqueue); |
@@ -4205,8 +4228,7 @@ void hci_unregister_dev(struct hci_dev *hdev) | |||
4205 | rfkill_destroy(hdev->rfkill); | 4228 | rfkill_destroy(hdev->rfkill); |
4206 | } | 4229 | } |
4207 | 4230 | ||
4208 | if (hdev->tfm_aes) | 4231 | hci_unregister_smp(hdev); |
4209 | crypto_free_blkcipher(hdev->tfm_aes); | ||
4210 | 4232 | ||
4211 | device_del(&hdev->dev); | 4233 | device_del(&hdev->dev); |
4212 | 4234 | ||