Skip to contentSkip to conversation

shared/mgmt: Make mgmt_new_default return the same instance

PATCH Superseded Luiz Augusto von Dentz 1 participant 1 message Feb 26, 2018 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shared/mgmt: Make mgmt_new_default return the same instance

From: Luiz Augusto von Dentz <[email protected]>

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(+)
src/shared/mgmt.c +7 -0
index 277e361a6..0721f73f2 100644
@@ -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;
 }
 
Signature · 1 line
2.14.3