Skip to content

Commit 56d426f

Browse files
krzkbroonie
authored andcommitted
ASoC: codecs: wcd934x: 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]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 6344ab5 commit 56d426f

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

sound/soc/codecs/wcd934x.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2019, Linaro Limited
33

4+
#include <linux/cleanup.h>
45
#include <linux/clk.h>
56
#include <linux/clk-provider.h>
67
#include <linux/interrupt.h>
@@ -4973,42 +4974,38 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w,
49734974
struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
49744975
unsigned int decimator;
49754976
char *dec_adc_mux_name = NULL;
4976-
char *widget_name = NULL;
4977-
char *wname;
4977+
char *widget_name;
49784978
int ret = 0, amic_n;
49794979
u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
49804980
u16 tx_gain_ctl_reg;
49814981
char *dec;
49824982
u8 hpf_coff_freq;
49834983

4984-
widget_name = kstrndup(w->name, 15, GFP_KERNEL);
4985-
if (!widget_name)
4984+
char *wname __free(kfree) = kstrndup(w->name, 15, GFP_KERNEL);
4985+
if (!wname)
49864986
return -ENOMEM;
49874987

4988-
wname = widget_name;
4988+
widget_name = wname;
49894989
dec_adc_mux_name = strsep(&widget_name, " ");
49904990
if (!dec_adc_mux_name) {
49914991
dev_err(comp->dev, "%s: Invalid decimator = %s\n",
49924992
__func__, w->name);
4993-
ret = -EINVAL;
4994-
goto out;
4993+
return -EINVAL;
49954994
}
49964995
dec_adc_mux_name = widget_name;
49974996

49984997
dec = strpbrk(dec_adc_mux_name, "012345678");
49994998
if (!dec) {
50004999
dev_err(comp->dev, "%s: decimator index not found\n",
50015000
__func__);
5002-
ret = -EINVAL;
5003-
goto out;
5001+
return -EINVAL;
50045002
}
50055003

50065004
ret = kstrtouint(dec, 10, &decimator);
50075005
if (ret < 0) {
50085006
dev_err(comp->dev, "%s: Invalid decimator = %s\n",
50095007
__func__, wname);
5010-
ret = -EINVAL;
5011-
goto out;
5008+
return -EINVAL;
50125009
}
50135010

50145011
tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL + 16 * decimator;
@@ -5101,8 +5098,7 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w,
51015098
WCD934X_DEC_PWR_LVL_DF);
51025099
break;
51035100
}
5104-
out:
5105-
kfree(wname);
5101+
51065102
return ret;
51075103
}
51085104

0 commit comments

Comments
 (0)