Skip to contentSkip to conversation

ALSA: ASoC: cs4271: free allocated GPIO

PATCH In review Daniel Mack 2 participants 3 messages Nov 7, 2012 – Nov 10, 2012

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

PATCH 1/1 ALSA: ASoC: cs4271: free allocated GPIO

In case of probe deferral, the allocated GPIO line is not freed, which prevents it from being claimed and properly asserted in later attempts.

Fix this by freeing the GPIO in case of errors.

---
 sound/soc/codecs/cs4271.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
sound/soc/codecs/cs4271.c +13 -4
index e5a7ea4..ea57014 100644
@@ -505,7 +505,7 @@ static int cs4271_probe(struct snd_soc_codec *codec)
 		ret = regulator_enable(cs4271->vd_supply);
 		if (ret < 0) {
 			dev_err(codec->dev, "unable to enable regulator\n");
-			return ret;
+			goto err;
 		}
 	}
 
@@ -548,22 +548,31 @@ static int cs4271_probe(struct snd_soc_codec *codec)
 			cs4271->bus_type);
 	if (ret) {
 		dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
-		return ret;
+		goto err_free_gpio;
 	}
 
 	ret = snd_soc_update_bits(codec, CS4271_MODE2,
 				  CS4271_MODE2_PDN | CS4271_MODE2_CPEN,
 				  CS4271_MODE2_PDN | CS4271_MODE2_CPEN);
 	if (ret < 0)
-		return ret;
+		goto err_free_gpio;
 	ret = snd_soc_update_bits(codec, CS4271_MODE2, CS4271_MODE2_PDN, 0);
 	if (ret < 0)
-		return ret;
+		goto err_free_gpio;
 	/* Power-up sequence requires 85 uS */
 	udelay(85);
 
 	return snd_soc_add_codec_controls(codec, cs4271_snd_controls,
 		ARRAY_SIZE(cs4271_snd_controls));
+
+err_free_gpio:
+	if (gpio_is_valid(cs4271->gpio_nreset))
+		gpio_free(cs4271->gpio_nreset);
+
+	cs4271->gpio_nreset = -EINVAL;
+
+err:
+	return ret;
 }
 
 static int cs4271_remove(struct snd_soc_codec *codec)
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 4 lines · Daniel Mack

In case of probe deferral, the allocated GPIO line is not freed, which prevents it from being claimed and properly asserted in later attempts.

Fix this by freeing the GPIO in case of errors.

Can we convert to devm_gpio_request_one() instead?

#2 lore raw
Quoted 8 lines · Mark Brown
Quoted 4 lines · Daniel Mack

In case of probe deferral, the allocated GPIO line is not freed, which prevents it from being claimed and properly asserted in later attempts.

Fix this by freeing the GPIO in case of errors.

Can we convert to devm_gpio_request_one() instead?

Sure, that's much nicer.