Skip to contentSkip to conversation

ASoC: codecs: wcd: Fix a less than zero check on an u32 array element

PATCH In review Colin Ian King 2 participants 2 messages Sep 24, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: codecs: wcd: Fix a less than zero check on an u32 array element

Currently the error check from the call to wcd_get_micbias_val is always false because an u32 unsigned int in common->micb_vout[i] is being used to to perform the less than zero error check. Fix this by using the int variable ret to perform the check.

Fixes 4f16b6351bbf ("ASoC: codecs: wcd: add common helper for wcd codecs")
---
 sound/soc/codecs/wcd-common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
sound/soc/codecs/wcd-common.c +5 -2
index 9bbfda828377..9fd3965ed540 100644
@@ -65,9 +65,12 @@ int wcd_dt_parse_micbias_info(struct wcd_common *common)
 	int i;
 
 	for (i = 0; i < common->max_bias; i++) {
-		common->micb_vout[i] = wcd_get_micbias_val(common->dev, i + 1, &common->micb_mv[i]);
-		if (common->micb_vout[i] < 0)
+		int ret;
+
+		ret = wcd_get_micbias_val(common->dev, i + 1, &common->micb_mv[i]);
+		if (ret < 0)
 			return -EINVAL;
+		common->micb_vout[i] = ret;
 	}
 
 	return 0;
Signature · 1 line
2.51.0
#1 lore raw
Quoted 8 lines · Colin Ian King

Currently the error check from the call to wcd_get_micbias_val is always false because an u32 unsigned int in common->micb_vout[i] is being used to to perform the less than zero error check. Fix this by using the int variable ret to perform the check.

Fixes 4f16b6351bbf ("ASoC: codecs: wcd: add common helper for wcd codecs")

---

Dan Carpenter sent exactly same fix yesterday:

https://www.spinics.net/lists/kernel/msg5855359.html

--srini

Quoted 22 lines
 sound/soc/codecs/wcd-common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
sound/soc/codecs/wcd-common.c +5 -2
index 9bbfda828377..9fd3965ed540 100644
@@ -65,9 +65,12 @@ int wcd_dt_parse_micbias_info(struct wcd_common *common)
 	int i;
 
 	for (i = 0; i < common->max_bias; i++) {
-		common->micb_vout[i] = wcd_get_micbias_val(common->dev, i + 1, &common->micb_mv[i]);
-		if (common->micb_vout[i] < 0)
+		int ret;
+
+		ret = wcd_get_micbias_val(common->dev, i + 1, &common->micb_mv[i]);
+		if (ret < 0)
 			return -EINVAL;
+		common->micb_vout[i] = ret;
 	}
 
 	return 0;