From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17F5928A716; Mon, 5 May 2025 23:17:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746487022; cv=none; b=lY6b/y2JKny9THUg4mSuD7AJMpuCLA2EOyiCxSF9ro4bmslSMDiX1vkT4f2IQJWXMm8guFuZ3909XpgMKD8lvpk7gLaRyMmObvXdSPz1HKiBTx+C1Y++ha84iblFjMaZ6L2BV9XvzqnTDyU3X5u5caD+LqdbNPDCxDNI2a2OIiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746487022; c=relaxed/simple; bh=ECRz2VfaKuPxDhpmY33wQ+nrPN5Czu4r27KgfaOuRzc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=aD40o+47mVk8ufq5IzU8TBNYts+3r8Ef7gL4WJfmCGuCprD/Q5mgQPTXgFOSE+pZSyAUgH54M0wF9AD0S8Ud1u1M2ZrCQCTh1FDfpOjemJD2bAfljbVgF7HPInHDlPNKoJkklT70uaauA2W225TNbbIz0/Z/XrmdtTu4wtWWFx8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MRPA+suT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MRPA+suT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9583C4CEEE; Mon, 5 May 2025 23:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746487021; bh=ECRz2VfaKuPxDhpmY33wQ+nrPN5Czu4r27KgfaOuRzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MRPA+suTXyfQeua7E+yakJS74A+BHgRIaFr8uUdhHXj/X/uuFbxZ0kC5q4wDGo9aA B25yXRO2N8YPeD62hhowsG/TsVpw+t/kEW2XacCoW6bfLElTbXvUdF3bTMXINpc2u+ 7Mvg2hp8HNwCxeEA4G9tNfzwgH57jTWO5y4tDs4EvVYmtLcHbhHDXfij0pT6uk7uTE CJcFB8rcAcQCCXug4DwUtSVoiR4iPnci3cWX4hMFuRds448buAFIEyhtZ9MreVL36P W1aFomSjRHCeA/W+mJG9jdfAb/wuFGJoxuYYr8vVf9VurQpFcBlLOiTGoyklI7BZnw JzetI6W7XYdyw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Martin=20Povi=C5=A1er?= , Mark Brown , Sasha Levin , lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 112/153] ASoC: ops: Enforce platform maximum on initial value Date: Mon, 5 May 2025 19:12:39 -0400 Message-Id: <20250505231320.2695319-112-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250505231320.2695319-1-sashal@kernel.org> References: <20250505231320.2695319-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.181 Content-Transfer-Encoding: 8bit From: Martin Povišer [ Upstream commit 783db6851c1821d8b983ffb12b99c279ff64f2ee ] Lower the volume if it is violating the platform maximum at its initial value (i.e. at the time of the 'snd_soc_limit_volume' call). Signed-off-by: Martin Povišer [Cherry picked from the Asahi kernel with fixups -- broonie] Signed-off-by: Mark Brown Link: https://patch.msgid.link/20250208-asoc-volume-limit-v1-1-b98fcf4cdbad@kernel.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/soc-ops.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index d8d0a26a554de..9eb4181c6697f 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -621,6 +621,33 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, } EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); +static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl) +{ + struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; + struct snd_ctl_elem_value uctl; + int ret; + + if (!mc->platform_max) + return 0; + + ret = kctl->get(kctl, &uctl); + if (ret < 0) + return ret; + + if (uctl.value.integer.value[0] > mc->platform_max) + uctl.value.integer.value[0] = mc->platform_max; + + if (snd_soc_volsw_is_stereo(mc) && + uctl.value.integer.value[1] > mc->platform_max) + uctl.value.integer.value[1] = mc->platform_max; + + ret = kctl->put(kctl, &uctl); + if (ret < 0) + return ret; + + return 0; +} + /** * snd_soc_limit_volume - Set new limit to an existing volume control. * @@ -645,7 +672,7 @@ int snd_soc_limit_volume(struct snd_soc_card *card, struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; if (max <= mc->max - mc->min) { mc->platform_max = max; - ret = 0; + ret = snd_soc_clip_to_platform_max(kctl); } } return ret; -- 2.39.5