* [PATCH 1/3] emulator/bthost: Simplify bthost_create
@ 2014-11-03 16:20 Szymon Janc
2014-11-03 16:20 ` [PATCH 2/3] emulator/bthost: Move smp_start to bthost_create Szymon Janc
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Szymon Janc @ 2014-11-03 16:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Use new0 instead of malloc+memset for allocating bthost.
---
emulator/bthost.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/emulator/bthost.c b/emulator/bthost.c
index a2c72a9..a123228 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -219,12 +219,10 @@ struct bthost *bthost_create(void)
{
struct bthost *bthost;
- bthost = malloc(sizeof(*bthost));
+ bthost = new0(struct bthost, 1);
if (!bthost)
return NULL;
- memset(bthost, 0, sizeof(*bthost));
-
/* Set defaults */
bthost->io_capability = 0x03;
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] emulator/bthost: Move smp_start to bthost_create
2014-11-03 16:20 [PATCH 1/3] emulator/bthost: Simplify bthost_create Szymon Janc
@ 2014-11-03 16:20 ` Szymon Janc
2014-11-03 16:20 ` [PATCH 3/3] emulator/bthost: Remove empty bthost_stop function Szymon Janc
2014-11-04 9:02 ` [PATCH 1/3] emulator/bthost: Simplify bthost_create Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-11-03 16:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
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 a123228..104916b 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;
- }
}
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] emulator/bthost: Remove empty bthost_stop function
2014-11-03 16:20 [PATCH 1/3] emulator/bthost: Simplify bthost_create Szymon Janc
2014-11-03 16:20 ` [PATCH 2/3] emulator/bthost: Move smp_start to bthost_create Szymon Janc
@ 2014-11-03 16:20 ` Szymon Janc
2014-11-04 9:02 ` [PATCH 1/3] emulator/bthost: Simplify bthost_create Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-11-03 16:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
emulator/bthost.c | 4 ----
emulator/bthost.h | 1 -
emulator/hciemu.c | 2 --
3 files changed, 7 deletions(-)
diff --git a/emulator/bthost.c b/emulator/bthost.c
index 104916b..2022e6b 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -2386,7 +2386,3 @@ void bthost_send_rfcomm_data(struct bthost *bthost, uint16_t handle,
free(uih_frame);
}
-
-void bthost_stop(struct bthost *bthost)
-{
-}
diff --git a/emulator/bthost.h b/emulator/bthost.h
index 62d415c..c0fa410 100644
--- a/emulator/bthost.h
+++ b/emulator/bthost.h
@@ -123,7 +123,6 @@ void bthost_send_rfcomm_data(struct bthost *bthost, uint16_t handle,
uint16_t len);
void bthost_start(struct bthost *bthost);
-void bthost_stop(struct bthost *bthost);
/* LE SMP support */
diff --git a/emulator/hciemu.c b/emulator/hciemu.c
index fcaeb70..c5bfa77 100644
--- a/emulator/hciemu.c
+++ b/emulator/hciemu.c
@@ -376,8 +376,6 @@ void hciemu_unref(struct hciemu *hciemu)
queue_destroy(hciemu->post_command_hooks, destroy_command_hook);
- bthost_stop(hciemu->host_stack);
-
g_source_remove(hciemu->host_source);
g_source_remove(hciemu->client_source);
g_source_remove(hciemu->master_source);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] emulator/bthost: Simplify bthost_create
2014-11-03 16:20 [PATCH 1/3] emulator/bthost: Simplify bthost_create Szymon Janc
2014-11-03 16:20 ` [PATCH 2/3] emulator/bthost: Move smp_start to bthost_create Szymon Janc
2014-11-03 16:20 ` [PATCH 3/3] emulator/bthost: Remove empty bthost_stop function Szymon Janc
@ 2014-11-04 9:02 ` Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2014-11-04 9:02 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Mon, Nov 03, 2014, Szymon Janc wrote:
> Use new0 instead of malloc+memset for allocating bthost.
> ---
> emulator/bthost.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-11-04 9:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-03 16:20 [PATCH 1/3] emulator/bthost: Simplify bthost_create Szymon Janc
2014-11-03 16:20 ` [PATCH 2/3] emulator/bthost: Move smp_start to bthost_create Szymon Janc
2014-11-03 16:20 ` [PATCH 3/3] emulator/bthost: Remove empty bthost_stop function Szymon Janc
2014-11-04 9:02 ` [PATCH 1/3] emulator/bthost: Simplify bthost_create Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).