From 5aa62eb4270ba27022bab708e12349151c036937 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 3 Nov 2014 17:20:55 +0100 Subject: [PATCH] emulator/bthost: Move smp_start to bthost_create This creates smp while creating bthost allowing for early bailout if kernel doesn't support crypto. Fix crash if smp_start failed due to SMP code always assuming valid pointer. --- emulator/bthost.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index a1232286e..104916bdc 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -223,6 +223,12 @@ struct bthost *bthost_create(void) if (!bthost) return NULL; + bthost->smp_data = smp_start(bthost); + if (!bthost->smp_data) { + free(bthost); + return NULL; + } + /* Set defaults */ bthost->io_capability = 0x03; @@ -436,6 +442,8 @@ void bthost_destroy(struct bthost *bthost) if (bthost->rfcomm_conn_data) free(bthost->rfcomm_conn_data); + smp_stop(bthost->smp_data); + free(bthost); } @@ -2268,8 +2276,6 @@ void bthost_start(struct bthost *bthost) if (!bthost) return; - bthost->smp_data = smp_start(bthost); - bthost->ncmd = 1; send_command(bthost, BT_HCI_CMD_RESET, NULL, 0); @@ -2383,8 +2389,4 @@ void bthost_send_rfcomm_data(struct bthost *bthost, uint16_t handle, void bthost_stop(struct bthost *bthost) { - if (bthost->smp_data) { - smp_stop(bthost->smp_data); - bthost->smp_data = NULL; - } } -- 2.47.3