[PATCH_v2 1/7] android/health: Fix queue creation for mdeps and devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create queue for mdeps, devices and channels when creating app
and device struct. It is simpler to read code than on demand
creation.
---
 android/health.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/android/health.c b/android/health.c
index 0462e99..7553467 100644
--- a/android/health.c
+++ b/android/health.c
@@ -678,6 +678,14 @@ static struct health_app *create_health_app(const char *app_name,
 			goto fail;
 	}
 
+	app->mdeps = queue_new();
+	if (!app->mdeps)
+		goto fail;
+
+	app->devices = queue_new();
+	if (!app->devices)
+		goto fail;
+
 	return app;
 
 fail:
@@ -784,14 +792,6 @@ static void bt_health_mdep_cfg_data(const void *buf, uint16_t len)
 		memcpy(mdep->descr, cmd->descr, cmd->descr_len);
 	}
 
-	if (app->num_of_mdep > 0 && !app->mdeps) {
-		app->mdeps = queue_new();
-		if (!app->mdeps) {
-			status = HAL_STATUS_FAILED;
-			goto fail;
-		}
-	}
-
 	if (!queue_push_tail(app->mdeps, mdep)) {
 		status = HAL_STATUS_FAILED;
 		goto fail;
@@ -1102,6 +1102,11 @@ static struct health_device *create_device(uint16_t app_id, const uint8_t *addr)
 
 	android2bdaddr(addr, &dev->dst);
 	dev->app_id = app_id;
+	dev->channels = queue_new();
+	if (!dev->channels) {
+		free_health_device(dev);
+		return NULL;
+	}
 
 	return dev;
 }
@@ -1159,21 +1164,9 @@ static void bt_health_connect_channel(const void *buf, uint16_t len)
 
 	channel->dev = dev;
 
-	if (!app->devices) {
-		app->devices = queue_new();
-		if (!app->devices)
-			goto fail;
-	}
-
 	if (!queue_push_tail(app->devices, dev))
 		goto fail;
 
-	if (!dev->channels) {
-		dev->channels = queue_new();
-		if (!dev->channels)
-			goto fail;
-	}
-
 	if (!queue_push_tail(dev->channels, channel)) {
 		queue_remove(app->devices, dev);
 		goto fail;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux