Skip to contentSkip to conversation

ASoC: cs42xx8: Check return value of regmap_read and report correct chipid value

PATCH Superseded Axel Lin 5 participants 5 messages Apr 3, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 ASoC: cs42xx8: Check return value of regmap_read and report correct chipid value

Fix checking return value of regmap_read().
Also fix reporting the chip_id value. CS42XX8_CHIPID_CHIP_ID_MASK is 0xF0, so the chip_id value is (val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4).

---
 sound/soc/codecs/cs42xx8.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
sound/soc/codecs/cs42xx8.c +4 -5
index 082299a..b1606cf 100644
@@ -495,17 +495,16 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap)
 	regcache_cache_bypass(cs42xx8->regmap, true);
 
 	/* Validate the chip ID */
-	regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
-	if (val < 0) {
+	ret = regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
+	if (ret < 0) {
 		dev_err(dev, "failed to get device ID: %x", val);
-		ret = -EINVAL;
 		goto err_enable;
 	}
 
 	/* The top four bits of the chip ID should be 0000 */
-	if ((val & CS42XX8_CHIPID_CHIP_ID_MASK) != 0x00) {
+	if (((val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4) != 0x00) {
 		dev_err(dev, "unmatched chip ID: %d\n",
-				val & CS42XX8_CHIPID_CHIP_ID_MASK);
+			(val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4);
 		ret = -EINVAL;
 		goto err_enable;
 	}
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 14 lines · Axel Lin

Fix checking return value of regmap_read().
Also fix reporting the chip_id value. CS42XX8_CHIPID_CHIP_ID_MASK is 0xF0, so the chip_id value is (val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4).

---
 sound/soc/codecs/cs42xx8.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
sound/soc/codecs/cs42xx8.c +0 -0
index 082299a..b1606cf 100644

sound/soc/codecs/cs42xx8.c int cs42xx8_probe(struct device *dev, struct regmap *regmap) · line 500

Quoted 8 lines
sound/soc/codecs/cs42xx8.c +2 -2
@@ -495,17 +495,16 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap)
 	regcache_cache_bypass(cs42xx8->regmap, true);
 
 	/* Validate the chip ID */
-	regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
-	if (val < 0) {
+	ret = regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
+	if (ret < 0) {
 		dev_err(dev, "failed to get device ID: %x", val);

%d and ret would be better here since val won't be useful in this case.

Thank you for the fix.
Nicolin Chen

Quoted 20 lines
sound/soc/codecs/cs42xx8.c +2 -3
-		ret = -EINVAL;
 		goto err_enable;
 	}
 
 	/* The top four bits of the chip ID should be 0000 */
-	if ((val & CS42XX8_CHIPID_CHIP_ID_MASK) != 0x00) {
+	if (((val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4) != 0x00) {
 		dev_err(dev, "unmatched chip ID: %d\n",
-				val & CS42XX8_CHIPID_CHIP_ID_MASK);
+			(val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4);
 		ret = -EINVAL;
 		goto err_enable;
 	}
Signature · 1 line
1.8.3.2
#2 lore raw
Quoted 51 lines · Nicolin Chen
Quoted 14 lines · Axel Lin

Fix checking return value of regmap_read().
Also fix reporting the chip_id value. CS42XX8_CHIPID_CHIP_ID_MASK is 0xF0, so the chip_id value is (val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4).

---
 sound/soc/codecs/cs42xx8.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
sound/soc/codecs/cs42xx8.c +0 -0
index 082299a..b1606cf 100644

sound/soc/codecs/cs42xx8.c int cs42xx8_probe(struct device *dev, struct regmap *regmap) · line 500

Quoted 8 lines
sound/soc/codecs/cs42xx8.c +2 -2
@@ -495,17 +495,16 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap)
 	regcache_cache_bypass(cs42xx8->regmap, true);
 
 	/* Validate the chip ID */
-	regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
-	if (val < 0) {
+	ret = regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
+	if (ret < 0) {
 		dev_err(dev, "failed to get device ID: %x", val);

%d and ret would be better here since val won't be useful in this case.

Thank you for the fix.
Nicolin Chen

Quoted 20 lines
sound/soc/codecs/cs42xx8.c +2 -4
-		ret = -EINVAL;
 		goto err_enable;
 	}
 
 	/* The top four bits of the chip ID should be 0000 */
-	if ((val & CS42XX8_CHIPID_CHIP_ID_MASK) != 0x00) {
+	if (((val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4) != 0x00) {
 		dev_err(dev, "unmatched chip ID: %d\n",
-				val & CS42XX8_CHIPID_CHIP_ID_MASK);
+			(val & CS42XX8_CHIPID_CHIP_ID_MASK) >> 4);
 		ret = -EINVAL;
 		goto err_enable;
 	}
--

1.8.3.2

maintainer
#3 lore raw
In reply to Nicolin Chen
Quoted 7 lines · Nicolin Chen

sound/soc/codecs/cs42xx8.c int cs42xx8_probe(struct device *dev, struct regmap *regmap) · line 500

Quoted 3 lines · Axel Lin
sound/soc/codecs/cs42xx8.c +2 -0
+	ret = regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
+	if (ret < 0) {
 		dev_err(dev, "failed to get device ID: %x", val);

%d and ret would be better here since val won't be useful in this case.

Yes, they would - val won't have anything in particular in it if the I/O fails.