Commit 0c6c6511 authored by Mark Brown's avatar Mark Brown

ASoC: Simplify code with cleanup.h

Merge series from Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>:

Allocate the memory with scoped/cleanup.h to reduce error handling
(simpler error paths) and make the code a bit smaller.
parents 1cc509ed 522133d4
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// //
// Author: Herve Codina <herve.codina@bootlin.com> // Author: Herve Codina <herve.codina@bootlin.com>
#include <linux/cleanup.h>
#include <linux/iio/consumer.h> #include <linux/iio/consumer.h>
#include <linux/minmax.h> #include <linux/minmax.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
...@@ -131,33 +132,27 @@ static int audio_iio_aux_add_dapms(struct snd_soc_component *component, ...@@ -131,33 +132,27 @@ static int audio_iio_aux_add_dapms(struct snd_soc_component *component,
struct audio_iio_aux_chan *chan) struct audio_iio_aux_chan *chan)
{ {
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
char *output_name;
char *input_name;
char *pga_name;
int ret; int ret;
input_name = kasprintf(GFP_KERNEL, "%s IN", chan->name); /* Allocated names are not needed afterwards (duplicated in ASoC internals) */
char *input_name __free(kfree) = kasprintf(GFP_KERNEL, "%s IN", chan->name);
if (!input_name) if (!input_name)
return -ENOMEM; return -ENOMEM;
output_name = kasprintf(GFP_KERNEL, "%s OUT", chan->name); char *output_name __free(kfree) = kasprintf(GFP_KERNEL, "%s OUT", chan->name);
if (!output_name) { if (!output_name)
ret = -ENOMEM; return -ENOMEM;
goto out_free_input_name;
}
pga_name = kasprintf(GFP_KERNEL, "%s PGA", chan->name); char *pga_name __free(kfree) = kasprintf(GFP_KERNEL, "%s PGA", chan->name);
if (!pga_name) { if (!pga_name)
ret = -ENOMEM; return -ENOMEM;
goto out_free_output_name;
}
widgets[0] = SND_SOC_DAPM_INPUT(input_name); widgets[0] = SND_SOC_DAPM_INPUT(input_name);
widgets[1] = SND_SOC_DAPM_OUTPUT(output_name); widgets[1] = SND_SOC_DAPM_OUTPUT(output_name);
widgets[2] = SND_SOC_DAPM_PGA(pga_name, SND_SOC_NOPM, 0, 0, NULL, 0); widgets[2] = SND_SOC_DAPM_PGA(pga_name, SND_SOC_NOPM, 0, 0, NULL, 0);
ret = snd_soc_dapm_new_controls(dapm, widgets, 3); ret = snd_soc_dapm_new_controls(dapm, widgets, 3);
if (ret) if (ret)
goto out_free_pga_name; return ret;
routes[0].sink = pga_name; routes[0].sink = pga_name;
routes[0].control = NULL; routes[0].control = NULL;
...@@ -165,17 +160,8 @@ static int audio_iio_aux_add_dapms(struct snd_soc_component *component, ...@@ -165,17 +160,8 @@ static int audio_iio_aux_add_dapms(struct snd_soc_component *component,
routes[1].sink = output_name; routes[1].sink = output_name;
routes[1].control = NULL; routes[1].control = NULL;
routes[1].source = pga_name; routes[1].source = pga_name;
ret = snd_soc_dapm_add_routes(dapm, routes, 2);
/* Allocated names are no more needed (duplicated in ASoC internals) */
out_free_pga_name: return snd_soc_dapm_add_routes(dapm, routes, 2);
kfree(pga_name);
out_free_output_name:
kfree(output_name);
out_free_input_name:
kfree(input_name);
return ret;
} }
static int audio_iio_aux_component_probe(struct snd_soc_component *component) static int audio_iio_aux_component_probe(struct snd_soc_component *component)
...@@ -244,8 +230,6 @@ static int audio_iio_aux_probe(struct platform_device *pdev) ...@@ -244,8 +230,6 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
struct audio_iio_aux_chan *iio_aux_chan; struct audio_iio_aux_chan *iio_aux_chan;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct audio_iio_aux *iio_aux; struct audio_iio_aux *iio_aux;
const char **names;
u32 *invert_ranges;
int count; int count;
int ret; int ret;
int i; int i;
...@@ -262,22 +246,22 @@ static int audio_iio_aux_probe(struct platform_device *pdev) ...@@ -262,22 +246,22 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
iio_aux->num_chans = count; iio_aux->num_chans = count;
names = kcalloc(iio_aux->num_chans, sizeof(*names), GFP_KERNEL); const char **names __free(kfree) = kcalloc(iio_aux->num_chans,
sizeof(*names),
GFP_KERNEL);
if (!names) if (!names)
return -ENOMEM; return -ENOMEM;
invert_ranges = kcalloc(iio_aux->num_chans, sizeof(*invert_ranges), GFP_KERNEL); u32 *invert_ranges __free(kfree) = kcalloc(iio_aux->num_chans,
if (!invert_ranges) { sizeof(*invert_ranges),
ret = -ENOMEM; GFP_KERNEL);
goto out_free_names; if (!invert_ranges)
} return -ENOMEM;
ret = device_property_read_string_array(dev, "io-channel-names", ret = device_property_read_string_array(dev, "io-channel-names",
names, iio_aux->num_chans); names, iio_aux->num_chans);
if (ret < 0) { if (ret < 0)
dev_err_probe(dev, ret, "failed to read io-channel-names\n"); return dev_err_probe(dev, ret, "failed to read io-channel-names\n");
goto out_free_invert_ranges;
}
/* /*
* snd-control-invert-range is optional and can contain fewer items * snd-control-invert-range is optional and can contain fewer items
...@@ -288,10 +272,8 @@ static int audio_iio_aux_probe(struct platform_device *pdev) ...@@ -288,10 +272,8 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
count = min_t(unsigned int, count, iio_aux->num_chans); count = min_t(unsigned int, count, iio_aux->num_chans);
ret = device_property_read_u32_array(dev, "snd-control-invert-range", ret = device_property_read_u32_array(dev, "snd-control-invert-range",
invert_ranges, count); invert_ranges, count);
if (ret < 0) { if (ret < 0)
dev_err_probe(dev, ret, "failed to read snd-control-invert-range\n"); return dev_err_probe(dev, ret, "failed to read snd-control-invert-range\n");
goto out_free_invert_ranges;
}
} }
for (i = 0; i < iio_aux->num_chans; i++) { for (i = 0; i < iio_aux->num_chans; i++) {
...@@ -300,23 +282,16 @@ static int audio_iio_aux_probe(struct platform_device *pdev) ...@@ -300,23 +282,16 @@ static int audio_iio_aux_probe(struct platform_device *pdev)
iio_aux_chan->is_invert_range = invert_ranges[i]; iio_aux_chan->is_invert_range = invert_ranges[i];
iio_aux_chan->iio_chan = devm_iio_channel_get(dev, iio_aux_chan->name); iio_aux_chan->iio_chan = devm_iio_channel_get(dev, iio_aux_chan->name);
if (IS_ERR(iio_aux_chan->iio_chan)) { if (IS_ERR(iio_aux_chan->iio_chan))
ret = PTR_ERR(iio_aux_chan->iio_chan); return dev_err_probe(dev, PTR_ERR(iio_aux_chan->iio_chan),
dev_err_probe(dev, ret, "get IIO channel '%s' failed\n", "get IIO channel '%s' failed\n",
iio_aux_chan->name); iio_aux_chan->name);
goto out_free_invert_ranges;
}
} }
platform_set_drvdata(pdev, iio_aux); platform_set_drvdata(pdev, iio_aux);
ret = devm_snd_soc_register_component(dev, &audio_iio_aux_component_driver, return devm_snd_soc_register_component(dev, &audio_iio_aux_component_driver,
NULL, 0); NULL, 0);
out_free_invert_ranges:
kfree(invert_ranges);
out_free_names:
kfree(names);
return ret;
} }
static const struct of_device_id audio_iio_aux_ids[] = { static const struct of_device_id audio_iio_aux_ids[] = {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/cleanup.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/bitops.h> #include <linux/bitops.h>
...@@ -2714,25 +2715,23 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w, ...@@ -2714,25 +2715,23 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
unsigned int decimator; unsigned int decimator;
char *dec_adc_mux_name = NULL; char *dec_adc_mux_name = NULL;
char *widget_name = NULL; char *widget_name;
char *wname;
int ret = 0, amic_n; int ret = 0, amic_n;
u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg; u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
u16 tx_gain_ctl_reg; u16 tx_gain_ctl_reg;
char *dec; char *dec;
u8 hpf_coff_freq; u8 hpf_coff_freq;
widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL); char *wname __free(kfree) = kmemdup_nul(w->name, 15, GFP_KERNEL);
if (!widget_name) if (!wname)
return -ENOMEM; return -ENOMEM;
wname = widget_name; widget_name = wname;
dec_adc_mux_name = strsep(&widget_name, " "); dec_adc_mux_name = strsep(&widget_name, " ");
if (!dec_adc_mux_name) { if (!dec_adc_mux_name) {
dev_err(comp->dev, "%s: Invalid decimator = %s\n", dev_err(comp->dev, "%s: Invalid decimator = %s\n",
__func__, w->name); __func__, w->name);
ret = -EINVAL; return -EINVAL;
goto out;
} }
dec_adc_mux_name = widget_name; dec_adc_mux_name = widget_name;
...@@ -2740,16 +2739,14 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w, ...@@ -2740,16 +2739,14 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
if (!dec) { if (!dec) {
dev_err(comp->dev, "%s: decimator index not found\n", dev_err(comp->dev, "%s: decimator index not found\n",
__func__); __func__);
ret = -EINVAL; return -EINVAL;
goto out;
} }
ret = kstrtouint(dec, 10, &decimator); ret = kstrtouint(dec, 10, &decimator);
if (ret < 0) { if (ret < 0) {
dev_err(comp->dev, "%s: Invalid decimator = %s\n", dev_err(comp->dev, "%s: Invalid decimator = %s\n",
__func__, wname); __func__, wname);
ret = -EINVAL; return -EINVAL;
goto out;
} }
tx_vol_ctl_reg = WCD9335_CDC_TX0_TX_PATH_CTL + 16 * decimator; 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, ...@@ -2836,8 +2833,7 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 0x10, 0x00); snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 0x10, 0x00);
break; break;
} }
out:
kfree(wname);
return ret; return ret;
} }
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2019, Linaro Limited // Copyright (c) 2019, Linaro Limited
#include <linux/cleanup.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/clk-provider.h> #include <linux/clk-provider.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -4973,25 +4974,23 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w, ...@@ -4973,25 +4974,23 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w,
struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
unsigned int decimator; unsigned int decimator;
char *dec_adc_mux_name = NULL; char *dec_adc_mux_name = NULL;
char *widget_name = NULL; char *widget_name;
char *wname;
int ret = 0, amic_n; int ret = 0, amic_n;
u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg; u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
u16 tx_gain_ctl_reg; u16 tx_gain_ctl_reg;
char *dec; char *dec;
u8 hpf_coff_freq; u8 hpf_coff_freq;
widget_name = kstrndup(w->name, 15, GFP_KERNEL); char *wname __free(kfree) = kstrndup(w->name, 15, GFP_KERNEL);
if (!widget_name) if (!wname)
return -ENOMEM; return -ENOMEM;
wname = widget_name; widget_name = wname;
dec_adc_mux_name = strsep(&widget_name, " "); dec_adc_mux_name = strsep(&widget_name, " ");
if (!dec_adc_mux_name) { if (!dec_adc_mux_name) {
dev_err(comp->dev, "%s: Invalid decimator = %s\n", dev_err(comp->dev, "%s: Invalid decimator = %s\n",
__func__, w->name); __func__, w->name);
ret = -EINVAL; return -EINVAL;
goto out;
} }
dec_adc_mux_name = widget_name; dec_adc_mux_name = widget_name;
...@@ -4999,16 +4998,14 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w, ...@@ -4999,16 +4998,14 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w,
if (!dec) { if (!dec) {
dev_err(comp->dev, "%s: decimator index not found\n", dev_err(comp->dev, "%s: decimator index not found\n",
__func__); __func__);
ret = -EINVAL; return -EINVAL;
goto out;
} }
ret = kstrtouint(dec, 10, &decimator); ret = kstrtouint(dec, 10, &decimator);
if (ret < 0) { if (ret < 0) {
dev_err(comp->dev, "%s: Invalid decimator = %s\n", dev_err(comp->dev, "%s: Invalid decimator = %s\n",
__func__, wname); __func__, wname);
ret = -EINVAL; return -EINVAL;
goto out;
} }
tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL + 16 * decimator; 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, ...@@ -5101,8 +5098,7 @@ static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w,
WCD934X_DEC_PWR_LVL_DF); WCD934X_DEC_PWR_LVL_DF);
break; break;
} }
out:
kfree(wname);
return ret; return ret;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// //
// based on ${LINUX}/sound/soc/generic/simple-card.c // based on ${LINUX}/sound/soc/generic/simple-card.c
#include <linux/cleanup.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
...@@ -573,10 +574,9 @@ static int graph_get_dais_count(struct simple_util_priv *priv, ...@@ -573,10 +574,9 @@ static int graph_get_dais_count(struct simple_util_priv *priv,
int audio_graph_parse_of(struct simple_util_priv *priv, struct device *dev) int audio_graph_parse_of(struct simple_util_priv *priv, struct device *dev)
{ {
struct snd_soc_card *card = simple_priv_to_card(priv); struct snd_soc_card *card = simple_priv_to_card(priv);
struct link_info *li;
int ret; int ret;
li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL); struct link_info *li __free(kfree) = kzalloc(sizeof(*li), GFP_KERNEL);
if (!li) if (!li)
return -ENOMEM; return -ENOMEM;
...@@ -628,7 +628,6 @@ int audio_graph_parse_of(struct simple_util_priv *priv, struct device *dev) ...@@ -628,7 +628,6 @@ int audio_graph_parse_of(struct simple_util_priv *priv, struct device *dev)
if (ret < 0) if (ret < 0)
goto err; goto err;
devm_kfree(dev, li);
return 0; return 0;
err: err:
......
...@@ -1350,10 +1350,9 @@ int audio_graph2_parse_of(struct simple_util_priv *priv, struct device *dev, ...@@ -1350,10 +1350,9 @@ int audio_graph2_parse_of(struct simple_util_priv *priv, struct device *dev,
struct graph2_custom_hooks *hooks) struct graph2_custom_hooks *hooks)
{ {
struct snd_soc_card *card = simple_priv_to_card(priv); struct snd_soc_card *card = simple_priv_to_card(priv);
struct link_info *li;
int ret; int ret;
li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL); struct link_info *li __free(kfree) = kzalloc(sizeof(*li), GFP_KERNEL);
if (!li) if (!li)
return -ENOMEM; return -ENOMEM;
...@@ -1417,8 +1416,6 @@ int audio_graph2_parse_of(struct simple_util_priv *priv, struct device *dev, ...@@ -1417,8 +1416,6 @@ int audio_graph2_parse_of(struct simple_util_priv *priv, struct device *dev,
ret = devm_snd_soc_register_card(dev, card); ret = devm_snd_soc_register_card(dev, card);
err: err:
devm_kfree(dev, li);
if (ret < 0) if (ret < 0)
dev_err_probe(dev, ret, "parse error\n"); dev_err_probe(dev, ret, "parse error\n");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> // Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
#include <dt-bindings/sound/audio-graph.h> #include <dt-bindings/sound/audio-graph.h>
#include <linux/cleanup.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -135,8 +136,8 @@ EXPORT_SYMBOL_GPL(simple_util_parse_daifmt); ...@@ -135,8 +136,8 @@ EXPORT_SYMBOL_GPL(simple_util_parse_daifmt);
int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np, int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np,
struct simple_util_dai *dai) struct simple_util_dai *dai)
{ {
u32 *array_values, *p;
int n, i, ret; int n, i, ret;
u32 *p;
if (!of_property_read_bool(np, "dai-tdm-slot-width-map")) if (!of_property_read_bool(np, "dai-tdm-slot-width-map"))
return 0; return 0;
...@@ -151,14 +152,15 @@ int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np, ...@@ -151,14 +152,15 @@ int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np,
if (!dai->tdm_width_map) if (!dai->tdm_width_map)
return -ENOMEM; return -ENOMEM;
array_values = kcalloc(n, sizeof(*array_values), GFP_KERNEL); u32 *array_values __free(kfree) = kcalloc(n, sizeof(*array_values),
GFP_KERNEL);
if (!array_values) if (!array_values)
return -ENOMEM; return -ENOMEM;
ret = of_property_read_u32_array(np, "dai-tdm-slot-width-map", array_values, n); ret = of_property_read_u32_array(np, "dai-tdm-slot-width-map", array_values, n);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "Could not read dai-tdm-slot-width-map: %d\n", ret); dev_err(dev, "Could not read dai-tdm-slot-width-map: %d\n", ret);
goto out; return ret;
} }
p = array_values; p = array_values;
...@@ -169,11 +171,8 @@ int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np, ...@@ -169,11 +171,8 @@ int simple_util_parse_tdm_width_map(struct device *dev, struct device_node *np,
} }
dai->n_tdm_widths = i; dai->n_tdm_widths = i;
ret = 0;
out:
kfree(array_values);
return ret; return 0;
} }
EXPORT_SYMBOL_GPL(simple_util_parse_tdm_width_map); EXPORT_SYMBOL_GPL(simple_util_parse_tdm_width_map);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// Copyright (C) 2012 Renesas Solutions Corp. // Copyright (C) 2012 Renesas Solutions Corp.
// Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
#include <linux/cleanup.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -727,7 +728,6 @@ static int simple_probe(struct platform_device *pdev) ...@@ -727,7 +728,6 @@ static int simple_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct snd_soc_card *card; struct snd_soc_card *card;
struct link_info *li;
int ret; int ret;
/* Allocate the private data and the DAI link array */ /* Allocate the private data and the DAI link array */
...@@ -741,7 +741,7 @@ static int simple_probe(struct platform_device *pdev) ...@@ -741,7 +741,7 @@ static int simple_probe(struct platform_device *pdev)
card->probe = simple_soc_probe; card->probe = simple_soc_probe;
card->driver_name = "simple-card"; card->driver_name = "simple-card";
li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL); struct link_info *li __free(kfree) = kzalloc(sizeof(*li), GFP_KERNEL);
if (!li) if (!li)
return -ENOMEM; return -ENOMEM;
...@@ -818,7 +818,6 @@ static int simple_probe(struct platform_device *pdev) ...@@ -818,7 +818,6 @@ static int simple_probe(struct platform_device *pdev)
if (ret < 0) if (ret < 0)
goto err; goto err;
devm_kfree(dev, li);
return 0; return 0;
err: err:
simple_util_clean_reference(card); simple_util_clean_reference(card);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/async.h> #include <linux/async.h>
#include <linux/cleanup.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/bitops.h> #include <linux/bitops.h>
...@@ -323,9 +324,9 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget( ...@@ -323,9 +324,9 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
const struct snd_soc_dapm_widget *_widget, const struct snd_soc_dapm_widget *_widget,
const char *prefix) const char *prefix)
{ {
struct snd_soc_dapm_widget *w; struct snd_soc_dapm_widget *w __free(kfree) = kmemdup(_widget,
sizeof(*_widget),
w = kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); GFP_KERNEL);
if (!w) if (!w)
return NULL; return NULL;
...@@ -333,20 +334,18 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget( ...@@ -333,20 +334,18 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, _widget->name); w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, _widget->name);
else else
w->name = kstrdup_const(_widget->name, GFP_KERNEL); w->name = kstrdup_const(_widget->name, GFP_KERNEL);
if (!w->name) { if (!w->name)
kfree(w);
return NULL; return NULL;
}
if (_widget->sname) { if (_widget->sname) {
w->sname = kstrdup_const(_widget->sname, GFP_KERNEL); w->sname = kstrdup_const(_widget->sname, GFP_KERNEL);
if (!w->sname) { if (!w->sname) {
kfree_const(w->name); kfree_const(w->name);
kfree(w);
return NULL; return NULL;
} }
} }
return w;
return_ptr(w);
} }
struct dapm_kcontrol_data { struct dapm_kcontrol_data {
...@@ -3883,11 +3882,10 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3883,11 +3882,10 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
struct snd_soc_dapm_path *path; struct snd_soc_dapm_path *path;
struct snd_soc_dai *source, *sink; struct snd_soc_dai *source, *sink;
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_pcm_hw_params *params = NULL;
const struct snd_soc_pcm_stream *config = NULL; const struct snd_soc_pcm_stream *config = NULL;
struct snd_pcm_runtime *runtime = NULL; struct snd_pcm_runtime *runtime = NULL;
unsigned int fmt; unsigned int fmt;
int ret = 0; int ret;
/* /*
* NOTE * NOTE
...@@ -3898,15 +3896,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3898,15 +3896,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
* stuff that increases stack usage. * stuff that increases stack usage.
* So, we use kzalloc()/kfree() for params in this function. * So, we use kzalloc()/kfree() for params in this function.
*/ */
params = kzalloc(sizeof(*params), GFP_KERNEL); struct snd_pcm_hw_params *params __free(kfree) = kzalloc(sizeof(*params),
GFP_KERNEL);
if (!params) if (!params)
return -ENOMEM; return -ENOMEM;
runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
if (!runtime) { if (!runtime)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
substream->runtime = runtime; substream->runtime = runtime;
...@@ -3916,7 +3913,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3916,7 +3913,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_startup(source, substream); ret = snd_soc_dai_startup(source, substream);
if (ret < 0) if (ret < 0)
goto out; return ret;
snd_soc_dai_activate(source, substream->stream); snd_soc_dai_activate(source, substream->stream);
} }
...@@ -3927,7 +3924,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3927,7 +3924,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_startup(sink, substream); ret = snd_soc_dai_startup(sink, substream);
if (ret < 0) if (ret < 0)
goto out; return ret;
snd_soc_dai_activate(sink, substream->stream); snd_soc_dai_activate(sink, substream->stream);
} }
...@@ -3942,16 +3939,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3942,16 +3939,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
config = rtd->dai_link->c2c_params + rtd->c2c_params_select; config = rtd->dai_link->c2c_params + rtd->c2c_params_select;
if (!config) { if (!config) {
dev_err(w->dapm->dev, "ASoC: link config missing\n"); dev_err(w->dapm->dev, "ASoC: link config missing\n");
ret = -EINVAL; return -EINVAL;
goto out;
} }
/* Be a little careful as we don't want to overflow the mask array */ /* Be a little careful as we don't want to overflow the mask array */
if (!config->formats) { if (!config->formats) {
dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n"); dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n");
ret = -EINVAL; return -EINVAL;
goto out;
} }
fmt = ffs(config->formats) - 1; fmt = ffs(config->formats) - 1;
...@@ -3972,7 +3967,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3972,7 +3967,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_hw_params(source, substream, params); ret = snd_soc_dai_hw_params(source, substream, params);
if (ret < 0) if (ret < 0)
goto out; return ret;
dapm_update_dai_unlocked(substream, params, source); dapm_update_dai_unlocked(substream, params, source);
} }
...@@ -3983,7 +3978,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3983,7 +3978,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_hw_params(sink, substream, params); ret = snd_soc_dai_hw_params(sink, substream, params);
if (ret < 0) if (ret < 0)
goto out; return ret;
dapm_update_dai_unlocked(substream, params, sink); dapm_update_dai_unlocked(substream, params, sink);
} }
...@@ -3993,11 +3988,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3993,11 +3988,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
runtime->channels = params_channels(params); runtime->channels = params_channels(params);
runtime->rate = params_rate(params); runtime->rate = params_rate(params);
out: return 0;
/* see above NOTE */
kfree(params);
return ret;
} }
static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
// with code, comments and ideas from :- // with code, comments and ideas from :-
// Richard Purdie <richard@openedhand.com> // Richard Purdie <richard@openedhand.com>
#include <linux/cleanup.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -727,14 +728,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -727,14 +728,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
struct soc_bytes *params = (void *)kcontrol->private_value; struct soc_bytes *params = (void *)kcontrol->private_value;
int ret, len; int ret, len;
unsigned int val, mask; unsigned int val, mask;
void *data;
if (!component->regmap || !params->num_regs) if (!component->regmap || !params->num_regs)
return -EINVAL; return -EINVAL;
len = params->num_regs * component->val_bytes; len = params->num_regs * component->val_bytes;
data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); void *data __free(kfree) = kmemdup(ucontrol->value.bytes.data, len,
GFP_KERNEL | GFP_DMA);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
...@@ -746,7 +747,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -746,7 +747,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
if (params->mask) { if (params->mask) {
ret = regmap_read(component->regmap, params->base, &val); ret = regmap_read(component->regmap, params->base, &val);
if (ret != 0) if (ret != 0)
goto out; return ret;
val &= params->mask; val &= params->mask;
...@@ -760,14 +761,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -760,14 +761,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&mask, &mask); &mask, &mask);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u16 *)data)[0] &= mask; ((u16 *)data)[0] &= mask;
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&val, &val); &val, &val);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u16 *)data)[0] |= val; ((u16 *)data)[0] |= val;
break; break;
...@@ -776,30 +777,23 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -776,30 +777,23 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&mask, &mask); &mask, &mask);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u32 *)data)[0] &= mask; ((u32 *)data)[0] &= mask;
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&val, &val); &val, &val);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u32 *)data)[0] |= val; ((u32 *)data)[0] |= val;
break; break;
default: default:
ret = -EINVAL; return -EINVAL;
goto out;
} }
} }
ret = regmap_raw_write(component->regmap, params->base, return regmap_raw_write(component->regmap, params->base, data, len);
data, len);
out:
kfree(data);
return ret;
} }
EXPORT_SYMBOL_GPL(snd_soc_bytes_put); EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment