Skip to content

Commit

Permalink
ASoC: codecs: wcd934x: Simplify with cleanup.h
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
krzk authored and broonie committed Jul 8, 2024
1 parent 6344ab5 commit 56d426f
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions sound/soc/codecs/wcd934x.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2019, Linaro Limited

#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/interrupt.h>
Expand Down Expand Up @@ -4973,42 +4974,38 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w,
struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
unsigned int decimator;
char *dec_adc_mux_name = NULL;
char *widget_name = NULL;
char *wname;
char *widget_name;
int ret = 0, amic_n;
u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
u16 tx_gain_ctl_reg;
char *dec;
u8 hpf_coff_freq;

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

wname = widget_name;
widget_name = wname;
dec_adc_mux_name = strsep(&widget_name, " ");
if (!dec_adc_mux_name) {
dev_err(comp->dev, "%s: Invalid decimator = %s\n",
__func__, w->name);
ret = -EINVAL;
goto out;
return -EINVAL;
}
dec_adc_mux_name = widget_name;

dec = strpbrk(dec_adc_mux_name, "012345678");
if (!dec) {
dev_err(comp->dev, "%s: decimator index not found\n",
__func__);
ret = -EINVAL;
goto out;
return -EINVAL;
}

ret = kstrtouint(dec, 10, &decimator);
if (ret < 0) {
dev_err(comp->dev, "%s: Invalid decimator = %s\n",
__func__, wname);
ret = -EINVAL;
goto out;
return -EINVAL;
}

tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL + 16 * decimator;
Expand Down Expand Up @@ -5101,8 +5098,7 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w,
WCD934X_DEC_PWR_LVL_DF);
break;
}
out:
kfree(wname);

return ret;
}

Expand Down

0 comments on commit 56d426f

Please sign in to comment.