Skip to content

Commit 82f898f

Browse files
krzklag-linaro
authored andcommitted
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: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 4194783 commit 82f898f

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

drivers/mfd/syscon.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Author: Dong Aisheng <[email protected]>
99
*/
1010

11+
#include <linux/cleanup.h>
1112
#include <linux/clk.h>
1213
#include <linux/err.h>
1314
#include <linux/hwspinlock.h>
@@ -45,7 +46,6 @@ static const struct regmap_config syscon_regmap_config = {
4546
static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
4647
{
4748
struct clk *clk;
48-
struct syscon *syscon;
4949
struct regmap *regmap;
5050
void __iomem *base;
5151
u32 reg_io_width;
@@ -54,20 +54,16 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
5454
struct resource res;
5555
struct reset_control *reset;
5656

57-
syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
57+
struct syscon *syscon __free(kfree) = kzalloc(sizeof(*syscon), GFP_KERNEL);
5858
if (!syscon)
5959
return ERR_PTR(-ENOMEM);
6060

61-
if (of_address_to_resource(np, 0, &res)) {
62-
ret = -ENOMEM;
63-
goto err_map;
64-
}
61+
if (of_address_to_resource(np, 0, &res))
62+
return ERR_PTR(-ENOMEM);
6563

6664
base = of_iomap(np, 0);
67-
if (!base) {
68-
ret = -ENOMEM;
69-
goto err_map;
70-
}
65+
if (!base)
66+
return ERR_PTR(-ENOMEM);
7167

7268
/* Parse the device's DT node for an endianness specification */
7369
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)
152148
list_add_tail(&syscon->list, &syscon_list);
153149
spin_unlock(&syscon_list_slock);
154150

155-
return syscon;
151+
return_ptr(syscon);
156152

157153
err_reset:
158154
reset_control_put(reset);
@@ -163,8 +159,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
163159
regmap_exit(regmap);
164160
err_regmap:
165161
iounmap(base);
166-
err_map:
167-
kfree(syscon);
168162
return ERR_PTR(ret);
169163
}
170164

0 commit comments

Comments
 (0)