]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Add DM_DEVICE_REMOVE condition to all exit paths
authorSimon Glass <sjg@chromium.org>
Thu, 4 Feb 2021 04:29:44 +0000 (21:29 -0700)
committerSimon Glass <sjg@chromium.org>
Thu, 4 Mar 2021 02:17:25 +0000 (19:17 -0700)
At present device_bind() does some unnecessary work if a device fails to
bind in SPL. Add the missing conditions.

Also fix a style nit in the same function while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/core/device.c

index d1098a3861aec3bc2fb8c63a88a63f4f6b9a4b0f..81f6880eac410e0833e5e733969537caf7076684 100644 (file)
@@ -137,9 +137,8 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
 
        if (parent) {
                size = parent->driver->per_child_plat_auto;
-               if (!size) {
+               if (!size)
                        size = parent->uclass->uc_drv->per_child_plat_auto;
-               }
                if (size) {
                        dev_or_flags(dev, DM_FLAG_ALLOC_PARENT_PDATA);
                        ptr = calloc(1, size);
@@ -209,14 +208,18 @@ fail_uclass_bind:
                }
        }
 fail_alloc3:
-       if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) {
-               free(dev_get_uclass_plat(dev));
-               dev_set_uclass_plat(dev, NULL);
+       if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
+               if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) {
+                       free(dev_get_uclass_plat(dev));
+                       dev_set_uclass_plat(dev, NULL);
+               }
        }
 fail_alloc2:
-       if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) {
-               free(dev_get_plat(dev));
-               dev_set_plat(dev, NULL);
+       if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
+               if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) {
+                       free(dev_get_plat(dev));
+                       dev_set_plat(dev, NULL);
+               }
        }
 fail_alloc1:
        devres_release_all(dev);