Skip to content

Commit 5b3cc85

Browse files
krzkbroonie
authored andcommitted
ASoC: dapm: Simplify dapm_cnew_widget() with cleanup.h
Allocate the memory with scoped/cleanup.h in dapm_cnew_widget() to reduce error handling (less error paths) and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1a7b846 commit 5b3cc85

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

sound/soc/soc-dapm.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/module.h>
2121
#include <linux/init.h>
2222
#include <linux/async.h>
23+
#include <linux/cleanup.h>
2324
#include <linux/delay.h>
2425
#include <linux/pm.h>
2526
#include <linux/bitops.h>
@@ -323,30 +324,28 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
323324
const struct snd_soc_dapm_widget *_widget,
324325
const char *prefix)
325326
{
326-
struct snd_soc_dapm_widget *w;
327-
328-
w = kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
327+
struct snd_soc_dapm_widget *w __free(kfree) = kmemdup(_widget,
328+
sizeof(*_widget),
329+
GFP_KERNEL);
329330
if (!w)
330331
return NULL;
331332

332333
if (prefix)
333334
w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, _widget->name);
334335
else
335336
w->name = kstrdup_const(_widget->name, GFP_KERNEL);
336-
if (!w->name) {
337-
kfree(w);
337+
if (!w->name)
338338
return NULL;
339-
}
340339

341340
if (_widget->sname) {
342341
w->sname = kstrdup_const(_widget->sname, GFP_KERNEL);
343342
if (!w->sname) {
344343
kfree_const(w->name);
345-
kfree(w);
346344
return NULL;
347345
}
348346
}
349-
return w;
347+
348+
return_ptr(w);
350349
}
351350

352351
struct dapm_kcontrol_data {

0 commit comments

Comments
 (0)