Skip to content

Commit 6440e7b

Browse files
krzkbroonie
authored andcommitted
ASoC: simple-card-utils: Simplify with cleanup.h
Allocate the memory with scoped/cleanup.h to reduce error handling (less error paths) and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski <[email protected]> Acked-by: Kuninori Morimoto <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 56d426f commit 6440e7b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

sound/soc/generic/simple-card-utils.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Copyright (c) 2016 Kuninori Morimoto <[email protected]>
66

77
#include <dt-bindings/sound/audio-graph.h>
8+
#include <linux/cleanup.h>
89
#include <linux/clk.h>
910
#include <linux/gpio/consumer.h>
1011
#include <linux/module.h>
@@ -135,8 +136,8 @@ EXPORT_SYMBOL_GPL(simple_util_parse_daifmt);
135136
int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np,
136137
struct simple_util_dai *dai)
137138
{
138-
u32 *array_values, *p;
139139
int n, i, ret;
140+
u32 *p;
140141

141142
if (!of_property_read_bool(np, "dai-tdm-slot-width-map"))
142143
return 0;
@@ -151,14 +152,15 @@ int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np,
151152
if (!dai->tdm_width_map)
152153
return -ENOMEM;
153154

154-
array_values = kcalloc(n, sizeof(*array_values), GFP_KERNEL);
155+
u32 *array_values __free(kfree) = kcalloc(n, sizeof(*array_values),
156+
GFP_KERNEL);
155157
if (!array_values)
156158
return -ENOMEM;
157159

158160
ret = of_property_read_u32_array(np, "dai-tdm-slot-width-map", array_values, n);
159161
if (ret < 0) {
160162
dev_err(dev, "Could not read dai-tdm-slot-width-map: %d\n", ret);
161-
goto out;
163+
return ret;
162164
}
163165

164166
p = array_values;
@@ -169,11 +171,8 @@ int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np,
169171
}
170172

171173
dai->n_tdm_widths = i;
172-
ret = 0;
173-
out:
174-
kfree(array_values);
175174

176-
return ret;
175+
return 0;
177176
}
178177
EXPORT_SYMBOL_GPL(simple_util_parse_tdm_width_map);
179178

0 commit comments

Comments
 (0)