summaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/manifest.c
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2015-06-12 10:21:09 -0500
committerGreg Kroah-Hartman <gregkh@google.com>2015-06-12 12:14:24 -0700
commit52e8ce317fe51dea86777b164b63e41e50f8a7bf (patch)
tree5d41433a8462a7174d12ff129cc9e0421c6cd03a /drivers/staging/greybus/manifest.c
parentf9b0366f16c3926e92e7d108fe8666fac671d026 (diff)
greybus: manifest: clean up properly when parsing cports
Currently, if an error occurs creating a connection, we simply return an error without cleaning up any of the connections that had already been successfully set up. Add code to destroy connections that have been created in the event an error occurs. Add a check to ensure the bundle's list of connections was empty before parsing for CPorts begins. Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging/greybus/manifest.c')
-rw-r--r--drivers/staging/greybus/manifest.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c
index 9881b7a1d92d..0b509cd38511 100644
--- a/drivers/staging/greybus/manifest.c
+++ b/drivers/staging/greybus/manifest.c
@@ -201,11 +201,16 @@ static char *gb_string_get(struct gb_interface *intf, u8 string_id)
static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
{
struct gb_interface *intf = bundle->intf;
+ struct gb_connection *connection;
+ struct gb_connection *connection_next;
struct manifest_desc *desc;
struct manifest_desc *next;
u8 bundle_id = bundle->id;
u32 count = 0;
+ if (WARN_ON(!list_empty(&bundle->connections)))
+ return 0;
+
/* Set up all cport descriptors associated with this bundle */
list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) {
struct greybus_descriptor_cport *desc_cport;
@@ -223,7 +228,7 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
protocol_id = desc_cport->protocol_id;
cport_id = le16_to_cpu(desc_cport->id);
if (!gb_connection_create(bundle, cport_id, protocol_id))
- return 0; /* Error */
+ goto cleanup;
count++;
@@ -232,6 +237,14 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
}
return count;
+cleanup:
+ /* An error occurred; undo any changes we've made */
+ list_for_each_entry_safe(connection, connection_next,
+ &bundle->connections, bundle_links) {
+ gb_connection_destroy(connection);
+ count--;
+ }
+ return 0; /* Error; count should also be 0 */
}
/*