summaryrefslogtreecommitdiff
path: root/net/bluetooth
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-08-08 06:32:50 (GMT)
committerMarcel Holtmann <marcel@holtmann.org>2014-08-14 06:49:17 (GMT)
commit222916e3e509f04678d0b6f13f7b17bbc8dd14b6 (patch)
tree2d843bb692f5ec91dc6848b10e69ba926dda0e03 /net/bluetooth
parent893ededeb189aa48c308116a7acd793efae5c830 (diff)
downloadlinux-222916e3e509f04678d0b6f13f7b17bbc8dd14b6.tar.xz
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.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 4a1ec25..1f691c5 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)
}
}
+static int hci_register_smp(struct hci_dev *hdev)
+{
+ int err;
+
+ BT_DBG("%s", hdev->name);
+
+ hdev->tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0,
+ CRYPTO_ALG_ASYNC);
+ if (IS_ERR(hdev->tfm_aes)) {
+ BT_ERR("Unable to create crypto context");
+ err = PTR_ERR(hdev->tfm_aes);
+ hdev->tfm_aes = NULL;
+ return err;
+ }
+
+ return 0;
+}
+
+static void hci_unregister_smp(struct hci_dev *hdev)
+{
+ BT_DBG("%s", hdev->name);
+
+ if (hdev->tfm_aes) {
+ crypto_free_blkcipher(hdev->tfm_aes);
+ hdev->tfm_aes = NULL;
+ }
+}
+
static int __hci_init(struct hci_dev *hdev)
{
int err;
@@ -4099,18 +4127,13 @@ int hci_register_dev(struct hci_dev *hdev)
dev_set_name(&hdev->dev, "%s", hdev->name);
- hdev->tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0,
- CRYPTO_ALG_ASYNC);
- if (IS_ERR(hdev->tfm_aes)) {
- BT_ERR("Unable to create crypto context");
- error = PTR_ERR(hdev->tfm_aes);
- hdev->tfm_aes = NULL;
+ error = hci_register_smp(hdev);
+ if (error)
goto err_wqueue;
- }
error = device_add(&hdev->dev);
if (error < 0)
- goto err_tfm;
+ goto err_smp;
hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops,
@@ -4152,8 +4175,8 @@ int hci_register_dev(struct hci_dev *hdev)
return id;
-err_tfm:
- crypto_free_blkcipher(hdev->tfm_aes);
+err_smp:
+ hci_unregister_smp(hdev);
err_wqueue:
destroy_workqueue(hdev->workqueue);
destroy_workqueue(hdev->req_workqueue);
@@ -4205,8 +4228,7 @@ void hci_unregister_dev(struct hci_dev *hdev)
rfkill_destroy(hdev->rfkill);
}
- if (hdev->tfm_aes)
- crypto_free_blkcipher(hdev->tfm_aes);
+ hci_unregister_smp(hdev);
device_del(&hdev->dev);