diff options
author | Alex Elder <elder@linaro.org> | 2015-06-12 18:21:12 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@google.com> | 2015-06-12 22:14:24 +0300 |
commit | 2a64fb0e1e13eee53e56805d8a1f0ff7bbf57306 (patch) | |
tree | 1b440616233035f9d97a0da5888114270e5bb3d0 /drivers/staging/greybus/manifest.c | |
parent | fe53b45ca8143e7f1073ff31d7c4cfb4e92dc824 (diff) | |
download | linux-2a64fb0e1e13eee53e56805d8a1f0ff7bbf57306.tar.xz |
greybus: manifest: clean up properly when parsing bundles
Currently, if an error occurs creating a bundle, we simply
return an error without cleaning up any of the bundles that
had already been successfully set up.
Add code to destroy bundles that have been created in the event
an error occurs. Add a check to ensure the interface's list of
bundles was empty before parsing for bundles 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.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c index 0b509cd38511..e329f3763176 100644 --- a/drivers/staging/greybus/manifest.c +++ b/drivers/staging/greybus/manifest.c @@ -256,11 +256,15 @@ static u32 gb_manifest_parse_bundles(struct gb_interface *intf) { struct manifest_desc *desc; struct manifest_desc *next; + struct gb_bundle *bundle; + struct gb_bundle *bundle_next; u32 count = 0; + if (WARN_ON(!list_empty(&intf->bundles))) + return 0; + list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) { struct greybus_descriptor_bundle *desc_bundle; - struct gb_bundle *bundle; if (desc->type != GREYBUS_TYPE_BUNDLE) continue; @@ -270,11 +274,11 @@ static u32 gb_manifest_parse_bundles(struct gb_interface *intf) bundle = gb_bundle_create(intf, desc_bundle->id, desc_bundle->class); if (!bundle) - return 0; /* Error */ + goto cleanup; /* Now go set up this bundle's functions and cports */ if (!gb_manifest_parse_cports(bundle)) - return 0; /* Error parsing cports */ + goto cleanup; count++; @@ -283,6 +287,13 @@ static u32 gb_manifest_parse_bundles(struct gb_interface *intf) } return count; +cleanup: + /* An error occurred; undo any changes we've made */ + list_for_each_entry_safe(bundle, bundle_next, &intf->bundles, links) { + gb_bundle_destroy(bundle); + count--; + } + return 0; /* Error; count should also be 0 */ } static bool gb_manifest_parse_interface(struct gb_interface *intf, |