From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liam Girdwood Subject: Re: [PATCH] ASoC: Fix overflow bug in SOC_DOUBLE_R_SX_TLV Date: Fri, 18 Jun 2010 11:29:24 +0100 Message-ID: <1276856964.3054.1.camel@odin> References: <20100618023810.GS7759@www.longlandclan.yi.org> <1276829770-31557-1-git-send-email-redhatter@gentoo.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-ww0-f51.google.com (mail-ww0-f51.google.com [74.125.82.51]) by alsa0.perex.cz (Postfix) with ESMTP id 4E3E524534 for ; Fri, 18 Jun 2010 12:29:29 +0200 (CEST) Received: by wwf26 with SMTP id 26so324399wwf.38 for ; Fri, 18 Jun 2010 03:29:26 -0700 (PDT) In-Reply-To: <1276829770-31557-1-git-send-email-redhatter@gentoo.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Stuart Longland Cc: Takashi Iwai , ALSA Development List , Mark Brown , Linux Kernel , Linux ARM Kernel List-Id: alsa-devel@alsa-project.org On Fri, 2010-06-18 at 12:56 +1000, Stuart Longland wrote: > When SX_TLV widgets are read, if the gain is set to a value below 0dB, > the mixer control is erroniously read as being at maximum volume. > > The value read out of the CODEC register is never sign-extended, and > when the minimum value is subtracted (read; added, since the minimum is > negative) the result is a number greater than the maximum allowed value > for the control, and hence it saturates. > > Solution: Mask the result so that it "wraps around", emulating > sign-extension. > > Signed-off-by: Stuart Longland > --- > sound/soc/soc-core.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c > index a82a797..0470288 100644 > --- a/sound/soc/soc-core.c > +++ b/sound/soc/soc-core.c > @@ -2400,8 +2400,8 @@ int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, > int val = snd_soc_read(codec, mc->reg) & mask; > int valr = snd_soc_read(codec, mc->rreg) & mask; > > - ucontrol->value.integer.value[0] = ((val & 0xff)-min); > - ucontrol->value.integer.value[1] = ((valr & 0xff)-min); > + ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; > + ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; > return 0; > } > EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); Acked-by: Liam Girdwood -- Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk From mboxrd@z Thu Jan 1 00:00:00 1970 From: lrg@slimlogic.co.uk (Liam Girdwood) Date: Fri, 18 Jun 2010 11:29:24 +0100 Subject: [PATCH] ASoC: Fix overflow bug in SOC_DOUBLE_R_SX_TLV In-Reply-To: <1276829770-31557-1-git-send-email-redhatter@gentoo.org> References: <20100618023810.GS7759@www.longlandclan.yi.org> <1276829770-31557-1-git-send-email-redhatter@gentoo.org> Message-ID: <1276856964.3054.1.camel@odin> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Fri, 2010-06-18 at 12:56 +1000, Stuart Longland wrote: > When SX_TLV widgets are read, if the gain is set to a value below 0dB, > the mixer control is erroniously read as being at maximum volume. > > The value read out of the CODEC register is never sign-extended, and > when the minimum value is subtracted (read; added, since the minimum is > negative) the result is a number greater than the maximum allowed value > for the control, and hence it saturates. > > Solution: Mask the result so that it "wraps around", emulating > sign-extension. > > Signed-off-by: Stuart Longland > --- > sound/soc/soc-core.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c > index a82a797..0470288 100644 > --- a/sound/soc/soc-core.c > +++ b/sound/soc/soc-core.c > @@ -2400,8 +2400,8 @@ int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, > int val = snd_soc_read(codec, mc->reg) & mask; > int valr = snd_soc_read(codec, mc->rreg) & mask; > > - ucontrol->value.integer.value[0] = ((val & 0xff)-min); > - ucontrol->value.integer.value[1] = ((valr & 0xff)-min); > + ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; > + ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; > return 0; > } > EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); Acked-by: Liam Girdwood -- Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760245Ab0FRK33 (ORCPT ); Fri, 18 Jun 2010 06:29:29 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:52933 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759218Ab0FRK31 (ORCPT ); Fri, 18 Jun 2010 06:29:27 -0400 Subject: Re: [PATCH] ASoC: Fix overflow bug in SOC_DOUBLE_R_SX_TLV From: Liam Girdwood To: Stuart Longland Cc: ALSA Development List , Takashi Iwai , Mark Brown , Linux ARM Kernel , Linux Kernel In-Reply-To: <1276829770-31557-1-git-send-email-redhatter@gentoo.org> References: <20100618023810.GS7759@www.longlandclan.yi.org> <1276829770-31557-1-git-send-email-redhatter@gentoo.org> Content-Type: text/plain; charset="UTF-8" Date: Fri, 18 Jun 2010 11:29:24 +0100 Message-ID: <1276856964.3054.1.camel@odin> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2010-06-18 at 12:56 +1000, Stuart Longland wrote: > When SX_TLV widgets are read, if the gain is set to a value below 0dB, > the mixer control is erroniously read as being at maximum volume. > > The value read out of the CODEC register is never sign-extended, and > when the minimum value is subtracted (read; added, since the minimum is > negative) the result is a number greater than the maximum allowed value > for the control, and hence it saturates. > > Solution: Mask the result so that it "wraps around", emulating > sign-extension. > > Signed-off-by: Stuart Longland > --- > sound/soc/soc-core.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c > index a82a797..0470288 100644 > --- a/sound/soc/soc-core.c > +++ b/sound/soc/soc-core.c > @@ -2400,8 +2400,8 @@ int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, > int val = snd_soc_read(codec, mc->reg) & mask; > int valr = snd_soc_read(codec, mc->rreg) & mask; > > - ucontrol->value.integer.value[0] = ((val & 0xff)-min); > - ucontrol->value.integer.value[1] = ((valr & 0xff)-min); > + ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; > + ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; > return 0; > } > EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); Acked-by: Liam Girdwood -- Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk