#define pr_fmt(fmt)    "OF: " fmt
 
+#include <linux/cleanup.h>
 #include <linux/console.h>
 #include <linux/ctype.h>
 #include <linux/cpu.h>
                                   const char *stem_name,
                                   int index, struct of_phandle_args *out_args)
 {
-       char *cells_name, *map_name = NULL, *mask_name = NULL;
-       char *pass_name = NULL;
+       char *cells_name __free(kfree) = kasprintf(GFP_KERNEL, "#%s-cells", stem_name);
+       char *map_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map", stem_name);
+       char *mask_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map-mask", stem_name);
+       char *pass_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map-pass-thru", stem_name);
        struct device_node *cur, *new = NULL;
        const __be32 *map, *mask, *pass;
        static const __be32 dummy_mask[] = { [0 ... MAX_PHANDLE_ARGS] = cpu_to_be32(~0) };
        if (index < 0)
                return -EINVAL;
 
-       cells_name = kasprintf(GFP_KERNEL, "#%s-cells", stem_name);
-       if (!cells_name)
+       if (!cells_name || !map_name || !mask_name || !pass_name)
                return -ENOMEM;
 
-       ret = -ENOMEM;
-       map_name = kasprintf(GFP_KERNEL, "%s-map", stem_name);
-       if (!map_name)
-               goto free;
-
-       mask_name = kasprintf(GFP_KERNEL, "%s-map-mask", stem_name);
-       if (!mask_name)
-               goto free;
-
-       pass_name = kasprintf(GFP_KERNEL, "%s-map-pass-thru", stem_name);
-       if (!pass_name)
-               goto free;
-
        ret = __of_parse_phandle_with_args(np, list_name, cells_name, -1, index,
                                           out_args);
        if (ret)
-               goto free;
+               return ret;
 
        /* Get the #<list>-cells property */
        cur = out_args->np;
                /* Get the <list>-map property */
                map = of_get_property(cur, map_name, &map_len);
                if (!map) {
-                       ret = 0;
-                       goto free;
+                       return 0;
                }
                map_len /= sizeof(u32);
 
 put:
        of_node_put(cur);
        of_node_put(new);
-free:
-       kfree(mask_name);
-       kfree(map_name);
-       kfree(cells_name);
-       kfree(pass_name);
-
        return ret;
 }
 EXPORT_SYMBOL(of_parse_phandle_with_args_map);
 
 
 #define pr_fmt(fmt)    "OF: " fmt
 
+#include <linux/cleanup.h>
 #include <linux/of.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
                                    const u32 *array, size_t sz)
 {
        struct property prop;
-       __be32 *val;
-       int i, ret;
+       __be32 *val __free(kfree) = kcalloc(sz, sizeof(__be32), GFP_KERNEL);
+       int i;
 
-       val = kcalloc(sz, sizeof(__be32), GFP_KERNEL);
        if (!val)
                return -ENOMEM;
 
        prop.length = sizeof(u32) * sz;
        prop.value = (void *)val;
 
-       ret = of_changeset_add_prop_helper(ocs, np, &prop);
-       kfree(val);
-
-       return ret;
+       return of_changeset_add_prop_helper(ocs, np, &prop);
 }
 EXPORT_SYMBOL_GPL(of_changeset_add_prop_u32_array);
 
 
 #define pr_fmt(fmt)    "OF: resolver: " fmt
 
+#include <linux/cleanup.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
 {
        struct device_node *refnode;
        struct property *prop;
-       char *value, *cur, *end, *node_path, *prop_name, *s;
+       char *value __free(kfree) = kmemdup(prop_fixup->value, prop_fixup->length, GFP_KERNEL);
+       char *cur, *end, *node_path, *prop_name, *s;
        int offset, len;
        int err = 0;
 
-       value = kmemdup(prop_fixup->value, prop_fixup->length, GFP_KERNEL);
        if (!value)
                return -ENOMEM;
 
 
                node_path = cur;
                s = strchr(cur, ':');
-               if (!s) {
-                       err = -EINVAL;
-                       goto err_fail;
-               }
+               if (!s)
+                       return -EINVAL;
                *s++ = '\0';
 
                prop_name = s;
                s = strchr(s, ':');
-               if (!s) {
-                       err = -EINVAL;
-                       goto err_fail;
-               }
+               if (!s)
+                       return -EINVAL;
                *s++ = '\0';
 
                err = kstrtoint(s, 10, &offset);
                if (err)
-                       goto err_fail;
+                       return err;
 
                refnode = __of_find_node_by_full_path(of_node_get(overlay), node_path);
                if (!refnode)
                }
                of_node_put(refnode);
 
-               if (!prop) {
-                       err = -ENOENT;
-                       goto err_fail;
-               }
+               if (!prop)
+                       return -ENOENT;
 
-               if (offset < 0 || offset + sizeof(__be32) > prop->length) {
-                       err = -EINVAL;
-                       goto err_fail;
-               }
+               if (offset < 0 || offset + sizeof(__be32) > prop->length)
+                       return -EINVAL;
 
                *(__be32 *)(prop->value + offset) = cpu_to_be32(phandle);
        }
 
-err_fail:
-       kfree(value);
-       return err;
+       return 0;
 }
 
 /* compare nodes taking into account that 'name' strips out the @ part */