From dcd05008e491252280c178d9d5300a885b4f4548 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Fri, 24 Jul 2015 15:32:20 +0530 Subject: [PATCH] greybus: svc: connection is created only once now We no longer create a fresh connection on receiving svc-hello message, but rather update the initial one. Update 'initial_svc_connection' after the connection is fully initialized. Look for the partially initialized connection while removing hd, as hd might be removed before getting svc-hello requests from svc. Also update gb_svc_connection_init() to initialize id_map on the first (and the only) call to connection-init function. We also can't update connection->bundle->intf->svc, as its a bundle-less connection. Lets stop updating intf->svc as its not really used. Signed-off-by: Viresh Kumar Tested-by: Perry Hung Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/core.c | 6 ++++++ drivers/staging/greybus/svc.c | 28 +++++----------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 3b1be2dd2359..bbfae4a01ce3 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -236,6 +236,12 @@ void greybus_remove_hd(struct greybus_host_device *hd) gb_interfaces_remove(hd); gb_endo_remove(hd->endo); + /* Is the SVC still using the partially uninitialized connection ? */ + if (hd->initial_svc_connection) { + gb_connection_exit(hd->initial_svc_connection); + gb_connection_destroy(hd->initial_svc_connection); + } + /* * Make sure there are no leftovers that can potentially corrupt sysfs. */ diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c index 28a4ca9f8aca..969c3899e954 100644 --- a/drivers/staging/greybus/svc.c +++ b/drivers/staging/greybus/svc.c @@ -54,6 +54,9 @@ gb_ap_interface_create(struct greybus_host_device *hd, intf->device_id = GB_DEVICE_ID_AP; svc_update_connection(intf, connection); + /* Its no longer a partially initialized connection */ + hd->initial_svc_connection = NULL; + return intf; } @@ -384,24 +387,11 @@ static int gb_svc_connection_init(struct gb_connection *connection) svc->connection = connection; connection->private = svc; - /* - * SVC connection is created twice: - * - before the interface-id of the AP and the endo type is known. - * - after receiving endo type and interface-id of the AP from the SVC. - * - * We should do light-weight initialization for the first case. - */ - if (!connection->bundle) { - WARN_ON(connection->hd->initial_svc_connection); - connection->hd->initial_svc_connection = connection; - return 0; - } + WARN_ON(connection->hd->initial_svc_connection); + connection->hd->initial_svc_connection = connection; ida_init(&greybus_svc_device_id_map); - /* Set interface's svc connection */ - connection->bundle->intf->svc = svc; - return 0; } @@ -409,14 +399,6 @@ static void gb_svc_connection_exit(struct gb_connection *connection) { struct gb_svc *svc = connection->private; - if (connection->hd->initial_svc_connection == connection) { - connection->hd->initial_svc_connection = NULL; - } else { - if (WARN_ON(connection->bundle->intf->svc != svc)) - return; - connection->bundle->intf->svc = NULL; - } - connection->private = NULL; kfree(svc); } -- 2.11.0