[alsa-devel] [PATCH 1/2] ASoC: rt5514: Fix the issue that the variable dereferenced before checking
The patch fixes the issue that variable dereferenced before checking 'rt5514_dsp->substream'. Move the assignment to after the variable checking of 'rt5514_dsp->substream'.
Signed-off-by: Oder Chiou oder_chiou@realtek.com --- sound/soc/codecs/rt5514-spi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index 8a9382e..743f509 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -80,7 +80,7 @@ static void rt5514_spi_copy_work(struct work_struct *work) { struct rt5514_dsp *rt5514_dsp = container_of(work, struct rt5514_dsp, copy_work.work); - struct snd_pcm_runtime *runtime = rt5514_dsp->substream->runtime; + struct snd_pcm_runtime *runtime; size_t period_bytes, truncated_bytes = 0;
mutex_lock(&rt5514_dsp->dma_lock); @@ -89,6 +89,7 @@ static void rt5514_spi_copy_work(struct work_struct *work) goto done; }
+ runtime = rt5514_dsp->substream->runtime; period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream);
if (rt5514_dsp->buf_size - rt5514_dsp->dsp_offset < period_bytes)
The patch adds the control of MCLK that depends on the status of DAPM.
Signed-off-by: Oder Chiou oder_chiou@realtek.com --- Documentation/devicetree/bindings/sound/rt5514.txt | 5 ++++ sound/soc/codecs/rt5514.c | 32 ++++++++++++++++++++++ sound/soc/codecs/rt5514.h | 3 ++ 3 files changed, 40 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/rt5514.txt b/Documentation/devicetree/bindings/sound/rt5514.txt index e24436f..9cabfc1 100644 --- a/Documentation/devicetree/bindings/sound/rt5514.txt +++ b/Documentation/devicetree/bindings/sound/rt5514.txt @@ -8,6 +8,11 @@ Required properties:
- reg : The I2C address of the device.
+Optional properties: + +- clocks: The phandle of the master clock to the CODEC +- clock-names: Should be "mclk" + Pins on the device (for linking into audio routes) for RT5514:
* DMIC1L diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index ecb0989..7162f05 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -932,10 +932,41 @@ static int rt5514_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, return 0; }
+static int rt5514_set_bias_level(struct snd_soc_codec *codec, + enum snd_soc_bias_level level) +{ + struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + int ret; + + switch (level) { + case SND_SOC_BIAS_PREPARE: + if (IS_ERR(rt5514->mclk)) + break; + + if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) { + clk_disable_unprepare(rt5514->mclk); + } else { + ret = clk_prepare_enable(rt5514->mclk); + if (ret) + return ret; + } + break; + + default: + break; + } + + return 0; +} + static int rt5514_probe(struct snd_soc_codec *codec) { struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec);
+ rt5514->mclk = devm_clk_get(codec->dev, "mclk"); + if (PTR_ERR(rt5514->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + rt5514->codec = codec;
return 0; @@ -991,6 +1022,7 @@ struct snd_soc_dai_driver rt5514_dai[] = { static struct snd_soc_codec_driver soc_codec_dev_rt5514 = { .probe = rt5514_probe, .idle_bias_off = true, + .set_bias_level = rt5514_set_bias_level, .controls = rt5514_snd_controls, .num_controls = ARRAY_SIZE(rt5514_snd_controls), .dapm_widgets = rt5514_dapm_widgets, diff --git a/sound/soc/codecs/rt5514.h b/sound/soc/codecs/rt5514.h index 6e89e7d..68883c6 100644 --- a/sound/soc/codecs/rt5514.h +++ b/sound/soc/codecs/rt5514.h @@ -12,6 +12,8 @@ #ifndef __RT5514_H__ #define __RT5514_H__
+#include <linux/clk.h> + #define RT5514_DEVICE_ID 0x10ec5514
#define RT5514_RESET 0x2000 @@ -243,6 +245,7 @@ enum { struct rt5514_priv { struct snd_soc_codec *codec; struct regmap *i2c_regmap, *regmap; + struct clk *mclk; int sysclk; int sysclk_src; int lrck;
The patch
ASoC: rt5514: Add the MCLK handling
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From c9506bb84b62917ae88087545ccb756d35655397 Mon Sep 17 00:00:00 2001
From: Oder Chiou oder_chiou@realtek.com Date: Fri, 17 Jun 2016 11:02:24 +0800 Subject: [PATCH] ASoC: rt5514: Add the MCLK handling
The patch adds the control of MCLK that depends on the status of DAPM.
Signed-off-by: Oder Chiou oder_chiou@realtek.com Signed-off-by: Mark Brown broonie@kernel.org --- Documentation/devicetree/bindings/sound/rt5514.txt | 5 ++++ sound/soc/codecs/rt5514.c | 32 ++++++++++++++++++++++ sound/soc/codecs/rt5514.h | 3 ++ 3 files changed, 40 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/rt5514.txt b/Documentation/devicetree/bindings/sound/rt5514.txt index e24436fc5ea9..9cabfc18cb57 100644 --- a/Documentation/devicetree/bindings/sound/rt5514.txt +++ b/Documentation/devicetree/bindings/sound/rt5514.txt @@ -8,6 +8,11 @@ Required properties:
- reg : The I2C address of the device.
+Optional properties: + +- clocks: The phandle of the master clock to the CODEC +- clock-names: Should be "mclk" + Pins on the device (for linking into audio routes) for RT5514:
* DMIC1L diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 879bf60f4965..e6ae2309e5f8 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -799,10 +799,41 @@ static int rt5514_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, return 0; }
+static int rt5514_set_bias_level(struct snd_soc_codec *codec, + enum snd_soc_bias_level level) +{ + struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + int ret; + + switch (level) { + case SND_SOC_BIAS_PREPARE: + if (IS_ERR(rt5514->mclk)) + break; + + if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) { + clk_disable_unprepare(rt5514->mclk); + } else { + ret = clk_prepare_enable(rt5514->mclk); + if (ret) + return ret; + } + break; + + default: + break; + } + + return 0; +} + static int rt5514_probe(struct snd_soc_codec *codec) { struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec);
+ rt5514->mclk = devm_clk_get(codec->dev, "mclk"); + if (PTR_ERR(rt5514->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + rt5514->codec = codec;
return 0; @@ -858,6 +889,7 @@ struct snd_soc_dai_driver rt5514_dai[] = { static struct snd_soc_codec_driver soc_codec_dev_rt5514 = { .probe = rt5514_probe, .idle_bias_off = true, + .set_bias_level = rt5514_set_bias_level, .controls = rt5514_snd_controls, .num_controls = ARRAY_SIZE(rt5514_snd_controls), .dapm_widgets = rt5514_dapm_widgets, diff --git a/sound/soc/codecs/rt5514.h b/sound/soc/codecs/rt5514.h index 6ad8a612f659..766f5a666ebe 100644 --- a/sound/soc/codecs/rt5514.h +++ b/sound/soc/codecs/rt5514.h @@ -12,6 +12,8 @@ #ifndef __RT5514_H__ #define __RT5514_H__
+#include <linux/clk.h> + #define RT5514_DEVICE_ID 0x10ec5514
#define RT5514_RESET 0x2000 @@ -240,6 +242,7 @@ enum { struct rt5514_priv { struct snd_soc_codec *codec; struct regmap *i2c_regmap, *regmap; + struct clk *mclk; int sysclk; int sysclk_src; int lrck;
The patch
ASoC: rt5514: Fix the issue that the variable dereferenced before checking
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From b63d4d13ac7b8f947407a7eb44fdc40fadc8c5b8 Mon Sep 17 00:00:00 2001
From: Oder Chiou oder_chiou@realtek.com Date: Fri, 17 Jun 2016 11:02:23 +0800 Subject: [PATCH] ASoC: rt5514: Fix the issue that the variable dereferenced before checking
The patch fixes the issue that variable dereferenced before checking 'rt5514_dsp->substream'. Move the assignment to after the variable checking of 'rt5514_dsp->substream'.
Signed-off-by: Oder Chiou oder_chiou@realtek.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/codecs/rt5514-spi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index 8a9382e9787a..743f509d48b7 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -80,7 +80,7 @@ static void rt5514_spi_copy_work(struct work_struct *work) { struct rt5514_dsp *rt5514_dsp = container_of(work, struct rt5514_dsp, copy_work.work); - struct snd_pcm_runtime *runtime = rt5514_dsp->substream->runtime; + struct snd_pcm_runtime *runtime; size_t period_bytes, truncated_bytes = 0;
mutex_lock(&rt5514_dsp->dma_lock); @@ -89,6 +89,7 @@ static void rt5514_spi_copy_work(struct work_struct *work) goto done; }
+ runtime = rt5514_dsp->substream->runtime; period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream);
if (rt5514_dsp->buf_size - rt5514_dsp->dsp_offset < period_bytes)
participants (2)
-
Mark Brown
-
Oder Chiou