From nobody Thu Apr 2 19:56:23 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95ACAC6FA82 for ; Wed, 21 Sep 2022 15:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231996AbiIUP6B (ORCPT ); Wed, 21 Sep 2022 11:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231978AbiIUP5R (ORCPT ); Wed, 21 Sep 2022 11:57:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55BBC9F8E9; Wed, 21 Sep 2022 08:51:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 964996312C; Wed, 21 Sep 2022 15:50:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7480C433D6; Wed, 21 Sep 2022 15:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663775417; bh=utFwHIqJdYZ7qhbyZT96a3UYn3/Usc38/MsqpTLwb2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xmNhUkFehN27v8nbhg47zFrhDZo0WrC05cCv8nHu8vqN7prraBqQxw7MyB/z+jv+j yyHhDvc5YiwoJ3V3cgQf0zcvTslo64l2pU34BXN+SyAo5E2B0804S1902dNoMpstWi HxS6KaOmR7zMr8TI9Plfzc28eqw5b7O2GhOF3cFM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Mark Brown , Sasha Levin Subject: [PATCH 5.15 28/45] ASoC: nau8824: Fix semaphore unbalance at error paths Date: Wed, 21 Sep 2022 17:46:18 +0200 Message-Id: <20220921153647.820249439@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220921153646.931277075@linuxfoundation.org> References: <20220921153646.931277075@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Takashi Iwai [ Upstream commit 5628560e90395d3812800a8e44a01c32ffa429ec ] 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 Link: https://lore.kernel.org/r/20220823081000.2965-3-tiwai@suse.de Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/codecs/nau8824.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sound/soc/codecs/nau8824.c b/sound/soc/codecs/nau8824.c index f7018f2dd21f..27589900f4fb 100644 --- a/sound/soc/codecs/nau8824.c +++ b/sound/soc/codecs/nau8824.c @@ -1042,6 +1042,7 @@ static int nau8824_hw_params(struct snd_pcm_substream= *substream, struct snd_soc_component *component =3D dai->component; struct nau8824 *nau8824 =3D snd_soc_component_get_drvdata(component); unsigned int val_len =3D 0, osr, ctrl_val, bclk_fs, bclk_div; + int err =3D -EINVAL; =20 nau8824_sema_acquire(nau8824, HZ); =20 @@ -1058,7 +1059,7 @@ static int nau8824_hw_params(struct snd_pcm_substream= *substream, osr &=3D NAU8824_DAC_OVERSAMPLE_MASK; if (nau8824_clock_check(nau8824, substream->stream, nau8824->fs, osr)) - return -EINVAL; + goto error; regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, NAU8824_CLK_DAC_SRC_MASK, osr_dac_sel[osr].clk_src << NAU8824_CLK_DAC_SRC_SFT); @@ -1068,7 +1069,7 @@ static int nau8824_hw_params(struct snd_pcm_substream= *substream, osr &=3D NAU8824_ADC_SYNC_DOWN_MASK; if (nau8824_clock_check(nau8824, substream->stream, nau8824->fs, osr)) - return -EINVAL; + goto error; regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, NAU8824_CLK_ADC_SRC_MASK, osr_adc_sel[osr].clk_src << NAU8824_CLK_ADC_SRC_SFT); @@ -1089,7 +1090,7 @@ static int nau8824_hw_params(struct snd_pcm_substream= *substream, else if (bclk_fs <=3D 256) bclk_div =3D 0; else - return -EINVAL; + goto error; regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_2, NAU8824_I2S_LRC_DIV_MASK | NAU8824_I2S_BLK_DIV_MASK, @@ -1110,15 +1111,17 @@ static int nau8824_hw_params(struct snd_pcm_substre= am *substream, val_len |=3D NAU8824_I2S_DL_32; break; default: - return -EINVAL; + goto error; } =20 regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1, NAU8824_I2S_DL_MASK, val_len); + err =3D 0; =20 + error: nau8824_sema_release(nau8824); =20 - return 0; + return err; } =20 static int nau8824_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) @@ -1127,8 +1130,6 @@ static int nau8824_set_fmt(struct snd_soc_dai *dai, u= nsigned int fmt) struct nau8824 *nau8824 =3D snd_soc_component_get_drvdata(component); unsigned int ctrl1_val =3D 0, ctrl2_val =3D 0; =20 - nau8824_sema_acquire(nau8824, HZ); - switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM: ctrl2_val |=3D NAU8824_I2S_MS_MASTER; @@ -1170,6 +1171,8 @@ static int nau8824_set_fmt(struct snd_soc_dai *dai, u= nsigned int fmt) return -EINVAL; } =20 + nau8824_sema_acquire(nau8824, HZ); + regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1, NAU8824_I2S_DF_MASK | NAU8824_I2S_BP_MASK | NAU8824_I2S_PCMB_EN, ctrl1_val); --=20 2.35.1