ofnode: Indicate when out of space in a few places
authorSimon Glass <sjg@chromium.org>
Sat, 11 Jan 2025 00:00:10 +0000 (17:00 -0700)
committerTom Rini <trini@konsulko.com>
Wed, 22 Jan 2025 21:58:03 +0000 (15:58 -0600)
Update ofnode_add_subnode() and ofnode_add_prop() to return a suitable
error when space is exhausted in the FDT. This makes it easier to see
what is going wrong.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
drivers/core/ofnode.c

index 98483c0..83c6006 100644 (file)
@@ -1710,9 +1710,10 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,
 int ofnode_write_prop(ofnode node, const char *propname, const void *value,
                      int len, bool copy)
 {
+       int ret;
+
        if (of_live_active()) {
                void *newval;
-               int ret;
 
                if (copy) {
                        newval = malloc(len);
@@ -1726,8 +1727,12 @@ int ofnode_write_prop(ofnode node, const char *propname, const void *value,
                        free(newval);
                return ret;
        } else {
-               return fdt_setprop(ofnode_to_fdt(node), ofnode_to_offset(node),
-                                  propname, value, len);
+               ret = fdt_setprop(ofnode_to_fdt(node), ofnode_to_offset(node),
+                                 propname, value, len);
+               if (ret)
+                       return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EINVAL;
+
+               return 0;
        }
 }
 
@@ -2015,7 +2020,7 @@ int ofnode_add_subnode(ofnode node, const char *name, ofnode *subnodep)
                        ret = -EEXIST;
                }
                if (offset < 0)
-                       return -EINVAL;
+                       return offset == -FDT_ERR_NOSPACE ? -ENOSPC : -EINVAL;
                subnode = noffset_to_ofnode(node, offset);
        }