From 0bf1f2441979e290945f4e5af40d76582c61da1e Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Mon, 7 Dec 2015 15:05:34 +0100 Subject: greybus: connection: separate connection creation and enabling Separate connection creation from enabling. This will ultimately allow connection structures to be created while parsing manifests, but the connections to not be enabled until a driver is bound. Signed-off-by: Johan Hovold Reviewed-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/connection.c | 12 +----------- drivers/staging/greybus/connection.h | 2 ++ drivers/staging/greybus/hd.c | 7 +++++++ drivers/staging/greybus/interface.c | 6 ++++++ drivers/staging/greybus/manifest.c | 14 ++++++++++++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 980244a873b8..c93650268b99 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -14,7 +14,6 @@ static int gb_connection_bind_protocol(struct gb_connection *connection); static void gb_connection_unbind_protocol(struct gb_connection *connection); -static int gb_connection_init(struct gb_connection *connection); static DEFINE_SPINLOCK(gb_connections_lock); @@ -125,7 +124,6 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id, struct gb_connection *connection; struct ida *id_map = &hd->cport_id_map; int ida_start, ida_end; - int retval; u8 major = 0; u8 minor = 1; @@ -194,14 +192,6 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id, spin_unlock_irq(&gb_connections_lock); - retval = gb_connection_init(connection); - if (retval) { - dev_err(&hd->dev, "%s: failed to initialize connection: %d\n", - connection->name, retval); - gb_connection_destroy(connection); - return NULL; - } - return connection; err_free_connection: @@ -396,7 +386,7 @@ static int gb_connection_protocol_get_version(struct gb_connection *connection) return 0; } -static int gb_connection_init(struct gb_connection *connection) +int gb_connection_init(struct gb_connection *connection) { int ret; diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index 77f77bf64a4e..329b705bd425 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -63,6 +63,8 @@ static inline bool gb_connection_is_static(struct gb_connection *connection) return !connection->intf; } +int gb_connection_init(struct gb_connection *connection); + void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id, u8 *data, size_t length); diff --git a/drivers/staging/greybus/hd.c b/drivers/staging/greybus/hd.c index b280925792b5..74569a38698a 100644 --- a/drivers/staging/greybus/hd.c +++ b/drivers/staging/greybus/hd.c @@ -124,6 +124,13 @@ int gb_hd_add(struct gb_host_device *hd) return ret; } + ret = gb_connection_init(hd->svc_connection); + if (ret) { + gb_connection_destroy(hd->svc_connection); + device_del(&hd->dev); + return ret; + } + return 0; } EXPORT_SYMBOL_GPL(gb_hd_add); diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c index 9ff7464b8459..e8eed858b545 100644 --- a/drivers/staging/greybus/interface.c +++ b/drivers/staging/greybus/interface.c @@ -180,6 +180,12 @@ int gb_interface_init(struct gb_interface *intf, u8 device_id) return -ENOMEM; } + ret = gb_connection_init(connection); + if (ret) { + gb_connection_destroy(connection); + return ret; + } + /* Get manifest size using control protocol on CPort */ size = gb_control_get_manifest_size_operation(intf); if (size <= 0) { diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c index 72400e38b392..2d470500222e 100644 --- a/drivers/staging/greybus/manifest.c +++ b/drivers/staging/greybus/manifest.c @@ -228,6 +228,7 @@ static char *gb_string_get(struct gb_interface *intf, u8 string_id) */ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle) { + struct gb_connection *connection; struct gb_interface *intf = bundle->intf; struct manifest_desc *desc; struct manifest_desc *next; @@ -235,6 +236,7 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle) u8 protocol_id; u16 cport_id; u32 count = 0; + int ret; /* Set up all cport descriptors associated with this bundle */ list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) { @@ -254,10 +256,18 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle) /* Found one. Set up its function structure */ protocol_id = desc_cport->protocol_id; - if (!gb_connection_create_dynamic(intf, bundle, cport_id, - protocol_id)) + connection = gb_connection_create_dynamic(intf, bundle, + cport_id, + protocol_id); + if (!connection) goto exit; + ret = gb_connection_init(connection); + if (ret) { + gb_connection_destroy(connection); + goto exit; + } + count++; /* Release the cport descriptor */ -- cgit v1.2.3