All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/mgmt: Make mgmt_new_default return the same instance
@ 2018-02-26 15:42 Luiz Augusto von Dentz
  0 siblings, 0 replies; only message in thread
From: Luiz Augusto von Dentz @ 2018-02-26 15:42 UTC (permalink / raw)
  To: linux-bluetooth

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

If an instance already exists there is no reason to create a second one
as they both will bind to HCI_CHANNEL_CONTROL.
---
 src/shared/mgmt.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 277e361a6..0721f73f2 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -81,6 +81,8 @@ struct mgmt_notify {
 	void *user_data;
 };
 
+static struct mgmt *default_mgmt;
+
 static void destroy_request(void *data)
 {
 	struct mgmt_request *request = data;
@@ -432,6 +434,9 @@ struct mgmt *mgmt_new_default(void)
 	} addr;
 	int fd;
 
+	if (default_mgmt)
+		return mgmt_ref(default_mgmt);
+
 	fd = socket(PF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
 								BTPROTO_HCI);
 	if (fd < 0)
@@ -455,6 +460,8 @@ struct mgmt *mgmt_new_default(void)
 
 	mgmt->close_on_unref = true;
 
+	default_mgmt = mgmt;
+
 	return mgmt;
 }
 
-- 
2.14.3


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-02-26 15:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-26 15:42 [PATCH BlueZ] shared/mgmt: Make mgmt_new_default return the same instance Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.