[Sound-open-firmware] [PATCH] volume: fix volume underflows

Ranjani Sridharan ranjani.sridharan at linux.intel.com
Tue Mar 13 07:08:53 CET 2018


This patch fixes the bug with volume ramp down which causes volume
to underflow causing unspecified behaviour.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
---
 src/audio/volume.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/audio/volume.c b/src/audio/volume.c
index 51a5826..0620e18 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -307,7 +307,7 @@ static uint64_t vol_work(void *data, uint64_t delay)
 	struct comp_data *cd = comp_get_drvdata(dev);
 	uint32_t vol;
 	int again = 0;
-	int i;
+	int i, new_vol;
 
 	/* inc/dec each volume if it's not at target */
 	for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) {
@@ -332,14 +332,19 @@ static uint64_t vol_work(void *data, uint64_t delay)
 			}
 		} else {
 			/* ramp down */
-			vol -= VOL_RAMP_STEP;
-
-			/* ramp completed ? */
-			if (vol <= cd->tvolume[i] || vol <= VOL_MIN)
+			new_vol = vol - VOL_RAMP_STEP;
+			if (new_vol <= 0) {
+				/* cannot ramp down below 0 */
 				vol_update(cd, i);
-			else {
-				cd->volume[i] = vol;
-				again = 1;
+			} else {
+				/* ramp completed ? */
+				if (new_vol <= cd->tvolume[i] ||
+					new_vol <= VOL_MIN) {
+					vol_update(cd, i);
+				} else {
+					cd->volume[i] = new_vol;
+					again = 1;
+				}
 			}
 		}
 
-- 
2.14.1



More information about the Sound-open-firmware mailing list