Commit 82f898f4 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Lee Jones

mfd: syscon: Use scoped variables with memory allocators to simplify error paths

Allocate the memory with scoped/cleanup.h to reduce error handling and
make the code a bit simpler.
Signed-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240707114823.9175-2-krzysztof.kozlowski@linaro.orgSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent 41947838
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* Author: Dong Aisheng <dong.aisheng@linaro.org> * Author: Dong Aisheng <dong.aisheng@linaro.org>
*/ */
#include <linux/cleanup.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/hwspinlock.h> #include <linux/hwspinlock.h>
...@@ -45,7 +46,6 @@ static const struct regmap_config syscon_regmap_config = { ...@@ -45,7 +46,6 @@ static const struct regmap_config syscon_regmap_config = {
static struct syscon *of_syscon_register(struct device_node *np, bool check_res) static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
{ {
struct clk *clk; struct clk *clk;
struct syscon *syscon;
struct regmap *regmap; struct regmap *regmap;
void __iomem *base; void __iomem *base;
u32 reg_io_width; u32 reg_io_width;
...@@ -54,20 +54,16 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res) ...@@ -54,20 +54,16 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
struct resource res; struct resource res;
struct reset_control *reset; struct reset_control *reset;
syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); struct syscon *syscon __free(kfree) = kzalloc(sizeof(*syscon), GFP_KERNEL);
if (!syscon) if (!syscon)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (of_address_to_resource(np, 0, &res)) { if (of_address_to_resource(np, 0, &res))
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto err_map;
}
base = of_iomap(np, 0); base = of_iomap(np, 0);
if (!base) { if (!base)
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto err_map;
}
/* Parse the device's DT node for an endianness specification */ /* Parse the device's DT node for an endianness specification */
if (of_property_read_bool(np, "big-endian")) if (of_property_read_bool(np, "big-endian"))
...@@ -152,7 +148,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res) ...@@ -152,7 +148,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
list_add_tail(&syscon->list, &syscon_list); list_add_tail(&syscon->list, &syscon_list);
spin_unlock(&syscon_list_slock); spin_unlock(&syscon_list_slock);
return syscon; return_ptr(syscon);
err_reset: err_reset:
reset_control_put(reset); reset_control_put(reset);
...@@ -163,8 +159,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res) ...@@ -163,8 +159,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
regmap_exit(regmap); regmap_exit(regmap);
err_regmap: err_regmap:
iounmap(base); iounmap(base);
err_map:
kfree(syscon);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment