linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [PATCH BlueZ v0 6/6] input: Use btd_service userdata pointer
Date: Mon, 27 May 2013 14:04:09 +0200	[thread overview]
Message-ID: <1369656249-27980-7-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1369656249-27980-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Avoid maintaining an internal list of probed input_device instances by
making use of btd_service's userdata pointer.
---
 profiles/input/device.c | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 498c226..7c3130c 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -41,6 +41,7 @@
 
 #include "log.h"
 
+#include "lib/uuid.h"
 #include "../src/adapter.h"
 #include "../src/device.h"
 #include "../src/profile.h"
@@ -84,7 +85,6 @@ struct input_device {
 	uint32_t		reconnect_attempt;
 };
 
-static GSList *devices = NULL;
 static int idle_timeout = 0;
 
 void input_set_idle_timeout(int timeout)
@@ -94,18 +94,6 @@ void input_set_idle_timeout(int timeout)
 
 static void input_device_enter_reconnect_mode(struct input_device *idev);
 
-static struct input_device *find_device_by_path(GSList *list, const char *path)
-{
-	for (; list; list = list->next) {
-		struct input_device *idev = list->data;
-
-		if (!strcmp(idev->path, path))
-			return idev;
-	}
-
-	return NULL;
-}
-
 static void input_device_free(struct input_device *idev)
 {
 	if (idev->dc_id)
@@ -863,10 +851,6 @@ int input_device_register(struct btd_service *service)
 
 	DBG("%s", path);
 
-	idev = find_device_by_path(devices, path);
-	if (idev)
-		return -EEXIST;
-
 	idev = input_device_new(service);
 	if (!idev)
 		return -EINVAL;
@@ -883,24 +867,24 @@ int input_device_register(struct btd_service *service)
 
 	btd_service_set_user_data(service, idev);
 
-	devices = g_slist_append(devices, idev);
-
 	return 0;
 }
 
 static struct input_device *find_device(const bdaddr_t *src,
 					const bdaddr_t *dst)
 {
-	GSList *list;
+	struct btd_device *device;
+	struct btd_service *service;
 
-	for (list = devices; list != NULL; list = list->next) {
-		struct input_device *idev = list->data;
+	device = adapter_find_device(adapter_find(src), dst);
+	if (device == NULL)
+		return NULL;
 
-		if (!bacmp(&idev->src, src) && !bacmp(&idev->dst, dst))
-			return idev;
-	}
+	service = btd_device_get_service(device, HID_UUID);
+	if (service == NULL)
+		return NULL;
 
-	return NULL;
+	return btd_service_get_user_data(service);
 }
 
 void input_device_unregister(struct btd_service *service)
@@ -914,7 +898,6 @@ void input_device_unregister(struct btd_service *service)
 	g_dbus_unregister_interface(btd_get_dbus_connection(),
 						idev->path, INPUT_INTERFACE);
 
-	devices = g_slist_remove(devices, idev);
 	input_device_free(idev);
 }
 
-- 
1.8.1.4


  parent reply	other threads:[~2013-05-27 12:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27 12:04 [PATCH BlueZ v0 0/6] Exploit btd_service's userdata pointer Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 1/6] network: Remove duplicated search Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 2/6] network: Fix missing NULL check for given UUID Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 3/6] network: Remove find_connection() Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 4/6] deviceinfo: Use btd_service userdata pointer Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 5/6] scanparam: " Mikel Astiz
2013-05-27 12:04 ` Mikel Astiz [this message]
2013-06-24  8:19 ` [PATCH BlueZ v0 0/6] Exploit btd_service's " Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369656249-27980-7-git-send-email-mikel.astiz.oss@gmail.com \
    --to=mikel.astiz.oss@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mikel.astiz@bmw-carit.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).