Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8643988rwb; Thu, 24 Nov 2022 02:18:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf4GbPO37wMyDDwDUYAst6TrW8nxi59bBujTdTQcHaAFpmCne/88r9aHdmM5jH1+w8yqhNxg X-Received: by 2002:a17:90a:4906:b0:218:9963:7138 with SMTP id c6-20020a17090a490600b0021899637138mr25417815pjh.43.1669285125071; Thu, 24 Nov 2022 02:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669285125; cv=none; d=google.com; s=arc-20160816; b=DAHd2SEDHv9F9ruM6ozPK6aji79XgGkDZio1jbC7WgkehRI20WN9IudH3CQzsBTJFA GqNxXbYq2/d8GOFQOeO1C2zUHyTU739hj1xYScVoHM1UcNfHpcN/6IecvvytODHjTjPw DQoDbZkdaD20ZQVVAQejzNU/leztPrfifVVGoepjl7qUlOcfrRT9d1BL32zKN+JYDxcr ix8I5y9LQ+BZK43HONlmyKgVN0tQURzFAjFw5x7iK5PbxwBv3NhQr4eDbKII5DBfrhja gbsKf86iIcMxW8MRFLOnA//F4xctxVcdHExZCd67Otv/LrKatH59XbbyosEFZeZQbuq0 IZ0Q== 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:mime-version:dkim-signature; bh=r/inbI+y1fhrxyLW9sS+q/7x6KkspXDB7h9KT6wBhFI=; b=DFcJn189nApF0nnOJugBpnrzV10as+O+4FCPhTN2jExaK2q/AH2y5xbz1pa2k1OsHZ ZW0WD39+siMwtuW9OhHkCHn2wURDDXU0kjcdTpxMAEnaZtHc8nLkpNklqasC2muAWURr cR5ODf388lKFSY8fpnQwZlt7a+ev0z95HyAvqOe9L/u3+HQHLZRMfBUJXRtTuttcIs+B 4cFCh4Z9tvs4h7hDF7HyQOpvo15JrVrJauHO9feWcPX0pxIww0FYycJE5NkDHPwVjxV/ Ko7/COj4W5Xr/8lthojVAXxG5CXSSMTfktHZ2k7kOo+J3BZNZuGhAMEGd6C37hQ96Emo 1Zqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FsQyigU5; 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 b8-20020a170903228800b00186f22a06absi757303plh.253.2022.11.24.02.18.34; Thu, 24 Nov 2022 02:18:45 -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=FsQyigU5; 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 S229966AbiKXJ5y (ORCPT + 87 others); Thu, 24 Nov 2022 04:57:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbiKXJ5r (ORCPT ); Thu, 24 Nov 2022 04:57:47 -0500 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31F7014001 for ; Thu, 24 Nov 2022 01:57:46 -0800 (PST) Received: by mail-yb1-xb36.google.com with SMTP id e76so1274244yba.5 for ; Thu, 24 Nov 2022 01:57:46 -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 :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=r/inbI+y1fhrxyLW9sS+q/7x6KkspXDB7h9KT6wBhFI=; b=FsQyigU5X9Bj9xZiNwYg2vk1ek0GVhZG+zbSZ3vYiapFPlAQUN1xt3rSqtvzfV2J0o xn34AJ262EZYn2nnGIyRHGnlUbJL/Ecj+cE9/nguY3T/aDuwKpTUmTkCIShYtgNJoqJ6 S+oSflzGcP2f6TMQwdf/Uqc3W+iufoDZ5qIrmRnn+wEJIxLZcDcvcGWYSRe8V3BNRzgl X5pfGd6YRxRlZWJBqxbiE5b9oBOh4m/QQneZJjN5a90umabI+6XNKCBALBGTsy86LiFl yhS7VqlNE1bn/uB9f0sMRct+oHhUAme3rh1NsgpPJVtF+ukY/BxuBNM+1XHkuRQJo8J9 n07A== 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 :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r/inbI+y1fhrxyLW9sS+q/7x6KkspXDB7h9KT6wBhFI=; b=CKiZIrMQ3MPJdAary6wA9DQ9ZvAT+Qt2HPK/K8zgErY3vhaEG1p4fNlrBK+FPspBgD oPtJDw2OeyCUUYp1v8bXdkvqvHFQn1d8Blv7vAZQkGIjlQ8W1GNjp2tBAzs32C7GeXIM 2QoZWliXFfMigEtbdLPI1ka7NV1odYNipLQs8DbPM+6cQuM6ceCUecPiDlCexI5Mdab6 IIjaNRu5a0XF6JwqkS+VNXD/ahBWQDtyFX/E5xXZ9AsVrWyHakVBSUxR3ALE4dqtuWWD HtgC3DwnLAWu5UFYXZLtjQwX35MWLnp5DLVb3t1o52kmJ192tmK2my+3iTjK9/kA2Ay6 I8JQ== X-Gm-Message-State: ANoB5pkp7RIWOi9XjUP83PcWdanqQUAbv9NFZ7NoHPNpqJDUjRAX2vk4 Ekq6TyK3gQmA8celhKqXOgb85IaY68SebcD/uUzCB4e6iKygig== X-Received: by 2002:a25:f302:0:b0:6dd:4825:ba8f with SMTP id c2-20020a25f302000000b006dd4825ba8fmr30016399ybs.103.1669283865119; Thu, 24 Nov 2022 01:57:45 -0800 (PST) MIME-Version: 1.0 From: Guillermo Rodriguez Garcia Date: Thu, 24 Nov 2022 10:57:34 +0100 Message-ID: Subject: SOC_DOUBLE_R_SX_TLV controls broken in cs24l51 driver To: linux-kernel@vger.kernel.org Cc: =?UTF-8?Q?Tan_Nay=C4=B1r?= , Srinivas Kandagatla , Banajit Goswami , Richard Fitzgerald , Lucas Tanure , David Rhodes , James Schulman , Charles Keepax , 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 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: pr_warn("Max: %d, Min: %d, Value: %d", max, min, val); pr_warn("platform_max: %d", mc->platform_max); if (mc->platform_max && val > mc->platform_max) { return -EINVAL; } if (val > max - min){ pr_warn("(val > max - min) check failed"); return -EINVAL; } if (val < 0) return -EINVAL; According to the datasheet of the CS24L51, section 6.13, page 61, the PCMMIXX_VOL registers accept the following range of values: Binary Code / Volume Setting 001 1000 / +12.0 dB =C2=B7=C2=B7=C2=B7 =C2=B7=C2=B7=C2=B7 000 0000 / 0 dB 111 1111 / -0.5 dB 111 1110 / -1.0 dB =C2=B7=C2=B7=C2=B7 =C2=B7=C2=B7=C2=B7 001 1001 / -51.5 dB Minimum value is 0x19 (001 1001) corresponding to -51.5 dB, then there are 127 possible gain settings from -51.5 dB to +12.0 dB, in 0.5 dB steps. This is declared in the driver as follows: SOC_DOUBLE_R_SX_TLV("PCM Playback Volume", CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 0, 0x19, 0x7F, adc_pcm_tlv), 0x19 =3D min value 0x7F =3D number of gain settings This seems to be correct according to the semantics of the SOC_DOUBLE_R_SX_TLV macro as described in commit 34198710f55b5f359f43e67d9a08fe5aadfbca1b ("ASoC: Add info callback for SX_TLV controls"). However, the (val > max - min) check in snd_soc_put_volsw_sx fails in the above example because val =3D 127, max - min =3D 127 - 25 =3D 102. So I am not sure how this should be fixed. Is the SX_TLV macro being used incorrectly here? Is the check in snd_soc_put_volsw_sx wrong? Any pointers are welcome. Thanks, (If possible, please CC me in any replies) Guillermo Rodriguez Garcia guille.rodriguez@gmail.com