Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up
@ 2011-02-01 15:47 Luiz Augusto von Dentz
  2011-02-01 15:47 ` [PATCH 2/2] Fix stopping inquiry before adapter object is initialized Luiz Augusto von Dentz
  2011-02-01 23:22 ` [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Johan Hedberg
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2011-02-01 15:47 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>

There is no need for HCIDEVUP/fork in such cases it will just consume
more resources for no reason.

To fix this HCI_DEV_REG is no longer generate for adapter already up
instead init_device is called directly which simplify the code path.
---
 plugins/hciops.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index ecfcec3..80ae61a 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2458,7 +2458,7 @@ static void init_pending(int index)
 	hci_set_bit(PENDING_NAME, &dev->pending);
 }
 
-static void init_device(int index)
+static void init_device(int index, gboolean already_up)
 {
 	struct hci_dev_req dr;
 	int dd;
@@ -2482,6 +2482,10 @@ static void init_device(int index)
 	init_pending(index);
 	start_hci_dev(index);
 
+	/* Avoid forking if nothing else has to be done */
+	if (already_up)
+		return;
+
 	/* Do initialization in the separate process */
 	pid = fork();
 	switch (pid) {
@@ -2562,7 +2566,7 @@ static void device_event(int event, int index)
 	switch (event) {
 	case HCI_DEV_REG:
 		info("HCI dev %d registered", index);
-		init_device(index);
+		init_device(index, FALSE);
 		break;
 
 	case HCI_DEV_UNREG:
@@ -2648,12 +2652,15 @@ static gboolean init_known_adapters(gpointer user_data)
 
 	for (i = 0; i < dl->dev_num; i++, dr++) {
 		struct dev_info *dev;
+		gboolean already_up;
+
+		already_up = hci_test_bit(HCI_UP, &dr->dev_opt);
 
-		device_event(HCI_DEV_REG, dr->dev_id);
+		init_device(dr->dev_id, already_up);
 
 		dev = &devs[dr->dev_id];
 
-		dev->already_up = hci_test_bit(HCI_UP, &dr->dev_opt);
+		dev->already_up = already_up;
 
 		if (!dev->already_up)
 			continue;
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-01 23:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-01 15:47 [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Luiz Augusto von Dentz
2011-02-01 15:47 ` [PATCH 2/2] Fix stopping inquiry before adapter object is initialized Luiz Augusto von Dentz
2011-02-01 23:22 ` [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox