Skip to content

Commit 5628560

Browse files
tiwaibroonie
authored andcommitted
ASoC: nau8824: Fix semaphore unbalance at error paths
The semaphore of nau8824 wasn't properly unlocked at some error handling code paths, hence this may result in the unbalance (and potential lock-up). Fix them to handle the semaphore up properly. Signed-off-by: Takashi Iwai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent cf50718 commit 5628560

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

sound/soc/codecs/nau8824.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
10431043
struct snd_soc_component *component = dai->component;
10441044
struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component);
10451045
unsigned int val_len = 0, osr, ctrl_val, bclk_fs, bclk_div;
1046+
int err = -EINVAL;
10461047

10471048
nau8824_sema_acquire(nau8824, HZ);
10481049

@@ -1059,7 +1060,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
10591060
osr &= NAU8824_DAC_OVERSAMPLE_MASK;
10601061
if (nau8824_clock_check(nau8824, substream->stream,
10611062
nau8824->fs, osr))
1062-
return -EINVAL;
1063+
goto error;
10631064
regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER,
10641065
NAU8824_CLK_DAC_SRC_MASK,
10651066
osr_dac_sel[osr].clk_src << NAU8824_CLK_DAC_SRC_SFT);
@@ -1069,7 +1070,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
10691070
osr &= NAU8824_ADC_SYNC_DOWN_MASK;
10701071
if (nau8824_clock_check(nau8824, substream->stream,
10711072
nau8824->fs, osr))
1072-
return -EINVAL;
1073+
goto error;
10731074
regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER,
10741075
NAU8824_CLK_ADC_SRC_MASK,
10751076
osr_adc_sel[osr].clk_src << NAU8824_CLK_ADC_SRC_SFT);
@@ -1090,7 +1091,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
10901091
else if (bclk_fs <= 256)
10911092
bclk_div = 0;
10921093
else
1093-
return -EINVAL;
1094+
goto error;
10941095
regmap_update_bits(nau8824->regmap,
10951096
NAU8824_REG_PORT0_I2S_PCM_CTRL_2,
10961097
NAU8824_I2S_LRC_DIV_MASK | NAU8824_I2S_BLK_DIV_MASK,
@@ -1111,15 +1112,17 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
11111112
val_len |= NAU8824_I2S_DL_32;
11121113
break;
11131114
default:
1114-
return -EINVAL;
1115+
goto error;
11151116
}
11161117

11171118
regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1,
11181119
NAU8824_I2S_DL_MASK, val_len);
1120+
err = 0;
11191121

1122+
error:
11201123
nau8824_sema_release(nau8824);
11211124

1122-
return 0;
1125+
return err;
11231126
}
11241127

11251128
static int nau8824_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
@@ -1128,8 +1131,6 @@ static int nau8824_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
11281131
struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component);
11291132
unsigned int ctrl1_val = 0, ctrl2_val = 0;
11301133

1131-
nau8824_sema_acquire(nau8824, HZ);
1132-
11331134
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
11341135
case SND_SOC_DAIFMT_CBM_CFM:
11351136
ctrl2_val |= NAU8824_I2S_MS_MASTER;
@@ -1171,6 +1172,8 @@ static int nau8824_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
11711172
return -EINVAL;
11721173
}
11731174

1175+
nau8824_sema_acquire(nau8824, HZ);
1176+
11741177
regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1,
11751178
NAU8824_I2S_DF_MASK | NAU8824_I2S_BP_MASK |
11761179
NAU8824_I2S_PCMB_EN, ctrl1_val);

0 commit comments

Comments
 (0)