]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Use access methods for dev/uclass private data
authorSimon Glass <sjg@chromium.org>
Wed, 23 Dec 2020 02:30:29 +0000 (19:30 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 5 Jan 2021 19:24:40 +0000 (12:24 -0700)
Use these functions in the core code as much as possible. With this, there
are only two places where each priv/plat pointer is accessed, one for read
and one for write.

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

index 8c121697711a40dadeb62634cdd1655fe7c88b0f..e15ab051be765e0de50fd15313b98e450a398990 100644 (file)
@@ -94,11 +94,11 @@ int device_unbind(struct udevice *dev)
        }
        if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) {
                free(dev_get_uclass_plat(dev));
-               dev->uclass_plat = NULL;
+               dev_set_uclass_plat(dev, NULL);
        }
        if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) {
                free(dev_get_parent_plat(dev));
-               dev->parent_plat = NULL;
+               dev_set_parent_plat(dev, NULL);
        }
        ret = uclass_unbind_device(dev);
        if (ret)
@@ -131,7 +131,7 @@ void device_free(struct udevice *dev)
        size = dev->uclass->uc_drv->per_device_auto;
        if (size) {
                free(dev_get_uclass_priv(dev));
-               dev->uclass_priv = NULL;
+               dev_set_uclass_priv(dev, NULL);
        }
        if (dev->parent) {
                size = dev->parent->driver->per_child_auto;
@@ -141,7 +141,7 @@ void device_free(struct udevice *dev)
                }
                if (size) {
                        free(dev_get_parent_priv(dev));
-                       dev->parent_priv = NULL;
+                       dev_set_parent_priv(dev, NULL);
                }
        }
        dev->flags &= ~DM_FLAG_PLATDATA_VALID;
index f2d750c8de44003caa2c32d9b58aea29750190b8..261c3b279353ac4105aff98581ea8efdca3e7840 100644 (file)
@@ -42,6 +42,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
        struct uclass *uc;
        int size, ret = 0;
        bool auto_seq = true;
+       void *ptr;
 
        if (devp)
                *devp = NULL;
@@ -64,7 +65,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
 #ifdef CONFIG_DEVRES
        INIT_LIST_HEAD(&dev->devres_head);
 #endif
-       dev->plat = plat;
+       dev_set_plat(dev, plat);
        dev->driver_data = driver_data;
        dev->name = name;
        dev->node = node;
@@ -102,25 +103,26 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
                }
                if (alloc) {
                        dev->flags |= DM_FLAG_ALLOC_PDATA;
-                       dev->plat = calloc(1, drv->plat_auto);
-                       if (!dev->plat) {
+                       ptr = calloc(1, drv->plat_auto);
+                       if (!ptr) {
                                ret = -ENOMEM;
                                goto fail_alloc1;
                        }
-                       if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat) {
-                               memcpy(dev->plat, plat, of_plat_size);
-                       }
+                       if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat)
+                               memcpy(ptr, plat, of_plat_size);
+                       dev_set_plat(dev, ptr);
                }
        }
 
        size = uc->uc_drv->per_device_plat_auto;
        if (size) {
                dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA;
-               dev->uclass_plat = calloc(1, size);
-               if (!dev->uclass_plat) {
+               ptr = calloc(1, size);
+               if (!ptr) {
                        ret = -ENOMEM;
                        goto fail_alloc2;
                }
+               dev_set_uclass_plat(dev, ptr);
        }
 
        if (parent) {
@@ -130,11 +132,12 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
                }
                if (size) {
                        dev->flags |= DM_FLAG_ALLOC_PARENT_PDATA;
-                       dev->parent_plat = calloc(1, size);
-                       if (!dev->parent_plat) {
+                       ptr = calloc(1, size);
+                       if (!ptr) {
                                ret = -ENOMEM;
                                goto fail_alloc3;
                        }
+                       dev_set_parent_plat(dev, ptr);
                }
                /* put dev into parent's successor list */
                list_add_tail(&dev->sibling_node, &parent->child_head);
@@ -191,19 +194,19 @@ fail_uclass_bind:
        if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
                list_del(&dev->sibling_node);
                if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) {
-                       free(dev->parent_plat);
-                       dev->parent_plat = NULL;
+                       free(dev_get_parent_plat(dev));
+                       dev_set_parent_plat(dev, NULL);
                }
        }
 fail_alloc3:
        if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) {
-               free(dev->uclass_plat);
-               dev->uclass_plat = NULL;
+               free(dev_get_uclass_plat(dev));
+               dev_set_uclass_plat(dev, NULL);
        }
 fail_alloc2:
        if (dev->flags & DM_FLAG_ALLOC_PDATA) {
-               free(dev->plat);
-               dev->plat = NULL;
+               free(dev_get_plat(dev));
+               dev_set_plat(dev, NULL);
        }
 fail_alloc1:
        devres_release_all(dev);
