Skip to content

Commit 6344ab5

Browse files
krzkbroonie
authored andcommitted
ASoC: codecs: wcd9335: 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 f9cbfb6 commit 6344ab5

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

sound/soc/codecs/wcd9335.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/module.h>
66
#include <linux/init.h>
77
#include <linux/platform_device.h>
8+
#include <linux/cleanup.h>
89
#include <linux/device.h>
910
#include <linux/wait.h>
1011
#include <linux/bitops.h>
@@ -2714,42 +2715,38 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
27142715
struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
27152716
unsigned int decimator;
27162717
char *dec_adc_mux_name = NULL;
2717-
char *widget_name = NULL;
2718-
char *wname;
2718+
char *widget_name;
27192719
int ret = 0, amic_n;
27202720
u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
27212721
u16 tx_gain_ctl_reg;
27222722
char *dec;
27232723
u8 hpf_coff_freq;
27242724

2725-
widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL);
2726-
if (!widget_name)
2725+
char *wname __free(kfree) = kmemdup_nul(w->name, 15, GFP_KERNEL);
2726+
if (!wname)
27272727
return -ENOMEM;
27282728

2729-
wname = widget_name;
2729+
widget_name = wname;
27302730
dec_adc_mux_name = strsep(&widget_name, " ");
27312731
if (!dec_adc_mux_name) {
27322732
dev_err(comp->dev, "%s: Invalid decimator = %s\n",
27332733
__func__, w->name);
2734-
ret = -EINVAL;
2735-
goto out;
2734+
return -EINVAL;
27362735
}
27372736
dec_adc_mux_name = widget_name;
27382737

27392738
dec = strpbrk(dec_adc_mux_name, "012345678");
27402739
if (!dec) {
27412740
dev_err(comp->dev, "%s: decimator index not found\n",
27422741
__func__);
2743-
ret = -EINVAL;
2744-
goto out;
2742+
return -EINVAL;
27452743
}
27462744

27472745
ret = kstrtouint(dec, 10, &decimator);
27482746
if (ret < 0) {
27492747
dev_err(comp->dev, "%s: Invalid decimator = %s\n",
27502748
__func__, wname);
2751-
ret = -EINVAL;
2752-
goto out;
2749+
return -EINVAL;
27532750
}
27542751

27552752
tx_vol_ctl_reg = WCD9335_CDC_TX0_TX_PATH_CTL + 16 * decimator;
@@ -2836,8 +2833,7 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
28362833
snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 0x10, 0x00);
28372834
break;
28382835
}
2839-
out:
2840-
kfree(wname);
2836+
28412837
return ret;
28422838
}
28432839

0 commit comments

Comments
 (0)