From nobody Thu May 7 19:51:08 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 6FBB5C433FE for ; Thu, 19 May 2022 22:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233817AbiESWcD (ORCPT ); Thu, 19 May 2022 18:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245475AbiESWb7 (ORCPT ); Thu, 19 May 2022 18:31:59 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23256B2278 for ; Thu, 19 May 2022 15:31:58 -0700 (PDT) Received: from hednb3.Dlink (unknown [109.252.138.248]) by mail.ispras.ru (Postfix) with ESMTPSA id C7E0C40755E1; Thu, 19 May 2022 22:31:47 +0000 (UTC) From: Alexey Khoroshilov To: Liam Girdwood , Mark Brown Cc: Alexey Khoroshilov , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] ASoC: max98090: Move check for invalid values before casting in max98090_put_enab_tlv() Date: Fri, 20 May 2022 01:31:26 +0300 Message-Id: <1652999486-29653-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Validation of signed input should be done before casting to unsigned int. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Alexey Khoroshilov Suggested-by: Mark Brown Fixes: 2fbe467bcbfc ("ASoC: max98090: Reject invalid values in custom contr= ol put()") --- sound/soc/codecs/max98090.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index 62b41ca050a2..5513acd360b8 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c @@ -393,7 +393,8 @@ static int max98090_put_enab_tlv(struct snd_kcontrol *k= control, struct soc_mixer_control *mc =3D (struct soc_mixer_control *)kcontrol->private_value; unsigned int mask =3D (1 << fls(mc->max)) - 1; - unsigned int sel =3D ucontrol->value.integer.value[0]; + int sel_unchecked =3D ucontrol->value.integer.value[0]; + unsigned int sel; unsigned int val =3D snd_soc_component_read(component, mc->reg); unsigned int *select; =20 @@ -413,8 +414,9 @@ static int max98090_put_enab_tlv(struct snd_kcontrol *k= control, =20 val =3D (val >> mc->shift) & mask; =20 - if (sel < 0 || sel > mc->max) + if (sel_unchecked < 0 || sel_unchecked > mc->max) return -EINVAL; + sel =3D sel_unchecked; =20 *select =3D sel; =20 --=20 2.7.4