@@ -324,6 +327,7 @@ int device_of_to_plat(struct udevice *dev)
 {
        const struct driver *drv;
        int size = 0;
+       void *ptr;
        int ret;
 
        if (!dev)
@@ -352,36 +356,37 @@ int device_of_to_plat(struct udevice *dev)
        assert(drv);
 
        /* Allocate private data if requested and not reentered */
-       if (drv->priv_auto && !dev->priv) {
-               dev->priv = alloc_priv(drv->priv_auto, drv->flags);
-               if (!dev->priv) {
+       if (drv->priv_auto && !dev_get_priv(dev)) {
+               ptr = alloc_priv(drv->priv_auto, drv->flags);
+               if (!ptr) {
                        ret = -ENOMEM;
                        goto fail;
                }
+               dev_set_priv(dev, ptr);
        }
        /* Allocate private data if requested and not reentered */
        size = dev->uclass->uc_drv->per_device_auto;
-       if (size && !dev->uclass_priv) {
-               dev->uclass_priv = alloc_priv(size,
-                                             dev->uclass->uc_drv->flags);
-               if (!dev->uclass_priv) {
+       if (size && !dev_get_uclass_priv(dev)) {
+               ptr = alloc_priv(size, dev->uclass->uc_drv->flags);
+               if (!ptr) {
                        ret = -ENOMEM;
                        goto fail;
                }
+               dev_set_uclass_priv(dev, ptr);
        }
 
        /* Allocate parent data for this child */
        if (dev->parent) {
                size = dev->parent->driver->per_child_auto;
-               if (!size) {
+               if (!size)
                        size = dev->parent->uclass->uc_drv->per_child_auto;
-               }
-               if (size && !dev->parent_priv) {
-                       dev->parent_priv = alloc_priv(size, drv->flags);
-                       if (!dev->parent_priv) {
+               if (size && !dev_get_parent_priv(dev)) {
+                       ptr = alloc_priv(size, drv->flags);
+                       if (!ptr) {
                                ret = -ENOMEM;
                                goto fail;
                        }
+                       dev_set_parent_priv(dev, ptr);
                }
        }
 
index 5e24927b341f4ed859c552e49868e97ba58dd2a2..e845f604724a9c5fbea31682164ce090e53b9c8e 100644 (file)
@@ -72,11 +72,14 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp)
        if (!uc)
                return -ENOMEM;
        if (uc_drv->priv_auto) {
-               uc->priv = calloc(1, uc_drv->priv_auto);
-               if (!uc->priv) {
+               void *ptr;
+
+               ptr = calloc(1, uc_drv->priv_auto);
+               if (!ptr) {
                        ret = -ENOMEM;
                        goto fail_mem;
                }
+               uclass_set_priv(uc, ptr);
        }
        uc->uc_drv = uc_drv;
        INIT_LIST_HEAD(&uc->sibling_node);
@@ -94,8 +97,8 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp)
        return 0;
 fail:
        if (uc_drv->priv_auto) {
-               free(uc->priv);
-               uc->priv = NULL;
+               free(uclass_get_priv(uc));
+               uclass_set_priv(uc, NULL);
        }
        list_del(&uc->sibling_node);
 fail_mem:
@@ -132,7 +135,7 @@ int uclass_destroy(struct uclass *uc)
                uc_drv->destroy(uc);
        list_del(&uc->sibling_node);
        if (uc_drv->priv_auto)
-               free(uc->priv);
+               free(uclass_get_priv(uc));
        free(uc);
 
        return 0;