Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8967272rwb; Thu, 24 Nov 2022 06:31:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6xdixp8I868xFSLoI5IXco4rhFCRDaAcPgqkym6WDjcP48o7OjbScNa3E1hOAiK4DxyoZP X-Received: by 2002:a05:6402:5299:b0:461:7291:79c1 with SMTP id en25-20020a056402529900b00461729179c1mr20959389edb.68.1669300263597; Thu, 24 Nov 2022 06:31:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669300263; cv=none; d=google.com; s=arc-20160816; b=i2YB0+mOooyaNYUNEfkTlMxJimarh6iQcsNcvSAZF6k8NFcHr1FkizMztHtJd3LsdM nTW+q2ROj7z1p8hBYLsxA5ZRTllIpNSFeCDho4UuKz9LACYQZXTqpLpvBy+MWbAmUst0 qH+Qfus3dTeKCehMNxkx45gr+gOLjynYY+XgZ6tRXYqKy0o4Jd9MqLmELVOdFpkVWewC pFlYj8L0RlRKdxnD+JdFsapRkdYAntnEZBmqG3PCEsk0VigvkSjDYOBhRxKrAYlitSMu vsROtiNIixm6Pq3rPR9yyd2xyM/h8SnPQk/Wz/GbM3H6Mpx8UsWzcgQCFpJC+vjjgD3Z rPHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=d19VZe73RsPQWbRMrRH216S4FHkhXapc6P3i52jmtAc=; b=N0C8A0Ht8sB+9PoQ+nZ4wAtrXPMAylcKsb2rPSeGGU/d6ISoHdZ111iJPKdkMGVOU6 8cwZiDGr0MROVQAs2TV0xQgVIC/4R9Bg3k03LBGR2ntZwNK2qRYxIa3i/TYWmJv3AXAB SL1wRM3pF7mXMfnjqq/Oz37ZUEwxcO15p8k3UQZqNARqPEWhUcgWEqRsHAwHrl67BxjM iKsA2S6jYqFwbPwpITjb0GhdmDkoRln2eaSCa0v0X908WlfN8RY2ZZl7uP7Z0K4fq4bp eUOYmlmqt4s3U7ubI5pnp35xHEy+RAI7/8s6g3Qd7ElNvWkQFsa3J6f/Uw5Xo6sgxbXY SgIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iHQdDPV0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa4-20020a1709076d0400b007ae100a7255si992144ejc.709.2022.11.24.06.30.41; Thu, 24 Nov 2022 06:31:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iHQdDPV0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbiKXNy3 (ORCPT + 86 others); Thu, 24 Nov 2022 08:54:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229739AbiKXNy2 (ORCPT ); Thu, 24 Nov 2022 08:54:28 -0500 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20F92E0DC0 for ; Thu, 24 Nov 2022 05:54:27 -0800 (PST) Received: by mail-yb1-xb29.google.com with SMTP id j196so1901846ybj.2 for ; Thu, 24 Nov 2022 05:54:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=d19VZe73RsPQWbRMrRH216S4FHkhXapc6P3i52jmtAc=; b=iHQdDPV0ac4BN0lr3UIcdo0l9o8IvC/T2aKWTM3N//are1c4pniWRMI9Wq7uw6zp35 irIz6Dzc+GGvWaUfq63UjjORdGQMOPbPvKsIBzQXhokJiz7rA9TLFYovwQh2ZvYN6cFz 7wYilt3BDqwAQn0wfaBdOGxLeI1vYWC/g8awjJgO1jaHNVtaZ9iiUNL8GHloaCxl7EMO zAu9uDM0LZfTkBSoKPOiI+tzfrH77UwF0n8b2JYeupK3X/ULL7TkvPtylxXSuaj8Zq5S bLlFJaQoXVctBwxN5UcG1t/Pnjtyj5GUv7fj8Z11a2xiM1qhukgu2smV3qeOQEWbw5QS ltLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d19VZe73RsPQWbRMrRH216S4FHkhXapc6P3i52jmtAc=; b=4ROpMzs/hzmYNpYS5m8rMl3HN4beGaR/1rQLE4A1/DmLPHb1CrhYRfBDyfH3YX/QUm lc4fCXvQICEnYBJtWFbFhhNbZLWjc3Fx3tDkIJsMFgfbnRsaH6RDVNpz/4JtP1RMwcfe wXlE4i/guOcgpkX69HC/5GTZOIgf3qpn7pQPXhCcLf//jd1T4lXd8EOH5h231e6i8kfu HbqpI9lDGLE2sALKqyEBYxT4aYzC3BEQcYvq5mbGQMhhzJUuG2dNwqcpXX8s4utiBkJx FMcIQZWdn6iCk3pu8wg8CXqP1HBxFjJVaNIeBugcl1SfR8L+znyGHmr2FCmWE94QvWBZ 1Btg== X-Gm-Message-State: ANoB5pnToMGEGdSqhO17/iVSj0jxJqIThp0YLtV1tlvoq2FJMRRDfU5I 0bIfhVmg29rjmCrGoq00dTjGTm3e2vEQkz58C5k= X-Received: by 2002:a05:6902:192:b0:6ef:3e1d:9054 with SMTP id t18-20020a056902019200b006ef3e1d9054mr9549191ybh.48.1669298066226; Thu, 24 Nov 2022 05:54:26 -0800 (PST) MIME-Version: 1.0 References: <20221124111336.GE105268@ediswmail.ad.cirrus.com> In-Reply-To: <20221124111336.GE105268@ediswmail.ad.cirrus.com> From: Guillermo Rodriguez Garcia Date: Thu, 24 Nov 2022 14:54:15 +0100 Message-ID: Subject: Re: SOC_DOUBLE_R_SX_TLV controls broken in cs24l51 driver To: Charles Keepax Cc: linux-kernel@vger.kernel.org, =?UTF-8?Q?Tan_Nay=C4=B1r?= , Srinivas Kandagatla , Banajit Goswami , Richard Fitzgerald , Lucas Tanure , David Rhodes , James Schulman , patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Mark Brown Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org El jue, 24 nov 2022 a las 12:13, Charles Keepax () escribi=C3=B3: > > On Thu, Nov 24, 2022 at 10:57:34AM +0100, Guillermo Rodriguez Garcia wrot= e: > > Hi all, > > > > I am using a dev board with a Cirrus Logic cs24l51 codec. > > > > This used to work fine prior to kernel version 5.x, however after 5.x > > it is not possible to set certain values for ALSA controls from > > userspace. > > > > I believe this is related to the input validation that is mentioned in > > this thread: https://lore.kernel.org/all/Yph8C3bRxcr6ogW7@sirena.org.uk= /T/, > > and possibly in this commit: 4f1e50d6a9cf9c1b8c859d449b5031cacfa8404e > > ("ASoC: ops: Reject out of bounds values in snd_soc_put_volsw_sx()") > > > > For the cs24l51, all the controls that fail are using the > > SOC_DOUBLE_R_SX_TLV macro. > > > > I have traced this to the checks in snd_soc_put_volsw_sx, specifically > > the (val > max - min) check: > > > > Can you try these two patches: > > https://lore.kernel.org/all/165236477046.1016627.15470197691244479154.b4-= ty@kernel.org/ Thanks. In my tests, these patches seem to fix the problem for some values, but not for all of them: $ amixer cset name=3D'Analog Playback Volume' '208','208' numid=3D3,iface=3DMIXER,name=3D'Analog Playback Volume' ; type=3DINTEGER,access=3Drw---R--,values=3D2,min=3D0,max=3D228,step=3D0 : values=3D208,208 | dBscale-min=3D-102.00dB,step=3D0.50dB,mute=3D0 $ amixer cset name=3D'Analog Playback Volume' '180','180' amixer: Control default element write error: Invalid argument Looking at the code I'd say that patch 1/2 is correct however I have doubts about patch 2/2: val_mask =3D mask << rshift; val2 =3D (ucontrol->value.integer.value[1] + min) & mask; + + if (mc->platform_max && val2 > mc->platform_max) + return -EINVAL; + if (val2 > max) + return -EINVAL; + val2 =3D val2 << rshift; err =3D snd_soc_component_update_bits(component, reg2, val_mask, The checks for max and platform_max are done on val2, but val2 is already the result of adding the minimum value ('min') and applying the mask. Shouldn't the checks be done on ucontrol->value.integer.value[1] instead? Thanks, Guillermo Rodriguez Garcia guille.rodriguez@gmail.com