Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: ASoC: cs4271: free allocated GPIO
@ 2012-11-10 18:52 Daniel Mack
  2012-11-13  6:47 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Mack @ 2012-11-10 18:52 UTC (permalink / raw)
  To: alsa-devel; +Cc: broonie, Alexander Sverdlin, 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 using devm_gpio_request().

Signed-off-by: Daniel Mack <zonque@gmail.com>
Reported-by: Michael Hirsch <hirsch@teufel.de>
Cc: Alexander Sverdlin <subaparts@yandex.ru>
---
 sound/soc/codecs/cs4271.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index f994af3..e3f0a7f 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -485,7 +485,7 @@ static int cs4271_probe(struct snd_soc_codec *codec)
 		gpio_nreset = cs4271plat->gpio_nreset;
 
 	if (gpio_nreset >= 0)
-		if (gpio_request(gpio_nreset, "CS4271 Reset"))
+		if (devm_gpio_request(codec->dev, gpio_nreset, "CS4271 Reset"))
 			gpio_nreset = -EINVAL;
 	if (gpio_nreset >= 0) {
 		/* Reset codec */
@@ -535,15 +535,10 @@ static int cs4271_probe(struct snd_soc_codec *codec)
 static int cs4271_remove(struct snd_soc_codec *codec)
 {
 	struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec);
-	int gpio_nreset;
 
-	gpio_nreset = cs4271->gpio_nreset;
-
-	if (gpio_is_valid(gpio_nreset)) {
+	if (gpio_is_valid(cs4271->gpio_nreset))
 		/* Set codec to the reset state */
-		gpio_set_value(gpio_nreset, 0);
-		gpio_free(gpio_nreset);
-	}
+		gpio_set_value(cs4271->gpio_nreset, 0);
 
 	return 0;
 };
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] ALSA: ASoC: cs4271: free allocated GPIO
@ 2012-11-07 13:15 Daniel Mack
  2012-11-07 14:07 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Mack @ 2012-11-07 13:15 UTC (permalink / raw)
  To: alsa-devel; +Cc: broonie, Alexander Sverdlin, 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.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Reported-by: Michael Hirsch <hirsch@teufel.de>
Cc: Alexander Sverdlin <subaparts@yandex.ru>
---
 sound/soc/codecs/cs4271.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index e5a7ea4..ea57014 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -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)
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-13  6:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-10 18:52 [PATCH] ALSA: ASoC: cs4271: free allocated GPIO Daniel Mack
2012-11-13  6:47 ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2012-11-07 13:15 Daniel Mack
2012-11-07 14:07 ` Mark Brown
2012-11-10 18:52   ` Daniel Mack

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox