From a77660a75a3f79c71064dc6848a2975731ca5c00 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 9 Mar 2016 12:20:37 +0100 Subject: [PATCH] greybus: interface: free bundles on initialisation errors Immediately free any created bundle structures on interface initialisation errors. Signed-off-by: Johan Hovold Reviewed-by: Jeffrey Carlyle Reviewed-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/interface.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c index a32e564851d8..fe4efe1bbdd5 100644 --- a/drivers/staging/greybus/interface.c +++ b/drivers/staging/greybus/interface.c @@ -185,6 +185,7 @@ void gb_interfaces_remove(struct gb_host_device *hd) */ int gb_interface_init(struct gb_interface *intf) { + struct gb_bundle *bundle, *tmp; int ret, size; void *manifest; @@ -211,7 +212,7 @@ int gb_interface_init(struct gb_interface *intf) ret = gb_control_get_manifest_operation(intf, manifest, size); if (ret) { dev_err(&intf->dev, "failed to get manifest: %d\n", ret); - goto free_manifest; + goto err_free_manifest; } /* @@ -221,18 +222,25 @@ int gb_interface_init(struct gb_interface *intf) if (!gb_manifest_parse(intf, manifest, size)) { dev_err(&intf->dev, "failed to parse manifest\n"); ret = -EINVAL; - goto free_manifest; + goto err_destroy_bundles; } ret = gb_control_get_interface_version_operation(intf); if (ret) - goto free_manifest; + goto err_destroy_bundles; ret = gb_control_get_bundle_versions(intf->control); if (ret) - goto free_manifest; + goto err_destroy_bundles; + + kfree(manifest); -free_manifest: + return 0; + +err_destroy_bundles: + list_for_each_entry_safe(bundle, tmp, &intf->bundles, links) + gb_bundle_destroy(bundle); +err_free_manifest: kfree(manifest); return ret; -- 2.20.1