From patchwork Mon Jan 24 15:32:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 534543 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDCB6C433F5 for ; Mon, 24 Jan 2022 15:35:27 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id F07B728BA; Mon, 24 Jan 2022 16:34:35 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz F07B728BA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1643038526; bh=H8CSXUKprkgwQSMfZvGKY0nOZEI/6JtPV3yXxnw+z/A=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uJHCKgCvS0U2G8BsTV+iybLM0W1ttdS76p0NUL43tSsR7XSoAERDd5JYFfKsDztcI XXeLmggXrb+Oa4bwMFiETgi1CCY69/V2AL0sGEQ1fDtYFOa0GQUEM0EcqSRBPHK5Db fHM9nnyKCSFU2cf3vLrnTa7eCVgP5LYxRpYnL2O8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 7FF4EF8030F; Mon, 24 Jan 2022 16:34:02 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id DEDE3F8032B; Mon, 24 Jan 2022 16:34:00 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 62FADF80083 for ; Mon, 24 Jan 2022 16:33:56 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 62FADF80083 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SNFL9qB0" 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 CB3A96149A; Mon, 24 Jan 2022 15:33:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34897C340E7; Mon, 24 Jan 2022 15:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643038433; bh=H8CSXUKprkgwQSMfZvGKY0nOZEI/6JtPV3yXxnw+z/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SNFL9qB0UJ1VQJXSuOKFEx3AGgLDouh+HU85gDA7yFg1aAwkWfND3fwqfW1zMVXpj +m1a69WFyyIGRRKaZEdZ4l+vgqByjAlqMI4VYUj/ubHpTSIXkYt4UEerfD5gyOQ0wc x6031ocCB1OF0njWJl3IzpzJnc4xOAMgXsrxWkH+sEjNduOCUC4eVCvs6FqvCQ//2a 0jmFTkN+4mBzSaOwLqpxbS3/w3WqLdDgnJSHeTvGFARbxkb0u6z+bijla4Nb4+nnjI ezVm3CJk3ivxMo/QyXP9mPQd2xTcfuxAHRtlIWvME3MiYERKiMNUJ92pZgq+Qp2qou jrgF83b9ZevUQ== From: Mark Brown To: Liam Girdwood Subject: [PATCH v1 1/3] ASoC: ops: Reject out of bounds values in snd_soc_put_volsw() Date: Mon, 24 Jan 2022 15:32:51 +0000 Message-Id: <20220124153253.3548853-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124153253.3548853-1-broonie@kernel.org> References: <20220124153253.3548853-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1419; h=from:subject; bh=H8CSXUKprkgwQSMfZvGKY0nOZEI/6JtPV3yXxnw+z/A=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBh7saihjCo+ozwM+QwXv6Oo2x19ONjtnaIuHg+l+Hj ZU7ydiiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYe7GogAKCRAk1otyXVSH0CujB/ 92G0gzebzErS14s3OjhKS66JcFgczyXwFfuQ+g8KaCw4N6kuOym+f084lSn1Dnvb0KBZxOPQAvJOS2 KaLxTSIn8Hsk8y9XDtxIzWF1HOnRfxhKUHiQ8fDlmTqhs+FehCW3ovLbYoYMmjdDdDF0KUJdUeFC4w LbP/hSYAWxu3oocFVzpHxo/N/agV7WXGynh8F7mFC7o5wLefg5a0K8RB8rKkJpSfz6QtANAymcS3Vl U4+NApoS25EGOQg70bmBTYDt2ys6yf+Bk/13XsskwtstZKV0tNdFwqZkj/y+ro7AT0oJpYjYlnUiJ5 hdlIV3cKSmljqrmk79JFm8TNCjXiJ6 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Cc: alsa-devel@alsa-project.org, Mark Brown , stable@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" We don't currently validate that the values being set are within the range we advertised to userspace as being valid, do so and reject any values that are out of range. Signed-off-by: Mark Brown Cc: stable@vger.kernel.org --- sound/soc/soc-ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index 08eaa9ddf191..fbe5d326b0f2 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -316,13 +316,27 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, if (sign_bit) mask = BIT(sign_bit + 1) - 1; - val = ((ucontrol->value.integer.value[0] + min) & mask); + val = ucontrol->value.integer.value[0]; + if (mc->platform_max && val > mc->platform_max) + return -EINVAL; + if (val > max - min) + return -EINVAL; + if (val < 0) + return -EINVAL; + val = (val + min) & mask; if (invert) val = max - val; val_mask = mask << shift; val = val << shift; if (snd_soc_volsw_is_stereo(mc)) { - val2 = ((ucontrol->value.integer.value[1] + min) & mask); + val2 = ucontrol->value.integer.value[1]; + if (mc->platform_max && val2 > mc->platform_max) + return -EINVAL; + if (val2 > max - min) + return -EINVAL; + if (val2 < 0) + return -EINVAL; + val2 = (val2 + min) & mask; if (invert) val2 = max - val2; if (reg == reg2) { From patchwork Mon Jan 24 15:32:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 536498 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00553C433EF for ; Mon, 24 Jan 2022 15:35:42 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 277FA28C1; Mon, 24 Jan 2022 16:34:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 277FA28C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1643038541; bh=+kjikJbyX399n8l4YflLelzMjQvpmTCrZ53Skgl4Wow=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pj+hZGFZkvbK3VWYo0cwLbnVfx2AqcUwCv5+sbL8dhPtxjr4sN70RYT3pEh4L0wTh q+eivySpoSXJxtgYO9YWukRQ/uja9v+THxIUEh7T9XnkzQMAURVyeik1i3uipIsVkG b9wc/bH9gRLsJ1YAH0wF/e9TXev4kdU2izDAJCQg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 456E8F80506; Mon, 24 Jan 2022 16:34:05 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CAA7CF8050F; Mon, 24 Jan 2022 16:34:03 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 22298F80163 for ; Mon, 24 Jan 2022 16:33:56 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 22298F80163 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PiY/5+Le" 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 ams.source.kernel.org (Postfix) with ESMTPS id 076E5B810E5; Mon, 24 Jan 2022 15:33:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC587C340E5; Mon, 24 Jan 2022 15:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643038434; bh=+kjikJbyX399n8l4YflLelzMjQvpmTCrZ53Skgl4Wow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PiY/5+LebGVnVcRv12epRwh9GBgt7ihfy/GW1+ug3+xb5aBevE0uUMabcMQLsd7oT AlKxuiSaN4BDEM5ogMpAjvmP/3fPd/Guxchl2fP3bEtGD0tHeIqSRILVGk1gx/J92l GhcMWMLIy6METfxBcdYDj7zYo0CeYokmJz1/TYK8n65N23hgbeTAPwooXpxO/wXSos gQsvW9alv4jhNHicMvWYbtTtHnuAO+yP7m4H+wvHcX22o/CXdRbwvzAkqwHG2qLtse StFoFmWFUbYSSpzDl26rwZOvxoX8mogio3W5evYV4zgsnsRR7V1yvyGBcsDZIArVAB dkNxBzxvuwMSA== From: Mark Brown To: Liam Girdwood Subject: [PATCH v1 2/3] ASoC: ops: Reject out of bounds values in snd_soc_put_volsw_sx() Date: Mon, 24 Jan 2022 15:32:52 +0000 Message-Id: <20220124153253.3548853-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124153253.3548853-1-broonie@kernel.org> References: <20220124153253.3548853-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1041; h=from:subject; bh=+kjikJbyX399n8l4YflLelzMjQvpmTCrZ53Skgl4Wow=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBh7sajUonxcZUECf7NrKKuplLQtpL6DGJ0fCoa8VRN DdN8i+GJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYe7GowAKCRAk1otyXVSH0L/WB/ 4oX3rubzi3wIUKvCjUETO3MCs6jkJxZSYSSVXstEcuV9nYfE+hPsG6BmKluWzNPwoBLzpunV6DFZ4Z oV6r2gm2XHc/5IePEH4aGs2X9fCAX6Gz7VZLysiTuqVpB+ANtfDfXiJqG9n6yTk3+M0J9l/Q+F/d22 VWc9HCleWQ71Wz7kplzGwp1SF1GK6Ns7PrNZHtH2pu2ovbhiRbf1M0LFCkL8CsavvpJ/e4rBV9MPaQ P6ccATfgAsltv4UWy4xU1UsNnvU4IQpvu04U7xmIvzjbgMq8XqspqMYHxIYk2jPiMbu9+UI/ASbpzb nSyPRULGSRlX1FSAWHiM0uYsQsCkfD X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Cc: alsa-devel@alsa-project.org, Mark Brown , stable@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" We don't currently validate that the values being set are within the range we advertised to userspace as being valid, do so and reject any values that are out of range. Signed-off-by: Mark Brown Cc: stable@vger.kernel.org --- sound/soc/soc-ops.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index fbe5d326b0f2..c31e63b27193 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -423,8 +423,15 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, int err = 0; unsigned int val, val_mask; + val = ucontrol->value.integer.value[0]; + if (mc->platform_max && val > mc->platform_max) + return -EINVAL; + if (val > max - min) + return -EINVAL; + if (val < 0) + return -EINVAL; val_mask = mask << shift; - val = (ucontrol->value.integer.value[0] + min) & mask; + val = (val + min) & mask; val = val << shift; err = snd_soc_component_update_bits(component, reg, val_mask, val); From patchwork Mon Jan 24 15:32:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 534542 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 062FDC433EF for ; Mon, 24 Jan 2022 15:35:57 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 3A8EB28B5; Mon, 24 Jan 2022 16:35:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3A8EB28B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1643038556; bh=jkhjis8H6JqAp1zJ1gh7YAG/4kx66gcS8datCwYFgUU=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=GU4rCqCJ6aRWybuezExJetDVa/htyKyT02A4SMaT1EklkLSKylzAWx43ok8gDzFYF TffGCYqNUry++e+HC782v/JrmxhGMIulHdK7b6qqazE80xdYluYms5Gn3AHvbGuGQI Cc94c2Tq3KskwGS2JT5v9wuNKF44hoL0cOJvfF54= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 085F5F80508; Mon, 24 Jan 2022 16:34:06 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 75120F80508; Mon, 24 Jan 2022 16:34:04 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C2A0AF80424 for ; Mon, 24 Jan 2022 16:33:59 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C2A0AF80424 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NF9JisuH" 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 ams.source.kernel.org (Postfix) with ESMTPS id 81362B810E0; Mon, 24 Jan 2022 15:33:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31603C340E7; Mon, 24 Jan 2022 15:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643038436; bh=jkhjis8H6JqAp1zJ1gh7YAG/4kx66gcS8datCwYFgUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NF9JisuHo2ZCNe3U38f3R4mDx/1hyTFPO8bRzd9LPn2FvdP6QP3qolR8dHHB22c3A C0JeglThuxvyUSa0iTaT7YMFlZOCCSPDGsZ1Ilq7Y3nnNPVfqiYtE/uEkkI0u+AsKo D5mdcY79vZ1OZA6TBgDhcPXjiQnzxvYSx09FkBSLOYuSrwxSinSdeO8lgEg+S10iuU AgWLoyNkznRU1/G23BVk6iUtUdkBuZG9CUMY8DgsZ67cSMjlNhmfjUnAG6BER9vkO/ cTj51zb4srg0d8XFK8odwhPtE7Q9/IFWzojYOErYe3bKn258o5EWTH/Ah9/SB0mKZk zB5BXU1egV82A== From: Mark Brown To: Liam Girdwood Subject: [PATCH v1 3/3] ASoC: ops: Reject out of bounds values in snd_soc_put_xr_sx() Date: Mon, 24 Jan 2022 15:32:53 +0000 Message-Id: <20220124153253.3548853-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124153253.3548853-1-broonie@kernel.org> References: <20220124153253.3548853-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=739; h=from:subject; bh=jkhjis8H6JqAp1zJ1gh7YAG/4kx66gcS8datCwYFgUU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBh7sakWbsihUi6ivlHyc+XDsV04Zi7JuDjensfPO4K IJ8b9UeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYe7GpAAKCRAk1otyXVSH0DJIB/ 96C0pXVD2VI++KwpJCPmOEZH7OklDsEyIV++4ozRLs6NggCnOdvVfFSP2FFPntTDvO27bLrkNk+gH8 FPmc8QUTKpJjEO9r/G2i0XrZM618h8rsIzrqAvzapM8/Z9vi2OJczP2BisdQ9w4pu1Ok9+kXiWbBWt ubXmxDDVrQ3ZQsv+qNZQqB1mDE4+gZJVQGIhK2ezPpxgQWWLFb1LkltvX9WSdcjuxoT7vhjTBpqJkf DcxrVQuoTDP8PoLqSH/I2ZYutH3TOXAJCTi3vMcGl8u+1XZJ95NOldqMcAaFU1DN5I3g/vVJqbnB/p wEpqaYNJymuor3+GM1Ub9Iye1wCHZE X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Cc: alsa-devel@alsa-project.org, Mark Brown , stable@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" We don't currently validate that the values being set are within the range we advertised to userspace as being valid, do so and reject any values that are out of range. Signed-off-by: Mark Brown Cc: stable@vger.kernel.org --- sound/soc/soc-ops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index c31e63b27193..dc0e7c8d31f3 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -879,6 +879,8 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, long val = ucontrol->value.integer.value[0]; unsigned int i; + if (val < mc->min || val > mc->max) + return -EINVAL; if (invert) val = max - val; val &= mask;