greybus: interface: free bundles on initialisation errors
authorJohan Hovold <johan@hovoldconsulting.com>
Wed, 9 Mar 2016 11:20:37 +0000 (12:20 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Thu, 10 Mar 2016 21:57:42 +0000 (13:57 -0800)
Immediately free any created bundle structures on interface
initialisation errors.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/interface.c

index a32e564851d81fa0fee10069fef48fa6a503b471..fe4efe1bbdd5cd1b7313abfde49019a6c06a91eb 100644 (file)
@@ -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;