summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-12-19 10:40:08 -0700
committerSimon Glass <sjg@chromium.org>2021-01-05 12:24:41 -0700
commit82021e31a71ae51bea1226e58727dd3163a26895 (patch)
treecc061e3e361eb03a5e782117c5b5dce894440b5a
parente7144b07e46af8e7c10841aaeb4d517ad33f4242 (diff)
downloadu-boot-82021e31a71ae51bea1226e58727dd3163a26895.tar.gz
u-boot-82021e31a71ae51bea1226e58727dd3163a26895.tar.bz2
u-boot-82021e31a71ae51bea1226e58727dd3163a26895.zip
dm: core: Split out alloc code into a new function
Add a new function to handle the allocation of private/platform data for a device. This will make it easier to skip this feature when using the new of-platdata. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/core/device.c89
1 files changed, 52 insertions, 37 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index a4c8310f81..72169632c8 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -323,34 +323,17 @@ static void *alloc_priv(int size, uint flags)
return priv;
}
-int device_of_to_plat(struct udevice *dev)
+/**
+ * device_alloc_priv() - Allocate priv/plat data required by the device
+ *
+ * @dev: Device to process
+ * @return 0 if OK, -ENOMEM if out of memory
+ */
+static int device_alloc_priv(struct udevice *dev)
{
const struct driver *drv;
- int size = 0;
void *ptr;
- int ret;
-
- if (!dev)
- return -EINVAL;
-
- if (dev->flags & DM_FLAG_PLATDATA_VALID)
- return 0;
-
- /* Ensure all parents have ofdata */
- if (dev->parent) {
- ret = device_of_to_plat(dev->parent);
- if (ret)
- goto fail;
-
- /*
- * The device might have already been probed during
- * the call to device_probe() on its parent device
- * (e.g. PCI bridge devices). Test the flags again
- * so that we don't mess up the device.
- */
- if (dev->flags & DM_FLAG_PLATDATA_VALID)
- return 0;
- }
+ int size;
drv = dev->driver;
assert(drv);
@@ -358,20 +341,17 @@ int device_of_to_plat(struct udevice *dev)
/* Allocate private data if requested and not reentered */
if (drv->priv_auto && !dev_get_priv(dev)) {
ptr = alloc_priv(drv->priv_auto, drv->flags);
- if (!ptr) {
- ret = -ENOMEM;
- goto fail;
- }
+ if (!ptr)
+ return -ENOMEM;
dev_set_priv(dev, ptr);
}
+
/* Allocate private data if requested and not reentered */
size = dev->uclass->uc_drv->per_device_auto;
if (size && !dev_get_uclass_priv(dev)) {
ptr = alloc_priv(size, dev->uclass->uc_drv->flags);
- if (!ptr) {
- ret = -ENOMEM;
- goto fail;
- }
+ if (!ptr)
+ return -ENOMEM;
dev_set_uclass_priv(dev, ptr);
}
@@ -382,14 +362,49 @@ int device_of_to_plat(struct udevice *dev)
size = dev->parent->uclass->uc_drv->per_child_auto;
if (size && !dev_get_parent_priv(dev)) {
ptr = alloc_priv(size, drv->flags);
- if (!ptr) {
- ret = -ENOMEM;
- goto fail;
- }
+ if (!ptr)
+ return -ENOMEM;
dev_set_parent_priv(dev, ptr);
}
}
+ return 0;
+}
+
+int device_of_to_plat(struct udevice *dev)
+{
+ const struct driver *drv;
+ int ret;
+
+ if (!dev)
+ return -EINVAL;
+
+ if (dev->flags & DM_FLAG_PLATDATA_VALID)
+ return 0;
+
+ /* Ensure all parents have ofdata */
+ if (dev->parent) {
+ ret = device_of_to_plat(dev->parent);
+ if (ret)
+ goto fail;
+
+ /*
+ * The device might have already been probed during
+ * the call to device_probe() on its parent device
+ * (e.g. PCI bridge devices). Test the flags again
+ * so that we don't mess up the device.
+ */
+ if (dev->flags & DM_FLAG_PLATDATA_VALID)
+ return 0;
+ }
+
+ ret = device_alloc_priv(dev);
+ if (ret)
+ goto fail;
+
+ drv = dev->driver;
+ assert(drv);
+
if (drv->of_to_plat &&
(CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) {
ret = drv->of_to_plat(dev);