dm: core: Add a new flag to track platform data
authorSimon Glass <sjg@chromium.org>
Mon, 30 Dec 2019 04:19:21 +0000 (21:19 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 7 Jan 2020 23:02:38 +0000 (16:02 -0700)
We want to avoid allocating platform data twice. This could happen if
device_probe() is called after device_ofdata_to_platdata() for the same
device.

Add a flag to track whether device_ofdata_to_platdata() has been called on
a device. Check the flag to make sure it doesn't happen twice, and clear
the flag when the data is freed.

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

index 5c8dc4ad701bd37b347f240c0f3bc3202fa2a315..444e34b4921b047c329866e93d872ddb83b9e8d7 100644 (file)
@@ -140,6 +140,7 @@ void device_free(struct udevice *dev)
                        dev->parent_priv = NULL;
                }
        }
+       dev->flags &= ~DM_FLAG_PLATDATA_VALID;
 
        devres_release_probe(dev);
 }
index 9506c7df8d1531178d5a96cbeb2a560bbda84714..9f39218423e1e1f9b4d734d3d4a73d9f9b9ed710 100644 (file)
@@ -320,7 +320,7 @@ int device_ofdata_to_platdata(struct udevice *dev)
        if (!dev)
                return -EINVAL;
 
-       if (dev->flags & DM_FLAG_ACTIVATED)
+       if (dev->flags & DM_FLAG_PLATDATA_VALID)
                return 0;
 
        drv = dev->driver;
@@ -368,6 +368,8 @@ int device_ofdata_to_platdata(struct udevice *dev)
                        goto fail;
        }
 
+       dev->flags |= DM_FLAG_PLATDATA_VALID;
+
        return 0;
 fail:
        device_free(dev);
index 21774708e716ea6344a5672a1153bf645ee99e83..9ebfd0a34eb5f1b40333b27ed8280642eb39b96e 100644 (file)
@@ -65,6 +65,9 @@ struct driver_info;
 /* DM does not enable/disable the power domains corresponding to this device */
 #define DM_FLAG_DEFAULT_PD_CTRL_OFF    (1 << 11)
 
+/* Driver platdata has been read. Cleared when the device is removed */
+#define DM_FLAG_PLATDATA_VALID         (1 << 12)
+
 /*
  * One or multiple of these flags are passed to device_remove() so that
  * a selective device removal as specified by the remove-stage and the