gpu: host1x: Cleanup on initialization failure
authorThierry Reding <treding@nvidia.com>
Wed, 8 Nov 2017 12:08:21 +0000 (13:08 +0100)
committerThierry Reding <treding@nvidia.com>
Wed, 13 Dec 2017 12:42:03 +0000 (13:42 +0100)
When an error happens during the initialization of one of the sub-
devices, make sure to properly cleanup all sub-devices that have been
initialized up to that point.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/gpu/host1x/bus.c

index 2e57c9cea696e317ae67a5ee9a7eb2b512fb2cf7..88a3558b7916e454a9cf5e365916b0751cc531f6 100644 (file)
@@ -211,8 +211,7 @@ int host1x_device_init(struct host1x_device *device)
                                dev_err(&device->dev,
                                        "failed to initialize %s: %d\n",
                                        dev_name(client->dev), err);
-                               mutex_unlock(&device->clients_lock);
-                               return err;
+                               goto teardown;
                        }
                }
        }
@@ -220,6 +219,14 @@ int host1x_device_init(struct host1x_device *device)
        mutex_unlock(&device->clients_lock);
 
        return 0;
+
+teardown:
+       list_for_each_entry_continue_reverse(client, &device->clients, list)
+               if (client->ops->exit)
+                       client->ops->exit(client);
+
+       mutex_unlock(&device->clients_lock);
+       return err;
 }
 EXPORT_SYMBOL(host1x_device_init);