diff options
author | Rob Herring <robh@kernel.org> | 2024-04-09 21:59:40 +0300 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2024-04-15 16:40:40 +0300 |
commit | 40b0f17453fca50165c9d56401be663448e9136c (patch) | |
tree | c3ba7211c1177690af02673aeffdee10f66dca9e /drivers/of/dynamic.c | |
parent | 1c5e3d9bf33b811e1c6dd9081b322004acc4a1fd (diff) | |
download | linux-40b0f17453fca50165c9d56401be663448e9136c.tar.xz |
of: Use scope based kfree() cleanups
Use the relatively new scope based kfree() cleanup to simplify error
handling. Doing so reduces the chances of memory leaks and simplifies
error paths by avoiding the need for goto statements.
Reviewed-by: Saravana Kannan <saravanak@google.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20240409-dt-cleanup-free-v2-2-5b419a4af38d@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'drivers/of/dynamic.c')
-rw-r--r-- | drivers/of/dynamic.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index af7c57a7a25d..43f4e2c93bd2 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -9,6 +9,7 @@ #define pr_fmt(fmt) "OF: " fmt +#include <linux/cleanup.h> #include <linux/of.h> #include <linux/spinlock.h> #include <linux/slab.h> @@ -1019,10 +1020,9 @@ int of_changeset_add_prop_u32_array(struct of_changeset *ocs, 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; @@ -1032,9 +1032,6 @@ int of_changeset_add_prop_u32_array(struct of_changeset *ocs, 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); |